Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Azat Alimov
POD
Commits
858d1270
Commit
858d1270
authored
1 year ago
by
Szymon
Browse files
Options
Download
Email Patches
Plain Diff
use find or create
parent
218ecaad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libpod/src/authorization_service.rs
+16
-53
libpod/src/authorization_service.rs
with
16 additions
and
53 deletions
+16
-53
libpod/src/authorization_service.rs
+
16
-
53
View file @
858d1270
...
...
@@ -93,84 +93,47 @@ pub async fn init_service(init_db: &InitDb) -> Result<()> {
/// Sets the connection Alice - GrantAccess -> Bob
pub
async
fn
grant_access
(
tx
:
&
AsyncTx
,
owner_key
:
&
str
,
req
:
&
GrantAccessReq
)
->
Result
<
()
>
{
// TODO: add scope to Alice database, using her key?
// TODO: check if target account exists?
let
mut
nodes
=
vec!
[];
// Get or create source
let
mut
res
=
graphql
::
execute_query_with_args
(
let
source_id
=
get_item_or_create
(
tx
,
"query {
PodOwnerNode(filter: {ownerKey: {eq: ARG1 }}) {
id,
}
}"
,
PodOwnerNode(filter: {ownerKey: {eq: ARG1 }}) {
id,
}
}"
,
&
[
json!
(
owner_key
)],
)
.await
?
;
debug!
(
"source result: {res:#?}"
);
let
source_id
=
if
let
Some
(
source
)
=
res
.pop_front
()
{
source
.id
}
else
{
let
source_id
=
ItemId
::
new
();
nodes
.push
(
json!
(
json!
(
{
"name"
:
"PodOwnerNode"
,
"id"
:
source_id
,
"properties"
:
{
"ownerKey"
:
owner_key
}
}));
source_id
};
}),
)
.await
?
;
// Get or create target
let
mut
res
=
graphql
::
execute_query_with_args
(
let
target_id
=
get_item_or_create
(
tx
,
"query {
PodOwnerNode(filter: {ownerKey: {eq: ARG1 }}) {
id,
}
}"
,
PodOwnerNode(filter: {ownerKey: {eq: ARG1 }}) {
id,
}
}"
,
&
[
json!
(
req
.to
)],
)
.await
?
;
debug!
(
"target result: {res:#?}"
);
let
target_id
=
if
let
Some
(
target
)
=
res
.pop_front
()
{
target
.id
}
else
{
let
target_id
=
ItemId
::
new
();
nodes
.push
(
json!
(
json!
(
{
"name"
:
"PodOwnerNode"
,
"id"
:
target_id
,
"properties"
:
{
"ownerKey"
:
req
.to
.as_str
()
}
}));
target_id
};
v5
::
internal_api
::
create_item_tx
(
tx
,
&
serde_json
::
from_value
(
json!
({
"nodes"
:
nodes
}))
.unwrap
(),
}),
)
.await
?
;
// Get or create edge
let
edge
=
v5
::
internal_api
::
get_edge_between_source_and_target
(
tx
,
&
source_id
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets