Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010502
user-roles.ts
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
user-roles.ts
View Options
import
{
App
,
Collection
,
FieldTypes
,
Policies
,
ActionName
,
Policy
,
}
from
"../../main"
;
export
default
class
UserRoles
extends
Collection
{
name
=
"user-roles"
;
fields
=
{
role
:
new
FieldTypes
.
Enum
((
app
:
App
)
=>
app
.
ConfigManager
.
get
(
"roles"
)
).
setRequired
(
true
),
user
:
new
FieldTypes
.
SingleReference
(
"users"
),
};
policies
=
{
create
:
new
Policies
.
Roles
([
"admin"
]),
delete
:
new
Policies
.
Public
(),
show
:
new
Policies
.
UserReferencedInField
(
"user"
),
edit
:
new
Policies
.
Noone
(),
}
as
{
[
policy
:
string
]
:
Policy
};
// this `as` statement allows the policies to be overwritten;
async
init
(
app
:
App
,
collection_name
:
string
)
{
await
super
.
init
(
app
,
collection_name
);
app
.
on
(
"started"
,
async
()
=>
{
const
roles
=
app
.
collections
[
"user-roles"
];
for
(
let
action
of
[
"create"
,
"delete"
]
as
ActionName
[])
{
const
policy
=
roles
.
getPolicy
(
action
);
if
(
policy
instanceof
Policies
.
Public
)
{
app
.
Logger
.
warn
(
"USER POLICY"
,
`<user-roles> collection is using <public> access strategy for
${
action
}
action. Anyone can change anyone elses role. This is the default behavior and you should overwrite it with <set_policy>`
);
}
}
});
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, May 7, 19:43 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
636118
Default Alt Text
user-roles.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment