Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3893815
control-access.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
control-access.ts
View Options
import
{
Field
,
Context
,
Policy
,
HybridField
,
App
,
ExtractStorage
,
}
from
"../../../main"
;
import
{
ExtractParams
,
ExtractOutput
}
from
"../../../chip-types/field"
;
type
Params
<
T
extends
Field
>
=
{
target_policies
:
{
[
key
in
"show"
|
"edit"
]
:
Policy
};
value_when_not_allowed
:
ExtractOutput
<
T
>
;
};
export
default
class
ControlAccess
<
T
extends
Field
>
extends
HybridField
<
T
>
{
typeName
=
"control-access"
;
edit_strategy
:
Policy
;
show_strategy
:
Policy
;
value_when_not_allowed
:
ExtractOutput
<
T
>
;
app
:
App
;
constructor
(
base_field
:
T
,
params
:
Params
<
T
>
)
{
super
(
base_field
);
this
.
edit_strategy
=
params
.
target_policies
.
edit
;
this
.
show_strategy
=
params
.
target_policies
.
show
;
this
.
value_when_not_allowed
=
params
.
value_when_not_allowed
;
}
async
isProperValue
(
context
:
Context
,
new_value
:
Parameters
<
T
[
"checkValue"
]
>
[
1
],
old_value
:
Parameters
<
T
[
"checkValue"
]
>
[
2
]
)
{
if
(
!
context
.
is_super
)
{
const
result
=
await
this
.
edit_strategy
.
check
(
context
);
if
(
result
&&
!
result
?
.
allowed
)
{
return
Field
.
invalid
(
result
.
reason
);
}
}
return
this
.
virtual_field
.
checkValue
(
context
,
new_value
,
old_value
);
}
async
decode
(
context
:
Context
,
value_in_db
:
ExtractStorage
<
T
>
,
old_value
:
ExtractOutput
<
T
>
,
format_params
:
ExtractParams
<
T
>
)
{
if
(
!
context
.
is_super
)
{
context
.
app
.
Logger
.
debug2
(
"CONTROL ACCESS"
,
`Checking the access to field
${
this
.
name
}
...`
,
{
value_in_db
}
);
const
result
=
await
this
.
show_strategy
.
check
(
context
);
if
(
result
&&
!
result
.
allowed
)
{
context
.
app
.
Logger
.
debug2
(
"CONTROL ACCESS"
,
`Access to field '
${
this
.
name
}
' not allowed!`
,
result
);
value_in_db
=
await
this
.
encode
(
context
,
this
.
value_when_not_allowed
);
}
else
if
(
result
?
.
allowed
)
{
context
.
app
.
Logger
.
debug2
(
"CONTROL ACCESS"
,
`Access to field '
${
this
.
name
}
' is allowed!`
,
result
);
}
}
const
ret
=
await
this
.
virtual_field
.
decode
(
context
,
value_in_db
,
old_value
,
format_params
);
return
ret
;
}
hasDefaultValue
()
{
return
this
.
virtual_field
.
hasDefaultValue
();
}
getDefaultValue
(
context
:
Context
)
{
return
this
.
virtual_field
.
getDefaultValue
(
context
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Mon, May 19, 00:55 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
661352
Default Alt Text
control-access.ts (2 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment