Skip to content

Commit

Permalink
Merge pull request #406 from OS2mo/bugfix/31661_remove_org
Browse files Browse the repository at this point in the history
Streamline how various request handlers use the 'org' parameter
  • Loading branch information
Christoffer Moesgaard committed Sep 13, 2019
2 parents d0ab43c + fef003e commit f5eaf08
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 100 deletions.
2 changes: 2 additions & 0 deletions NEWS.rst
Expand Up @@ -11,6 +11,8 @@ Bug fixes

* #22316: Ensure update payloads sent to LoRa satisfy validation
requirements
* #31663: ``org`` is now correctly an optional (deprecated) parameter on
creation of various objects

Internal changes
----------------
Expand Down
6 changes: 4 additions & 2 deletions backend/mora/service/address.py
Expand Up @@ -17,6 +17,7 @@
from . import employee
from . import facet
from . import handlers
from . import org
from . import orgunit
from .address_handler import base
from .validation import validator
Expand Down Expand Up @@ -227,7 +228,8 @@ def prepare_create(self, req):

valid_from, valid_to = util.get_validities(req)

orgid = util.get_mapping_uuid(req, mapping.ORG, required=True)
org_uuid = org.get_configured_organisation(
util.get_mapping_uuid(req, mapping.ORG, required=False))["uuid"]

address_type_uuid = util.get_mapping_uuid(req, mapping.ADDRESS_TYPE,
required=True)
Expand Down Expand Up @@ -261,7 +263,7 @@ def prepare_create(self, req):
funktionstype=address_type_uuid,
adresser=[handler.get_lora_address()],
tilknyttedebrugere=[employee_uuid] if employee_uuid else [],
tilknyttedeorganisationer=[orgid],
tilknyttedeorganisationer=[org_uuid],
tilknyttedeenheder=[org_unit_uuid] if org_unit_uuid else [],
tilknyttedefunktioner=[manager_uuid] if manager_uuid else [],
opgaver=handler.get_lora_properties(),
Expand Down
13 changes: 3 additions & 10 deletions backend/mora/service/association.py
Expand Up @@ -16,9 +16,9 @@
import uuid

from . import handlers
from . import org
from .validation import validator
from .. import common
from .. import exceptions
from .. import lora
from .. import mapping
from .. import util
Expand All @@ -29,23 +29,16 @@ class AssociationRequestHandler(handlers.OrgFunkRequestHandler):
function_key = mapping.ASSOCIATION_KEY

def prepare_create(self, req):
c = lora.Connector()

org_unit = util.checked_get(req, mapping.ORG_UNIT,
{}, required=True)
org_unit_uuid = util.get_uuid(org_unit, required=True)

employee = util.checked_get(req, mapping.PERSON, {}, required=True)
employee_uuid = util.get_uuid(employee, required=True)

org_unit_obj = c.organisationenhed.get(org_unit_uuid)

if not org_unit_obj:
exceptions.ErrorCodes.E_ORG_UNIT_NOT_FOUND(
org_unit_uuid=org_unit_uuid,
)
org_uuid = org.get_configured_organisation(
util.get_mapping_uuid(req, mapping.ORG, required=False))["uuid"]

org_uuid = org_unit_obj['relationer']['tilhoerer'][0]['uuid']
association_type_uuid = util.get_mapping_uuid(
req,
mapping.ASSOCIATION_TYPE,
Expand Down
6 changes: 3 additions & 3 deletions backend/mora/service/employee.py
Expand Up @@ -79,9 +79,9 @@ def prepare_create(self, req):
{},
required=False
)
org_uuid_specified = util.get_mapping_uuid(req, mapping.ORG,
required=True)
org_uuid = org.get_configured_organisation(org_uuid_specified)["uuid"]

org_uuid = org.get_configured_organisation(
util.get_mapping_uuid(req, mapping.ORG, required=False))["uuid"]

