forked from sourcenetwork/defradb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR: Rename and split to permission package
- Loading branch information
1 parent
78a9b65
commit 0e573d5
Showing
5 changed files
with
63 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package fetcher | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sourcenetwork/defradb/acp" | ||
"github.com/sourcenetwork/defradb/db/permission" | ||
) | ||
|
||
// runDocReadPermissionCheck handles the checking (while fetching) if the document has read access | ||
// or not, according to our access logic based on weather (1) the request is permissioned, | ||
// (2) the collection is permissioned (has a policy), (3) acp module exists. | ||
func (df *DocumentFetcher) runDocReadPermissionCheck(ctx context.Context) error { | ||
hasPermission, err := permission.CheckDocPermissionedAccessOnCollection( | ||
ctx, | ||
df.acp, | ||
df.col, | ||
acp.ReadPermission, | ||
df.kv.Key.DocID, | ||
) | ||
|
||
if err != nil { | ||
df.passedPermissionCheck = false | ||
return err | ||
} | ||
|
||
df.passedPermissionCheck = hasPermission | ||
return nil | ||
} |