Skip to content

Commit

Permalink
Get rid of the servicedesk client ext. for jira lib
Browse files Browse the repository at this point in the history
The former code was based on pycontribs/jira#388
which is closed and unmaintained. We only need to read the organizations
from the servicedesk REST API and the local code is minimal.

We can now use the normal jira library.
  • Loading branch information
guewen committed Jan 31, 2019
1 parent 39251c6 commit 338308a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import common
from . import importer
from . import adapter
51 changes: 51 additions & 0 deletions connector_jira_servicedesk/models/jira_organization/adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

import jira
from jira.utils import CaseInsensitiveDict

from odoo.addons.component.core import Component


class Organization(jira.resources.Resource):
"""A Service Desk Organization."""

def __init__(self, options, session, raw=None):
super().__init__(
'organization/{0}',
options,
session,
'{server}/rest/servicedeskapi/{path}'
)
if raw:
self._parse_raw(raw)


class OrganizationAdapter(Component):
_name = 'jira.organization.adapter'
_inherit = ['jira.webservice.adapter']
_apply_on = ['jira.organization']

_desk_headers = CaseInsensitiveDict({'X-ExperimentalApi': 'opt-in'})

def read(self, id_):
organization = Organization(
self.client._options,
self.client._session
)
organization.find(id_, headers=self._desk_headers)
return organization.raw

def search(self):
base = (self.client._options['server'] +
'/rest/servicedeskapi/organization')
orgs = self.client._fetch_pages(
Organization,
'values',
'organization',
# limit to False will get them in batch
maxResults=False,
headers=self._desk_headers,
base=base
)
return [org.id for org in orgs]
16 changes: 1 addition & 15 deletions connector_jira_servicedesk/models/jira_organization/common.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)


from odoo import fields, models
from odoo.addons.queue_job.job import job

from odoo.addons.component.core import Component


class JiraOrganization(models.Model):
_name = 'jira.organization'
Expand All @@ -27,16 +26,3 @@ def import_batch(self, backend, from_date=None, to_date=None):
with backend.work_on(self._name) as work:
importer = work.component(usage='batch.importer')
importer.run()


class OrganizationAdapter(Component):
_name = 'jira.organization.adapter'
_inherit = ['jira.webservice.adapter']
_apply_on = ['jira.organization']

def read(self, id_):
return self.client.desk.organization(id_).raw

def search(self):
orgs = self.client.desk.organizations()
return [org.id for org in orgs]

0 comments on commit 338308a

Please sign in to comment.