cpr = util.checked_get(req, mapping.CPR_NO, "", required=False)
userid = util.get_uuid(req, required=False) or str(uuid.uuid4())
Expand Down
7 changes: 3 additions & 4 deletions backend/mora/service/engagement.py
Expand Up @@ -17,6 +17,7 @@
import uuid

from . import handlers
from . import org
from .validation import validator
from .. import common
from .. import lora
Expand All @@ -29,8 +30,6 @@ class EngagementRequestHandler(handlers.OrgFunkRequestHandler):
function_key = mapping.ENGAGEMENT_KEY

def prepare_create(self, req):
c = lora.Connector()

org_unit = util.checked_get(req, mapping.ORG_UNIT,
{}, required=True)
org_unit_uuid = util.get_uuid(org_unit, required=True)
Expand All @@ -55,9 +54,9 @@ def prepare_create(self, req):
self.function_key, valid_from, valid_to, employee_uuid,
)

org_unit_obj = c.organisationenhed.get(org_unit_uuid)
org_uuid = org.get_configured_organisation(
util.get_mapping_uuid(req, mapping.ORG, required=False))["uuid"]

org_uuid = org_unit_obj['relationer']['tilhoerer'][0]['uuid']
job_function_uuid = util.get_mapping_uuid(req,
mapping.JOB_FUNCTION)
engagement_type_uuid = util.get_mapping_uuid(req,
Expand Down
8 changes: 4 additions & 4 deletions backend/mora/service/itsystem.py
Expand Up @@ -21,6 +21,7 @@
import flask

from . import handlers
from . import org
from .validation import validator
from .. import common
from .. import exceptions
Expand All @@ -45,15 +46,14 @@ def prepare_create(self, req):
if not system:
exceptions.ErrorCodes.E_NOT_FOUND()

# Get org unit uuid for validation purposes
org_unit = util.checked_get(req, mapping.ORG_UNIT,
{}, required=False)
org_unit = util.checked_get(req, mapping.ORG_UNIT, {}, required=False)
org_unit_uuid = util.get_uuid(org_unit, required=False)

employee = util.checked_get(req, mapping.PERSON, {}, required=False)
employee_uuid = util.get_uuid(employee, required=False)

org_uuid = system['relationer']['tilhoerer'][0]['uuid']
org_uuid = org.get_configured_organisation(
util.get_mapping_uuid(req, mapping.ORG, required=False))["uuid"]

valid_from, valid_to = util.get_validities(req)

Expand Down
9 changes: 3 additions & 6 deletions backend/mora/service/leave.py
Expand Up @@ -16,6 +16,7 @@
import uuid

from . import handlers
from . import org
from .validation import validator
from .. import common
from .. import exceptions
Expand All @@ -29,17 +30,13 @@ class LeaveRequestHandler(handlers.OrgFunkRequestHandler):
function_key = mapping.LEAVE_KEY

def prepare_create(self, req):
c = lora.Connector()

employee = util.checked_get(req, mapping.PERSON, {}, required=True)
employee_uuid = util.get_uuid(employee, required=True)

userobj = c.bruger.get(employee_uuid)
org_uuid = org.get_configured_organisation(
util.get_mapping_uuid(req, mapping.ORG, required=False))["uuid"]

if not userobj:
exceptions.ErrorCodes.E_USER_NOT_FOUND(employee_uuid=employee_uuid)

org_uuid = userobj['relationer']['tilhoerer'][0]['uuid']
leave_type_uuid = util.get_mapping_uuid(req, mapping.LEAVE_TYPE,
required=True)
valid_from, valid_to = util.get_validities(req)
Expand Down
17 changes: 6 additions & 11 deletions backend/mora/service/manager.py
Expand Up @@ -12,15 +12,15 @@
This section describes how to interact with employee manager roles.
"""
import uuid
import operator
import flask
import uuid

from . import address
from . import employee
from . import facet
from . import handlers
from . import org
from . import orgunit
from . import facet
from . import employee
from .validation import validator
from .. import common
from .. import lora
Expand Down Expand Up @@ -128,22 +128,17 @@ def get_one_mo_object(cls, effect, start, end, funcid):
def prepare_create(self, req):
""" To create a vacant manager postition, set employee_uuid to None
and set a value org_unit_uuid """
c = lora.Connector()

org_unit = util.checked_get(req, mapping.ORG_UNIT,
{}, required=True)
org_unit_uuid = util.get_uuid(org_unit, required=True)

employee = util.checked_get(req, mapping.PERSON, {}, required=False)
employee_uuid = util.get_uuid(employee, required=False)

# TODO: Figure out what to do with this
valid_from, valid_to = util.get_validities(req)

org_uuid = (
c.organisationenhed.get(org_unit_uuid)
['relationer']['tilhoerer'][0]['uuid']
)
org_uuid = org.get_configured_organisation(
util.get_mapping_uuid(req, mapping.ORG, required=False))["uuid"]

manager_type_uuid = util.get_mapping_uuid(req, mapping.MANAGER_TYPE)
manager_level_uuid = util.get_mapping_uuid(req, mapping.MANAGER_LEVEL)
Expand Down
9 changes: 0 additions & 9 deletions backend/mora/service/orgunit.py
Expand Up @@ -107,8 +107,6 @@ def get(cls, c, type, objid):
])

def prepare_create(self, req):
c = lora.Connector()

req = flask.request.get_json()

name = util.checked_get(req, mapping.NAME, "", required=True)
Expand All @@ -126,13 +124,6 @@ def prepare_create(self, req):
parent_uuid = util.get_mapping_uuid(req, mapping.PARENT, required=True)

org_uuid = org.get_configured_organisation()["uuid"]
organisationenhed_get = c.organisationenhed.get(parent_uuid)

if not (organisationenhed_get or parent_uuid == org_uuid):
exceptions.ErrorCodes.V_PARENT_NOT_FOUND(
parent_uuid=parent_uuid,
org_unit_uuid=unitid,
)

org_unit_type_uuid = util.get_mapping_uuid(req, mapping.ORG_UNIT_TYPE,
required=False)
Expand Down
9 changes: 3 additions & 6 deletions backend/mora/service/role.py
Expand Up @@ -17,6 +17,7 @@
import uuid

from . import handlers
from . import org
from .validation import validator
from .. import common
from .. import exceptions
Expand All @@ -30,8 +31,6 @@ class RoleRequestHandler(handlers.OrgFunkRequestHandler):
function_key = mapping.ROLE_KEY

def prepare_create(self, req):
c = lora.Connector()

org_unit = util.checked_get(req, mapping.ORG_UNIT,
{}, required=True)
org_unit_uuid = util.get_uuid(org_unit, required=True)
Expand All @@ -47,10 +46,8 @@ def prepare_create(self, req):
validator.is_date_range_in_employee_range(employee, valid_from,
valid_to)

org_uuid = (
c.organisationenhed.get(org_unit_uuid)
['relationer']['tilhoerer'][0]['uuid']
)
org_uuid = org.get_configured_organisation(
util.get_mapping_uuid(req, mapping.ORG, required=False))["uuid"]

role_type_uuid = util.get_mapping_uuid(req, mapping.ROLE_TYPE,
required=True)
Expand Down
39 changes: 0 additions & 39 deletions backend/tests/test_integration_address.py
Expand Up @@ -66,9 +66,6 @@ def test_create_errors(self, mock):
"type": "address",
"address_type": ean_class,
"value": '1234567890',
"org": {
'uuid': '456362c4-0ee4-4e5e-a72c-751239745e62',
},
"validity": {
"from": "2013-01-01",
"to": None,
Expand Down Expand Up @@ -102,9 +99,6 @@ def test_create_errors(self, mock):
"org_unit": {
'uuid': unitid,
},
"org": {
'uuid': '456362c4-0ee4-4e5e-a72c-751239745e62',
},
"validity": {
"from": "2013-01-01",
"to": None,
Expand Down Expand Up @@ -132,9 +126,6 @@ def test_create_errors(self, mock):
"type": "address",
"address_type": email_class,
"org_unit": {"uuid": unitid},
"org": {
'uuid': '456362c4-0ee4-4e5e-a72c-751239745e62',
},
# NB: no value
"validity": {
"from": "2017-01-01",
Expand Down Expand Up @@ -164,9 +155,6 @@ def test_create_errors(self, mock):
# NB: no type!
"address_type": None,
"value": "hallo@exmaple.com",
"org": {
'uuid': '456362c4-0ee4-4e5e-a72c-751239745e62',
},
"org_unit": {"uuid": unitid},
"validity": {
"from": "2013-01-01",
Expand Down Expand Up @@ -195,9 +183,6 @@ def test_create_errors(self, mock):
"address_type": address_class,
"value": "b1f1817d-5f02-4331-b8b3-97330a5d3197",
"org_unit": {"uuid": nothingid},
"org": {
'uuid': '456362c4-0ee4-4e5e-a72c-751239745e62',
},
"validity": {
"from": "2013-01-01",
"to": None,
Expand All @@ -223,9 +208,6 @@ def test_create_errors(self, mock):
"address_type": address_class,
"value": "b1f1817d-5f02-4331-b8b3-97330a5d3197",
"person": {"uuid": nothingid},
"org": {
'uuid': '456362c4-0ee4-4e5e-a72c-751239745e62',
},
"validity": {
"from": "2013-01-01",
"to": None,
Expand Down Expand Up @@ -272,9 +254,6 @@ def test_create_dar_address_fails_correctly(self, mock):
"validity": {
"from": "2017-01-02",
},
"org": {
'uuid': "456362c4-0ee4-4e5e-a72c-751239745e62"
},
}
]
)
Expand Down Expand Up @@ -338,9 +317,6 @@ def test_add_org_unit_address(self, mock):
"org_unit": {
"uuid": unitid
},
"org": {
'uuid': '456362c4-0ee4-4e5e-a72c-751239745e62',
},
"validity": {
"from": "2017-01-02",
},
Expand Down Expand Up @@ -445,9 +421,6 @@ def test_add_employee_address(self, mock):
"person": {
"uuid": employee_id
},
"org": {
'uuid': '456362c4-0ee4-4e5e-a72c-751239745e62',
},
"validity": {
"from": "2017-01-02",
},
Expand Down Expand Up @@ -589,9 +562,6 @@ def test_create_employee_with_address(self, mock):
json={
"name": "Torkild Testperson",
"cpr_no": "0101501234",
"org": {
'uuid': "456362c4-0ee4-4e5e-a72c-751239745e62"
},
"details": [
{
"type": "address",
Expand All @@ -602,9 +572,6 @@ def test_create_employee_with_address(self, mock):
"validity": {
"from": "2017-01-02",
},
"org": {
'uuid': "456362c4-0ee4-4e5e-a72c-751239745e62"
},
},
]
},
Expand Down Expand Up @@ -734,9 +701,6 @@ def test_create_manager_with_address(self, mock):
"validity": {
"from": "2017-01-02",
},
"org": {
'uuid': "456362c4-0ee4-4e5e-a72c-751239745e62"
},
}],
}],
amqp_topics={
Expand Down Expand Up @@ -855,9 +819,6 @@ def test_create_org_unit_with_address(self, mock):
"validity": {
"from": "2017-01-02",
},
"org": {
'uuid': "456362c4-0ee4-4e5e-a72c-751239745e62"
},
},
]
},
Expand Down

0 comments on commit f5eaf08

Please sign in to comment.