Changing user permissions works.

dev
Philippe PITTOLI 2019-12-11 00:10:58 +01:00
parent 553a23956a
commit 73b76c0852
3 changed files with 34 additions and 17 deletions

View File

@ -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 {

View File

@ -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 + ", "
]

View File

@ -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