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

Function has_default_resource_access

core/station/impl/src/core/authorization.rs:70–117  ·  view source on GitHub ↗

Checks if the user had access to the resource based on default rules (non-permission based). e.g. the user has access to their own user record, etc...

(user: &User, resource: &Resource)

Source from the content-addressed store, hash-verified

68///
69/// e.g. the user has access to their own user record, etc...
70fn has_default_resource_access(user: &User, resource: &Resource) -> bool {
71 match &resource {
72 &Resource::Request(RequestResourceAction::Read(ResourceId::Id(request_id))) => {
73 match REQUEST_REPOSITORY.find_indexed_fields_by_request_id(request_id) {
74 None => false,
75 Some(request) => {
76 if request.approved_by.iter().any(|id| *id == user.id)
77 || request.rejected_by.iter().any(|id| *id == user.id)
78 || request.requested_by == user.id
79 {
80 return true;
81 }
82
83 let validator = RequestApprovalRightsEvaluator::new(
84 REQUEST_APPROVE_RIGHTS_REQUEST_POLICY_RULE_EVALUATOR.clone(),
85 user.id,
86 &request,
87 );
88
89 validator.evaluate().unwrap_or(false)
90 }
91 }
92 }
93
94 Resource::User(UserResourceAction::Read(ResourceId::Id(user_id))) => {
95 // The user has access to their own user record.
96 *user_id == user.id
97 }
98 Resource::Notification(action) => {
99 match action {
100 // The user can always list notifications.
101 NotificationResourceAction::List => true,
102 // The user cannot update arbitrary notifications.
103 NotificationResourceAction::Update(ResourceId::Any) => false,
104 NotificationResourceAction::Update(ResourceId::Id(id)) => {
105 let key = NotificationKey { id: *id };
106 if let Some(notification) = NOTIFICATION_REPOSITORY.get(&key) {
107 // The user has access to the user's own notifications.
108 notification.target_user_id == user.id
109 } else {
110 false
111 }
112 }
113 }
114 }
115 _ => false,
116 }
117}
118
119/// This function checks if the user has the required privilege to perform the given action.
120///

Callers 1

is_allowedMethod · 0.85

Calls 4

iterMethod · 0.80
evaluateMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected