Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F9582984
roles.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
roles.js
View Options
const
get_matching_roles_counter
=
async
function
(
app
,
context
,
allowed_roles
)
{
const
user_id
=
context
.
user_id
;
const
user_roles
=
(
await
app
.
run_action
(
new
app
.
Sealious
.
SuperContext
(
context
),
[
"collections"
,
"user-roles"
],
"show"
,
{
filter
:
{
user
:
user_id
}
}
)).
items
.
map
(
role_resource
=>
role_resource
.
role
);
return
allowed_roles
.
filter
(
allowed_role
=>
user_roles
.
includes
(
allowed_role
)
).
length
;
};
module
.
exports
=
app
=>
({
name
:
"roles"
,
getRestrictingQuery
:
async
(
context
,
params
)
=>
{
if
(
context
.
user_id
===
null
)
{
return
new
app
.
Query
.
DenyAll
();
}
const
matching_roles_counter
=
await
get_matching_roles_counter
(
app
,
context
,
params
);
return
matching_roles_counter
>
0
?
new
app
.
Query
.
AllowAll
()
:
new
app
.
Query
.
DenyAll
();
},
checker_function
:
async
(
context
,
params
)
=>
{
if
(
context
.
user_id
===
null
)
{
return
Promise
.
reject
(
"You're not logged in!"
);
}
const
allowed_roles
=
params
;
const
matching_roles_counter
=
await
get_matching_roles_counter
(
app
,
context
,
allowed_roles
);
return
matching_roles_counter
>
0
?
Promise
.
resolve
()
:
Promise
.
reject
(
`Action allowed only for users with role
${
allowed_roles
.
join
(
", "
)
}
.`
);
},
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 11, 08:24 (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
984049
Default Alt Text
roles.js (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment