Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,9 @@ IDENTITY_OPTIONS = ['copersonid', 'orgidentityid']
### <a name="coperson"></a>[CoPerson API](https://spaces.at.internet2.edu/display/COmanage/CoPerson+API) (COmanage v3.3.0+)

- `copeople_add() -> dict`
- `### NOT IMPLEMENTED ###`
- Add a new CO Person. A person must have an OrgIdentity before they can be added to a CO.
- Note that linking to an OrgIdentity and invitations are separate operations.
- `copeople_delete() -> bool`
- `### NOT IMPLEMENTED ###`
- `copeople_delete(coperson_id: int) -> bool`
- Remove a CO Person. This method will also delete related data, such as `CoPersonRoles`, `EmailAddresses`,
and `Identifiers`.
- A person must be removed from any COs (CoPerson records must be deleted)
Expand Down
4 changes: 2 additions & 2 deletions comanage_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ def coorg_identity_links_view_one(self, coorg_identity_link_id: int):
def copeople_add(self):
return copeople_add(self)

def copeople_delete(self):
return copeople_delete(self)
def copeople_delete(self, coperson_id: int):
return copeople_delete(self, coperson_id=coperson_id)

def copeople_edit(self):
return copeople_edit(self)
Expand Down
102 changes: 85 additions & 17 deletions comanage_api/_copeople.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
Methods
-------
copeople_add() -> dict
### NOT IMPLEMENTED ###
Add a new CO Person. A person must have an OrgIdentity before they can be added to a CO.
Note that linking to an OrgIdentity and invitations are separate operations.
copeople_delete() -> bool
### NOT IMPLEMENTED ###
copeople_delete(coperson_id: int) -> bool
Remove a CO Person. This method will also delete related data, such as CoPersonRoles, EmailAddresses,
and Identifiers. A person must be removed from any COs (CoPerson records must be deleted)
before the OrgIdentity record can be removed.
Expand Down Expand Up @@ -41,37 +39,107 @@

def copeople_add(self) -> dict:
"""
### NOT IMPLEMENTED ###
Add a new CO Person. A person must have an OrgIdentity before they can be added to a CO.
Note that linking to an OrgIdentity and invitations are separate operations.

:param self:
:return
501 Server Error: Not Implemented for url: mock://not_implemented_501.local:
:request
{
"RequestType":"CoPeople",
"Version":"1.0",
"CoPeople":
[
{
"Version":"1.0",
"CoId":"<CoId>",
"Timezone":"<Timezone>",
"DateOfBirth":"<DateOfBirth>",
"Status":("Active"|"Approved"|"Confirmed"|"Declined"|"Deleted"|"Denied"|
"Duplicate"|"Expired"|"GracePeriod"|"Invited"|"Locked"|"Pending"|
"PendingApproval"|"PendingConfirmation"|
"PendingVetting"|"Suspended")
}
]
}:

Response Format
HTTP Status Response Body Description
201 Added NewObjectResponse CoPerson created
400 Bad Request CoPerson Request not
provided in POST body
400 Invalid Fields ErrorResponse An error in one or more
provided fields
401 Unauthorized Authentication required
403 Co Does Not Exist The specified Co does not exist
500 Other Error Unknown error
"""
url = self._MOCK_501_URL
resp = self._mock_session.get(
url=url
post_body = {
"RequestType":"CoPeople",
"Version":"1.0",
"CoPeople":
[
{
"Version":"1.0",
"CoId":"<CoId>",
"Status":"Active"
}
]
}

post_body['CoPeople'][0]['CoId'] = self._CO_API_ORG_ID

post_body = json.dumps(post_body)
url = self._CO_API_URL + '/co_people.json'
resp = self._s.post(
url=url,
data=post_body
)
if resp.status_code == 201:
return json.loads(resp.text)
else:
resp.raise_for_status()


def copeople_delete(self) -> bool:
def copeople_delete(self, coperson_id: int) -> bool:
"""
### NOT IMPLEMENTED ###
Remove a CO Person. This method will also delete related data, such as CoPersonRoles, EmailAddresses,
and Identifiers. A person must be removed from any COs (CoPerson records must be deleted)
before the OrgIdentity record can be removed.

:param self:
:return
501 Server Error: Not Implemented for url: mock://not_implemented_501.local:
:request
{
"RequestType":"CoPeople",
"Version":"1.0",
"CoPeople":
[
{
"Version":"1.0",
"CoId":"<CoId>",
"Timezone":"<Timezone>",
"DateOfBirth":"<DateOfBirth>",
"Status":("Active"|"Approved"|"Confirmed"|"Declined"|"Deleted"|"Denied"|
"Duplicate"|"Expired"|"GracePeriod"|"Invited"|"Locked"|"Pending"|
"PendingApproval"|"PendingConfirmation"|
"PendingVetting"|"Suspended")
}
]
}:

Response Format
HTTP Status Response Body Description
200 Deleted OrgPerson deleted
400 Invalid Fields id not provided
401 Unauthorized Authentication required
403 CoPersonRole Exists The Person has one or more Person
Role records and cannot be deleted
403 CouPerson Exists in Unowned COU The Person has a role in one
or more COUs that the authenitcated
user does not control
404 OrgIdentity Unknown id not found
500 Other Error Unknown error
"""
url = self._MOCK_501_URL
resp = self._mock_session.get(

url = self._CO_API_URL + '/co_people/' + str(coperson_id) + '.json'
resp = self._s.delete(
url=url
)
if resp.status_code == 200:
Expand Down
7 changes: 5 additions & 2 deletions examples/copeople_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
# copeople_delete() -> bool
print('### copeople_delete')
try:
delete_copeople = api.copeople_delete()
print(json.dumps(delete_copeople, indent=4))
per_co_copeople = api.copeople_view_per_co()
if per_co_copeople['CoPeople']:
coperson_id = int(per_co_copeople['CoPeople'][0]['Id'])
delete_copeople = api.copeople_delete(coperson_id=coperson_id)
print(delete_copeople)
except HTTPError as err:
print('[ERROR] Exception caught')
print('--> ', type(err).__name__, '-', err)
Expand Down