Browse Source

[FIX] Redirect url and Handler

pull/78/head
Sreejith P 7 years ago
parent
commit
19ac328c57
  1. 9
      hr_linkedin_recruitment/README.rst
  2. 2
      hr_linkedin_recruitment/__manifest__.py
  3. 14
      hr_linkedin_recruitment/doc/RELEASE_NOTES.md
  4. 7
      hr_linkedin_recruitment/doc/requirment.txt
  5. 32
      hr_linkedin_recruitment/models/hr_job.py
  6. 18
      hr_linkedin_recruitment/models/mechanize_op.py

9
hr_linkedin_recruitment/README.rst

@ -18,17 +18,24 @@ The module integrates LinkedIn with Odoo HR Recruitment.
* Profile URL of Candidates. * Profile URL of Candidates.
* Automate Odoo HRMS with LinkedIn. * Automate Odoo HRMS with LinkedIn.
Company Company
------- -------
* `Cybrosys Technologies <https://cybrosys.com/>`__ * `Cybrosys Technologies <https://cybrosys.com/>`__
Developers
----------
* `Nilmar Shereef <shereef@cybrosys.in>`__
* `Jesni Banu <jesni@cybrosys.in>`__
Contact Contact
------- -------
* Mail Contact : odoo@cybrosys.com * Mail Contact : odoo@cybrosys.com
* Mail Contact : shereef@cybrosys.in * Mail Contact : shereef@cybrosys.in
* Mail Contact : info@cybrosys.com * Mail Contact : info@cybrosys.com
Related Blog
-------
* `Cybrosys LinkedIn Blog <https://www.cybrosys.com/blog/odoo-linkedin-integration-in-hr/>`__
Further information Further information
=================== ===================
HTML Description: `<static/description/index.html>`__ HTML Description: `<static/description/index.html>`__

2
hr_linkedin_recruitment/__manifest__.py

@ -25,7 +25,7 @@
'summary': "Integrates LinkedIn with HR Recruitment", 'summary': "Integrates LinkedIn with HR Recruitment",
'description': "Basic module for LnkedIn-HR Recruitment connector", 'description': "Basic module for LnkedIn-HR Recruitment connector",
'category': 'Generic Modules/Human Resources', 'category': 'Generic Modules/Human Resources',
'version': "10.0.1.1.0", 'version': "10.0.2.0.0",
'depends': ['hr_recruitment', 'auth_oauth'], 'depends': ['hr_recruitment', 'auth_oauth'],
'author': 'Cybrosys Techno Solutions', 'author': 'Cybrosys Techno Solutions',
'company': 'Cybrosys Techno Solutions', 'company': 'Cybrosys Techno Solutions',

14
hr_linkedin_recruitment/doc/RELEASE_NOTES.md

@ -0,0 +1,14 @@
## Module <hr_linkedin_recruitment>
#### 19.05.2018
#### Version 10.0.2.0.0
##### FIX
- Redirect url
- Handler for wrong password
- Handler import error
#### 28.04.2018
#### Version 10.0.1.0.0
##### ADD
- Initial commit for LinkedIn-Odoo Integration

7
hr_linkedin_recruitment/doc/requirment.txt

@ -1,5 +1,8 @@
Odoo integration module "hr_linkedin_recruitment" depends on the several external python package. Odoo integration module "hr_linkedin_recruitment" depends on the several external python package.
Please ensure that listed packaged has installed in your system: Please ensure that listed packaged has installed in your system:
* linkedin * python-linkedin (sudo python-linkedin)
* mechanize * mechanize (sudo pip install mechanize)

32
hr_linkedin_recruitment/models/hr_job.py

