Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F996435
user-referenced-in-field.subtest.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
user-referenced-in-field.subtest.ts
View Options
import
assert
from
"assert"
;
import
{
withStoppedApp
}
from
"../../../test_utils/with-test-app"
;
import
{
Collection
}
from
"../../../main"
;
describe
(
"user-referenced-in-field"
,
()
=>
{
it
(
"should deny if the user isn't the one referenced in the field and allow if it is"
,
async
()
=>
withStoppedApp
(
async
({
app
,
rest_api
})
=>
{
Collection
.
fromDefinition
(
app
,
{
name
:
"pets"
,
fields
:
[
{
name
:
"name"
,
type
:
"text"
},
{
name
:
"owner"
,
type
:
"single_reference"
,
params
:
{
collection
:
"users"
},
},
],
access_strategy
:
{
create
:
"public"
,
default
:
[
"user-referenced-in-field"
,
"owner"
],
},
});
await
app
.
start
();
for
(
let
username
of
[
"Alice"
,
"Bob"
])
{
const
user
=
await
app
.
runAction
(
new
app
.
Sealious
.
SuperContext
(),
[
"collections"
,
"users"
],
"create"
,
{
username
:
username
,
password
:
"password"
,
email
:
`
${
username
.
toLowerCase
()
}
@example.com`
,
}
);
await
app
.
runAction
(
new
app
.
Sealious
.
SuperContext
(),
[
"collections"
,
"pets"
],
"create"
,
{
name
:
`
${
username
}
's pet`
,
owner
:
user
.
id
}
);
}
const
alice_session
=
await
rest_api
.
login
({
username
:
"Alice"
,
password
:
"password"
,
});
const
{
items
}
=
await
rest_api
.
get
(
"/api/v1/collections/pets"
,
alice_session
);
assert
.
equal
(
items
.
length
,
1
);
assert
.
equal
(
items
[
0
].
name
,
"Alice's pet"
);
}));
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Dec 24, 14:03 (10 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557257
Default Alt Text
user-referenced-in-field.subtest.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment