Skip to content

Commit c9265b3

Browse files
committed
update including names in permissions
1 parent f678f9a commit c9265b3

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ Anyone who has even one of these roles assigned will be able to view the documen
106106
* `admin`... is a role for testing-purposes, new features, etc...
107107
* `teacher`... see everything (except for admin-only). So when you make a document visible to users with the role, let's say `5chif`, then you don't have to specify `teacher`. That is implied.
108108
* You gain a role either by getting the OU= value set by LDAP (`Teachers` gets translated to `teacher` and `Students` to `students`), or by assigning a client-role with that name.
109+
* The name of the user works as permission-role as well. So in the case of this test-setup here the user 'student' has first-name 'Stu' and last-name 'Dent'; So the viable permission for this user would be `@@@ Stu Dent`.
110+
* Roles are case-insensitive. So putting `@@@ Stu Dent, 4BHIF` is the same as putting `@@@ stu dent, 4bhif`.
109111
* If the directive is in the first line of the document (the very first line), then it applies to the whole document.
110112
* In that case, there is no end-directive.
111113
* Documents that are hidden for a viewer will not be displayed to that viewer, even if the viewer has a direct-link.
@@ -140,6 +142,7 @@ Some text in a document only visible to users with the `4bhif` OR `4chif` OR `5a
140142
#### File-Content Restrictions
141143
Put the security directive in the middle of your documents' content.
142144
Don't forget to put in an end-directive in this case.
145+
These directives cannot be nested!
143146

144147
```markdown
145148
# Some Docuemnt

md/test-perms.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ The following paragraph is only visible to 5BHIF:
1313
@@@
1414

1515
# User Permission
16-
The following paragraph is only visible to Gerald Unterrainer
17-
@@@ Gerald Unterrainer
18-
>Only visible to Gerald Unterrainer
16+
The following paragraph is only visible to Stu Dent
17+
@@@ Stu Dent
18+
>Only visible to Stu Dent
1919
2020
@@@
21-
# Nested Permission
21+
# NO Nested Permissions!
22+
Nested permissions don't work due to the way we parse the permission-declarations (regexp).
23+
2224
The following paragraph is only visible to 5BHIF:
2325
@@@ 5bhif
2426
>Only visible to users in 5BHIF group.

utils.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,15 @@ async function hasRoles(req, clientRoles, all, override) {
105105
// console.log("attributes", attributes);
106106
if (attributes && attributes.attributes && attributes.attributes.config) {
107107
const a = JSON.parse(attributes.attributes.config);
108-
const r = JSON.parse(req.user.rolesCalculated);
108+
let r = JSON.parse(req.user.rolesCalculated);
109109
// console.log("Roles Calculated", r);
110+
if (r === undefined || r === null) {
111+
r = {};
112+
}
113+
let name = req.user.name
114+
name = name.trim()
115+
name = name.toLowerCase()
116+
r[name] = true;
110117
const cr = await getClientRoles(req, clientRoles);
111118
if (cr) {
112119
for (const role of cr) {

0 commit comments

Comments
 (0)