MCPcopy Create free account
hub / github.com/dfinity/orbit / is_allowed

Method is_allowed

core/station/impl/src/core/authorization.rs:23–64  ·  view source on GitHub ↗
(ctx: &CallContext, resource: &Resource)

Source from the content-addressed store, hash-verified

21
22impl Authorization {
23 pub fn is_allowed(ctx: &CallContext, resource: &Resource) -> bool {
24 // If the call is made by the system, then the access is granted by default.
25 if ctx.caller_is_controller_or_self() {
26 return true;
27 }
28
29 // Gets the expanded list of resources.
30 // e.g. if the resource is for account(1), then the list will expand to [account(1), account(any)]
31 let resources = resource.to_expanded_list();
32
33 // Checks if the caller has access to the requested resource.
34 resources.iter().any(|resource| {
35 let permission = PERMISSION_SERVICE.get_permission(resource);
36
37 // Checks if the resource is public, if so, then the access is granted.
38 if permission.allowed_public() {
39 return true;
40 }
41
42 if let Some(user) = ctx.user() {
43 // If the user is not active, then the access is denied.
44 if !user.is_active() {
45 return false;
46 }
47
48 // If the resource is available to authenticated users, then the access is granted.
49 if permission.allowed_authenticated() {
50 return true;
51 }
52
53 // Validates if the user has access to the resource based on the default rules (non-permission based).
54 if has_default_resource_access(user, resource) {
55 return true;
56 }
57
58 // Checks if the user has access to the resource based on the system permissions.
59 return permission.is_allowed(user);
60 }
61
62 false
63 })
64 }
65}
66
67/// Checks if the user had access to the resource based on default rules (non-permission based).

Callers

nothing calls this directly

Calls 9

to_expanded_listMethod · 0.80
iterMethod · 0.80
allowed_publicMethod · 0.80
is_activeMethod · 0.80
allowed_authenticatedMethod · 0.80
get_permissionMethod · 0.45
userMethod · 0.45

Tested by

no test coverage detected