From 553a23956a93294ffed83fe9fdcb95fc029b8cb8 Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Tue, 10 Dec 2019 14:24:58 +0100
Subject: [PATCH] project edition can manage user permissions
---
client/project-creation-modal.ls | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/client/project-creation-modal.ls b/client/project-creation-modal.ls
index cb8ffeb..f6cb40d 100644
--- a/client/project-creation-modal.ls
+++ b/client/project-creation-modal.ls
@@ -34,6 +34,24 @@ permission-groups =
"Write"
"Admin"
+permissions-add = (self, permission, user-id) ->
+ perm-list = self.permissions.find (e) -> e[0] == 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
+ # 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 ]]
+
permission-to-form-selection = (self, permission) ->
h \option {
value: permission
@@ -100,7 +118,9 @@ ProjectCreationModal = (project, todod-ws, users) ->
h \aside.menu [
h \p.menu-label [ "Permissions" ]
h \ul.menu-list self.permissions.map (permission) ->
- h \li [
+ h \li {
+ key: "permission" + permission[0]
+ } [
h \p permission.map (e, index) ->
if index == 0
"Permissions '" + e + "': "
@@ -142,8 +162,7 @@ ProjectCreationModal = (project, todod-ws, users) ->
# TODO:
# adding the permissions in self.permissions
# then editing the project in the db via todod-ws
- # self.permissions
- console.log "right: #{self.tmp.new-user-permission.permission}, user #{self.tmp.new-user-permission.uid}"
+ permissions-add self, self.tmp.new-user-permission.permission, self.tmp.new-user-permission.uid
} [ "+" ]
]