From 73b76c08528fd726e8793228e11643b60fe8e93d Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Wed, 11 Dec 2019 00:10:58 +0100 Subject: [PATCH] Changing user permissions works. --- client/authd.ls | 9 +++++++++ client/project-creation-modal.ls | 30 +++++++++++++----------------- client/todowebsocket.ls | 12 ++++++++++++ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/client/authd.ls b/client/authd.ls index 80d3adb..b4afbc3 100644 --- a/client/authd.ls +++ b/client/authd.ls @@ -22,6 +22,7 @@ module.exports = { "update-password": 8 "list-users": 9 + "set-permissions": 10 } response-types = { @@ -114,6 +115,14 @@ module.exports = { key: "nico-nico-nii" } + self.set-permissions = (list-id, user-id, permission) -> + self.send request-types[\set-permissions], JSON.stringify { + token: self.token + list: list-id + uid: user-id + permission: permission + } + # TODO: authd overhaul #self.add-user = (login, password) -> # self.send request-types[\add-user], JSON.stringify { diff --git a/client/project-creation-modal.ls b/client/project-creation-modal.ls index f6cb40d..e21b28d 100644 --- a/client/project-creation-modal.ls +++ b/client/project-creation-modal.ls @@ -30,27 +30,24 @@ user-form-selection = (self, user) -> } [ user.login ] permission-groups = - "Read" - "Write" - "Admin" + "read" + "post" + "edit" + "admin" permissions-add = (self, permission, user-id) -> - perm-list = self.permissions.find (e) -> e[0] == permission + perm-list = self.permissions[permission] if perm-list is-already-there = perm-list.find (e) -> (""+ e) == ("" + user-id) if is-already-there console.log "user #{user-id} already in #{perm-list}" else - perm-list ++= [ user-id ] - self.permissions := self.permissions.map (e) -> - if e[0] == permission - perm-list - else - e + perm-list ++= [ parseInt(user-id) ] + self.permissions[permission] := perm-list # console.log "adding user #{user-id} to #{perm-list[0]}: #{perm-list}" else console.log "Cannot find #{permission} permissions, creating it" - self.permissions ++= [ [ permission, user-id ]] + self.permissions[permission] := user-id permission-to-form-selection = (self, permission) -> h \option { @@ -70,8 +67,7 @@ ProjectCreationModal = (project, todod-ws, users) -> self = { title: project.title || "" - permissions: project.permissions || [[]] - # new-user: "New user" + permissions: project.permissions || {admin: [], edit: [], post: [], read: []} tmp: new-user-permission: @@ -117,13 +113,13 @@ ProjectCreationModal = (project, todod-ws, users) -> h \aside.menu [ h \p.menu-label [ "Permissions" ] - h \ul.menu-list self.permissions.map (permission) -> + h \ul.menu-list Object.keys(self.permissions).map (permission) -> h \li { - key: "permission" + permission[0] + key: "permission" + permission } [ - h \p permission.map (e, index) -> + h \p self.permissions[permission].map (e, index) -> if index == 0 - "Permissions '" + e + "': " + "Permissions '" + permission + "': " + e + ", " else "" + e + ", " ] diff --git a/client/todowebsocket.ls b/client/todowebsocket.ls index 64e46f3..0e517b5 100644 --- a/client/todowebsocket.ls +++ b/client/todowebsocket.ls @@ -87,30 +87,35 @@ module.exports = { self.list-lists = -> self.send request-types[\list-lists], JSON.stringify { token: self.token + id: "list-lists" } self.get-list = (list-id) -> self.send request-types[\get-list], JSON.stringify { token: self.token list: list-id + id: "get-list" } self.get-tasks = (list-id) -> self.send request-types[\get-tasks], JSON.stringify { token: self.token list: list-id + id: "get-tasks" } self.get-task = (task-id) -> self.send request-types[\get-task], JSON.stringify { token: self.token task: task-id + id: "get-task" } self.remove-list = (list-id) -> self.send request-types[\remove-list], JSON.stringify { token: self.token list: list-id + id: "remove-list" } # TODO: extra properties @@ -118,6 +123,7 @@ module.exports = { payload = { token: self.token title: title + id: "add-list" } for key, value of opts @@ -129,6 +135,7 @@ module.exports = { payload = { token: self.token list: list-id + id: "edit-list" } for key, value of opts @@ -140,6 +147,7 @@ module.exports = { self.send request-types[\remove-task], JSON.stringify { token: self.token task: task-id + id: "remove-task" } # TODO: extra properties @@ -148,6 +156,7 @@ module.exports = { token: self.token list: list-id title: title + id: "add-task" } for key, value of opts @@ -159,6 +168,7 @@ module.exports = { payload = { token: self.token task: task-id + id: "edit-task" } for key, value of opts @@ -170,12 +180,14 @@ module.exports = { self.send request-types[\subscribe], JSON.stringify { token: self.token list: list-id + id: "subscribe" } self.unsubscribe = (list-id) -> self.send request-types[\unsubscribe], JSON.stringify { token: self.token list: list-id + id: "unsubscribe" } self