@ -25,6 +25,7 @@ _logger = logging.getLogger(__name__)
try: try:
import mechanize import mechanize
from linkedin import linkedin from linkedin import linkedin
from mechanize_op import MechanizeRedirectHandler
except ImportError: except ImportError:
_logger.error('Odoo module hr_linkedin_recruitment depends on the several external python package' _logger.error('Odoo module hr_linkedin_recruitment depends on the several external python package'
@ -34,8 +35,7 @@ import requests
import json import json
import urlparse import urlparse
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError, Warning
from mechanize_op import MechanizeRedirectHandler
class HrJobShare(models.Model): class HrJobShare(models.Model):
@ -59,15 +59,25 @@ class HrJobShare(models.Model):
has_access_url = 'https://api.linkedin.com/v1/companies/%s/relation-to-viewer/is-company-share-enabled?format=json'%(li_credential['page_id']) has_access_url = 'https://api.linkedin.com/v1/companies/%s/relation-to-viewer/is-company-share-enabled?format=json'%(li_credential['page_id'])
page_share_url = 'https://api.linkedin.com/v1/companies/%s/shares?format=json'%(li_credential['page_id']) page_share_url = 'https://api.linkedin.com/v1/companies/%s/shares?format=json'%(li_credential['page_id'])
response = self.has_acces_request('GET', has_access_url, access_token) access_response = self.has_acces_request('GET', has_access_url, access_token)
access_response_text = response.json() access_response_text = access_response.json()
if access_response_text: if access_response_text:
response = self.share_request('POST', page_share_url, access_token, data=json.dumps(share_data)) response = self.share_request('POST', page_share_url, access_token, data=json.dumps(share_data))
share_response_text = response.json() share_response_text = response.json()
share_response_code = response.status_code share_response_code = response.status_code
if share_response_code == 201: if share_response_code == 201:
self.update_key = share_response_text['updateKey'] self.update_key = share_response_text['updateKey']
else:
raise Warning("You have no share access in company page.!")
def has_acces_request(self, method, has_access_url, access_token):
""" Function will return TRUE if credentials user has the access to update """
headers = {'x-li-format': 'json', 'Content-Type': 'application/json'}
params = {}
params.update({'oauth2_access_token': access_token})
kw = dict(params=params, headers=headers, timeout=60)
req_response = requests.request(method.upper(), has_access_url, **kw)
return req_response
def share_request(self, method, page_share_url, access_token, data): def share_request(self, method, page_share_url, access_token, data):
""" Function will return UPDATED KEY , [201] if sharing is OK """ """ Function will return UPDATED KEY , [201] if sharing is OK """
@ -93,15 +103,15 @@ class HrJobShare(models.Model):
li_credential['page_id'] = self.env['ir.values'].get_default('hr.recruitment.config.settings', li_credential['page_id'] = self.env['ir.values'].get_default('hr.recruitment.config.settings',
'company_page_id') 'company_page_id')
else: else:
raise exceptions.Warning(_('Please fill up company page ID in LinkedIn Credential settings.')) raise Warning(_('Please fill up company page ID in LinkedIn Credential settings.'))
if self.env['ir.values'].get_default('hr.recruitment.config.settings', 'li_username'): if self.env['ir.values'].get_default('hr.recruitment.config.settings', 'li_username'):
li_credential['un'] = self.env['ir.values'].get_default('hr.recruitment.config.settings', 'li_username') li_credential['un'] = self.env['ir.values'].get_default('hr.recruitment.config.settings', 'li_username')
else: else:
raise exceptions.Warning(_('Please fill up username in LinkedIn Credential settings.')) raise Warning(_('Please fill up username in LinkedIn Credential settings.'))
if self.env['ir.values'].get_default('hr.recruitment.config.settings', 'li_password'): if self.env['ir.values'].get_default('hr.recruitment.config.settings', 'li_password'):
li_credential['pw'] = self.env['ir.values'].get_default('hr.recruitment.config.settings', 'li_password') li_credential['pw'] = self.env['ir.values'].get_default('hr.recruitment.config.settings', 'li_password')
else: else:
raise exceptions.Warning(_('Please fill up password in LinkedIn Credential settings.')) raise Warning(_('Please fill up password in LinkedIn Credential settings.'))
# Browser Data Posting And Signing # Browser Data Posting And Signing
br = mechanize.Browser() br = mechanize.Browser()
@ -109,7 +119,7 @@ class HrJobShare(models.Model):
br.handler_classes['_redirect'] = MechanizeRedirectHandler br.handler_classes['_redirect'] = MechanizeRedirectHandler
br.set_handle_redirect(True) br.set_handle_redirect(True)
br.set_handle_robots(False) br.set_handle_robots(False)
return_uri = 'http://0.0.0.0:8010' return_uri = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
li_permissions = ['r_basicprofile', 'r_emailaddress', 'w_share', 'rw_company_admin'] li_permissions = ['r_basicprofile', 'r_emailaddress', 'w_share', 'rw_company_admin']
auth = linkedin.LinkedInAuthentication(li_credential['api_key'], auth = linkedin.LinkedInAuthentication(li_credential['api_key'],
li_credential['secret_key'], li_credential['secret_key'],
@ -117,11 +127,15 @@ class HrJobShare(models.Model):
li_permissions) li_permissions)
br.open(auth.authorization_url) br.open(auth.authorization_url)
br.select_form(nr=0) br.select_form(nr=0)
print "li_credential", li_credential
br.form['session_key'] = li_credential['un'] br.form['session_key'] = li_credential['un']
br.form['session_password'] = li_credential['pw'] br.form['session_password'] = li_credential['pw']
r = br.submit() r = br.submit()
try:
auth.authorization_code = urlparse.parse_qs(urlparse.urlsplit(r.geturl()).query)['code'] auth.authorization_code = urlparse.parse_qs(urlparse.urlsplit(r.geturl()).query)['code']
except:
raise Warning("Please cross check your username and password.!")
li_suit_credent = {} li_suit_credent = {}
li_suit_credent['access_token'] = str(auth.get_access_token().access_token) li_suit_credent['access_token'] = str(auth.get_access_token().access_token)
li_suit_credent['li_credential'] = li_credential li_suit_credent['li_credential'] = li_credential

18
hr_linkedin_recruitment/models/mechanize_op.py

@ -21,18 +21,16 @@
# #
################################################################################### ###################################################################################
import logging import logging
from urllib2 import HTTPError
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try: try:
import mechanize import mechanize
except ImportError: from mechanize import _response
_logger.error('Odoo module hr_linkedin_recruitment depends on the several external python package' from mechanize import _rfc3986
'Please read the doc/requirement.txt file inside the module.') import re
import re
from mechanize import _response
from mechanize import _rfc3986
class MechanizeRedirectHandler(mechanize.HTTPRedirectHandler): class MechanizeRedirectHandler(mechanize.HTTPRedirectHandler):
def http_error_302(self, req, fp, code, msg, headers): def http_error_302(self, req, fp, code, msg, headers):
# Code from mechanize._urllib2_fork.HTTPRedirectHandler: # Code from mechanize._urllib2_fork.HTTPRedirectHandler:
if 'location' in headers: if 'location' in headers:
@ -70,3 +68,9 @@ class MechanizeRedirectHandler(mechanize.HTTPRedirectHandler):
http_error_301 = http_error_303 = http_error_307 = http_error_302 http_error_301 = http_error_303 = http_error_307 = http_error_302
http_error_refresh = http_error_302 http_error_refresh = http_error_302
except ImportError:
_logger.warning('Odoo module hr_linkedin_recruitment depends on the several external python package'
'Please read the doc/requirement.txt file inside the module.')

Loading…
Cancel
Save