Skip to content

Commit b292de0

Browse files
committed
Fixed the update_role method similarly to the way create_new_role was fixed. Permissions are now passed in as a dict that gets flattened into the payload.
1 parent 26ac790 commit b292de0

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

canvas_sdk/methods/roles.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def create_new_role(request_ctx, account_id, role, base_role_type=None, permissi
6767
:param base_role_type: (optional) Specifies the role type that will be used as a base for the permissions granted to this role. Defaults to 'AccountMembership' if absent
6868
:type base_role_type: string or None
6969
:param permissions: (optional) Specifies the permissions that will be granted to this role. See Canvas API docs for details on the structure.
70-
:type base_role_type: dict
70+
:type permissions: dict
7171
:return: Create a new role
7272
:rtype: requests.Response (with Role data)
7373
@@ -138,7 +138,7 @@ def activate_role(request_ctx, account_id, role, **request_kwargs):
138138
return response
139139

140140

141-
def update_role(request_ctx, account_id, role, permissions_X_explicit=None, permissions_X_enabled=None, **request_kwargs):
141+
def update_role(request_ctx, account_id, role, label=None, permissions={}, **request_kwargs):
142142
"""
143143
Update permissions for an existing role.
144144
@@ -157,20 +157,24 @@ def update_role(request_ctx, account_id, role, permissions_X_explicit=None, perm
157157
:type account_id: string
158158
:param role: (required) ID
159159
:type role: string
160-
:param permissions_X_explicit: (optional) no description
161-
:type permissions_X_explicit: boolean or None
162-
:param permissions_X_enabled: (optional) These arguments are described in the documentation for the {api:RoleOverridesController#add_role add_role method}.
163-
:type permissions_X_enabled: boolean or None
160+
:param label: The label for the role. Can only change the label of a custom role that belongs directly to the account.
161+
:type label: string
162+
:param permissions: (optional) Specifies the permissions that will be granted to this role. See Canvas API docs for details on the structure.
163+
:type permissions: dict
164164
:return: Update a role
165165
:rtype: requests.Response (with Role data)
166166
167167
"""
168168

169169
path = '/v1/accounts/{account_id}/roles/{role}'
170-
payload = {
171-
'permissions[X][explicit]' : permissions_X_explicit,
172-
'permissions[X][enabled]' : permissions_X_enabled,
173-
}
170+
payload = {}
171+
if label and label != '':
172+
payload['label'] = label
173+
# flatten the permissions dict
174+
for p in permissions:
175+
for a in permissions[p]:
176+
payload['permissions[{}][{}]'.format(p, a)] = permissions[p][a]
177+
174178
url = request_ctx.base_api_url + path.format(account_id=account_id, role=role)
175179
response = client.put(request_ctx, url, payload=payload, **request_kwargs)
176180

0 commit comments

Comments
 (0)