diff --git a/README.md b/README.md index b6e4268..3518f7a 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,10 @@ If you find any issues or would like to help contribute to the project, please r | ---- | --------------- | | GET /servers/:serverid/channels | Get all channels in a server | | GET /servers/:serverid/channels/:channelid | Get a channel from a server by ID | +| PATCH /servers/:serverid/channels/:channelid | Update specific channel attributes by ID | | POST /servers/:serverid/channels | Create Channel, formdata: name&parent | | GET /servers/:serverid/channels/:channelid/acl | Get ACL list for channel ID | +| PATCH /servers/:serverid/channels/:channelid/acl | Update specific channel ACL by channel ID | | DELETE /servers/:serverid/channels/:channelid | Delete Channel | diff --git a/app/api.py b/app/api.py index 257f651..93dd73b 100644 --- a/app/api.py +++ b/app/api.py @@ -448,6 +448,51 @@ def channel_new_channel(self, id): return Response(json.dumps(data, sort_keys=True, indent=4), mimetype='application/json') + @route('/channels/', 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('/channels/', 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('/channels//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() + 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('/sendmessage', methods=['POST']) def send_message(self, id):