-
Notifications
You must be signed in to change notification settings - Fork 33
Add channel update API & channel acl update API #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0b2a0aa
1f2c7e3
44943f9
65f62c1
2a4ab97
103757b
c1a4ea9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -448,6 +448,51 @@ def channel_new_channel(self, id): | |
|
|
||
| return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json') | ||
|
|
||
| @route('<int:id>/channels/<int:channel_id>', methods=['PATCH']) | ||
| def update_channel(self, id, channel_id): | ||
| """ Update specific channel attributes | ||
| """ | ||
|
|
||
| server = meta.getServer(id) | ||
|
|
||
| # Return 404 if not found | ||
| if server is None: | ||
| return jsonify(message="Not Found"), 404 | ||
|
|
||
| # Return 404 if not found | ||
| channel = server.getChannelState(channel_id) | ||
| if channel is None: | ||
| return jsonify(message="Not Found"), 404 | ||
|
|
||
| name = request.form.get('name') | ||
| parent = request.form.get('parent') | ||
| description = request.form.get('description') | ||
| links = request.form.getlist('links[]') | ||
| description = request.form.get('description') | ||
| position = request.form.get('position') | ||
| temporary = request.form.get('temporary') | ||
|
|
||
| if name is not None: | ||
| channel.name = str(name) | ||
| if parent is not None: | ||
| channel.parent = int(parent) | ||
| if description is not None: | ||
| channel.description = str(description) | ||
| if links is not None: | ||
| for idx in range(len(links)): | ||
| links[idx] = int(links[idx]) | ||
| channel.links = links | ||
| if position is not None: | ||
| channel.position = int(position) | ||
| if temporary is not None: | ||
| channel.temporary = bool(temporary) | ||
|
|
||
| server.setChannelState(channel) | ||
|
|
||
| data = obj_to_dict(server.getChannelState(channel_id)) | ||
|
|
||
| return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json') | ||
|
|
||
| @conditional(auth.login_required, auth_enabled) | ||
| @route('<int:id>/channels/<channel>', methods=['DELETE']) | ||
| def channel_del_channel(self, id, channel): | ||
|
|
@@ -580,6 +625,59 @@ def channel_acl(self, id, channel_id): | |
| data = obj_to_dict(server.getACL(channel_id)) | ||
| return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json') | ||
|
|
||
| @conditional(auth.login_required, auth_enabled) | ||
| @route('<int:id>/channels/<int:channel_id>/acl', methods=['PATCH']) | ||
| def update_channel_acl(self, id, channel_id): | ||
| """ Update specific channel ACL | ||
| """ | ||
|
|
||
| server = meta.getServer(id) | ||
|
|
||
| # Return 404 if not found | ||
| if server is None: | ||
| return jsonify(message="Not Found"), 404 | ||
|
|
||
| origin_acl = server.getACL(channel_id) | ||
| update_acls = origin_acl[0] | ||
| update_groups = origin_acl[1] | ||
| update_inherit = origin_acl[2] | ||
|
|
||
| params = request.get_json() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you're reading the request JSON body here. However, all of the methods read via multipart form data, so I would rather not change it if possible. Looking back at the project, I do wish I went with reading the JSON body instead though. 🙂
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is ok. Can back to use form data.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here form data with array, you have any idea? |
||
| if "acls" in params and params['acls'] is not None: | ||
| new_acls = [] | ||
| for props in params['acls']: | ||
| new_acls.append(Murmur.ACL( | ||
| props['applyHere'], | ||
| props['applySubs'], | ||
| props['inherited'], | ||
| props['userid'], | ||
| props['group'], | ||
| props['allow'], | ||
| props['deny']) | ||
| ) | ||
| update_acls = new_acls | ||
|
|
||
| if "groups" in params and params['groups'] is not None: | ||
| new_groups = [] | ||
| for props in params['groups']: | ||
| new_groups.append(Murmur.Group( | ||
| props['name'], | ||
| props['inherited'], | ||
| props['inherit'], | ||
| props['inheritable'], | ||
| props['add'], | ||
| props['remove']) | ||
| ) | ||
| update_groups = new_groups | ||
|
|
||
| if "inherit" in params and params['inherit'] is not None: | ||
| update_inherit = bool(params['inherit']) | ||
|
|
||
| server.setACL(channel_id, update_acls, update_groups, update_inherit) | ||
|
|
||
| data = obj_to_dict(server.getACL(channel_id)) | ||
| return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json') | ||
|
|
||
| @conditional(auth.login_required, auth_enabled) | ||
| @route('<int:id>/sendmessage', methods=['POST']) | ||
| def send_message(self, id): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain what's going on here with the ACL settings. It's been a while since I've worked on Murmur Slice API, so I'm a bit rusty. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh this part, I want to follow RESTful PATCH.
Example :
If this request only pass
acls, not passgroupsandinherit, will only update acls.update_groups will be groups of
origin_acl, update_inherit will be inherit oforigin_acl.And update_acls will be
new_aclson
server.setACL(channel_id, update_acls, update_groups, update_inherit)