Skip to content

Commit

Permalink
Merge pull request #1503 from slntopp/dev
Browse files Browse the repository at this point in the history
Fix link and join update
  • Loading branch information
loathedrobot authored Feb 28, 2024
2 parents ab80301 + 6e42991 commit 4466244
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/graph/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,41 @@ func (ctrl *AccountsController) Update(ctx context.Context, acc Account, patch m

// Grant account access to namespace
func (acc *Account) LinkNamespace(ctx context.Context, edge driver.Collection, ns Namespace, level access.Level, role string) error {
_, err := edge.CreateDocument(ctx, Access{
a := Access{
From: acc.ID,
To: ns.ID,
Level: level,
Role: role,
DocumentMeta: driver.DocumentMeta{
Key: acc.Key + "-" + ns.Key,
},
})
}

if _, err := edge.UpdateDocument(ctx, a.DocumentMeta.Key, a); err == nil {
return nil
}

_, err := edge.CreateDocument(ctx, a)
return err
}

// Grant namespace access to account
func (acc *Account) JoinNamespace(ctx context.Context, edge driver.Collection, ns Namespace, level access.Level, role string) error {
_, err := edge.CreateDocument(ctx, Access{
a := Access{
From: ns.ID,
To: acc.ID,
Level: level,
Role: role,
DocumentMeta: driver.DocumentMeta{
Key: ns.Key + "-" + acc.Key,
},
})
}

if _, err := edge.UpdateDocument(ctx, a.DocumentMeta.Key, a); err == nil {
return nil
}

_, err := edge.CreateDocument(ctx, a)
return err
}

Expand Down

0 comments on commit 4466244

Please sign in to comment.