Skip to content

Commit

Permalink
refactor: drop requester and owner from user specifier (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
keplervital authored Apr 29, 2024
1 parent 708e2ae commit 2d437ba
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 149 deletions.
1 change: 1 addition & 0 deletions apps/wallet/public/.well-known/ic-domains
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
orbitwallet.io
alpha.orbitwallet.io
staging.orbitwallet.io
testing.orbitwallet.io
dev.orbitwallet.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
variant="plain"
density="comfortable"
hide-details
:disabled="isViewMode"
disabled
/>
</VCol>
<VCol cols="12" class="pt-4 pb-0">
Expand All @@ -22,7 +22,7 @@
:rules="[requiredRule]"
variant="filled"
density="comfortable"
:disabled="isViewMode"
:disabled="isViewMode || !!model.id"
@selected-asset="onSelectedAsset"
/>
</VCol>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import {
mapRequestPolicyRuleUserSpecifierEnumToVariant,
mapRequestPolicyRuleUserSpecifierToEnum,
} from '~/mappers/request-specifiers.mapper';
import { RequestPolicyRuleUserSpecifierEnum } from '~/types/station.types';
import { variantIs } from '~/utils/helper.utils';
const input = withDefaults(
Expand Down Expand Up @@ -104,16 +103,8 @@ const disabledSlider = ref(false);
watch(
() => userTypeModel.value,
userType => {
switch (userType) {
case RequestPolicyRuleUserSpecifierEnum.Requester:
model.value.min_approved = 100;
disabledSlider.value = true;
break;
default:
disabledSlider.value = false;
break;
}
_ => {
disabledSlider.value = false;
},
{ immediate: true },
);
Expand Down
13 changes: 2 additions & 11 deletions apps/wallet/src/components/request-policies/rule/QuorumRule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import {
mapRequestPolicyRuleUserSpecifierToEnum,
} from '~/mappers/request-specifiers.mapper';
import { FormValidationRules } from '~/types/helper.types';
import { RequestPolicyRuleUserSpecifierEnum } from '~/types/station.types';
import { intNumberRangeRule, requiredRule } from '~/utils/form.utils';
import { variantIs } from '~/utils/helper.utils';
Expand Down Expand Up @@ -130,16 +129,8 @@ const disabledInput = ref(false);
watch(
() => userTypeModel.value,
userType => {
switch (userType) {
case RequestPolicyRuleUserSpecifierEnum.Requester:
model.value.min_approved = 1;
disabledInput.value = true;
break;
default:
disabledInput.value = false;
break;
}
_ => {
disabledInput.value = false;
},
{ immediate: true },
);
Expand Down
2 changes: 0 additions & 2 deletions apps/wallet/src/generated/station/station.did
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ type UserSpecifier = variant {
Any;
Id : vec UUID;
Group : vec UUID;
Owner;
Requester;
};

type ResourceSpecifier = variant {
Expand Down
4 changes: 1 addition & 3 deletions apps/wallet/src/generated/station/station.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,7 @@ export type UserResourceAction = { 'List' : null } |
{ 'Update' : ResourceId };
export type UserSpecifier = { 'Id' : Array<UUID> } |
{ 'Any' : null } |
{ 'Group' : Array<UUID> } |
{ 'Requester' : null } |
{ 'Owner' : null };
{ 'Group' : Array<UUID> };
export type UserStatus = { 'Inactive' : null } |
{ 'Active' : null };
export interface _SERVICE {
Expand Down
2 changes: 0 additions & 2 deletions apps/wallet/src/generated/station/station.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ export const idlFactory = ({ IDL }) => {
'Id' : IDL.Vec(UUID),
'Any' : IDL.Null,
'Group' : IDL.Vec(UUID),
'Requester' : IDL.Null,
'Owner' : IDL.Null,
});
const Quorum = IDL.Record({
'min_approved' : IDL.Nat16,
Expand Down
12 changes: 0 additions & 12 deletions apps/wallet/src/mappers/request-specifiers.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ export const mapRequestSpecifierToEnum = (specifier: RequestSpecifier): RequestS
export const mapRequestPolicyRuleUserSpecifierToEnum = (
specifier: UserSpecifier,
): RequestPolicyRuleUserSpecifierEnum => {
if (variantIs(specifier, 'Owner')) {
return RequestPolicyRuleUserSpecifierEnum.Owner;
}

if (variantIs(specifier, 'Requester')) {
return RequestPolicyRuleUserSpecifierEnum.Requester;
}

if (variantIs(specifier, 'Any')) {
return RequestPolicyRuleUserSpecifierEnum.Any;
}
Expand All @@ -100,10 +92,6 @@ export const mapRequestPolicyRuleUserSpecifierEnumToVariant = (
specifier: RequestPolicyRuleUserSpecifierEnum,
): UserSpecifier => {
switch (specifier) {
case RequestPolicyRuleUserSpecifierEnum.Owner:
return { Owner: null };
case RequestPolicyRuleUserSpecifierEnum.Requester:
return { Requester: null };
case RequestPolicyRuleUserSpecifierEnum.Any:
return { Any: null };
case RequestPolicyRuleUserSpecifierEnum.Group:
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet/src/stores/station.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export const createUserInitialAccount = async (
user_groups: [],
users: [userId],
},
configs_request_policy: [{ Quorum: { min_approved: 100, approvers: { Owner: null } } }],
transfer_request_policy: [{ Quorum: { min_approved: 100, approvers: { Owner: null } } }],
configs_request_policy: [{ Quorum: { min_approved: 1, approvers: { Id: [userId] } } }],
transfer_request_policy: [{ Quorum: { min_approved: 1, approvers: { Id: [userId] } } }],
},
},
});
Expand Down
2 changes: 0 additions & 2 deletions apps/wallet/src/types/station.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ export enum RequestPolicyRuleEnum {
}

export enum RequestPolicyRuleUserSpecifierEnum {
Owner = 'Owner',
Requester = 'Requester',
Any = 'Any',
Group = 'Group',
Id = 'Id',
Expand Down
10 changes: 6 additions & 4 deletions canister_ids.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"app_wallet": {
"playground": "bxkhk-6yaaa-aaaal-ai6va-cai",
"production": "5fu67-giaaa-aaaal-ajbla-cai",
"testing": "l3uq6-ryaaa-aaaal-adu2a-cai"
},
"control_panel": {
"playground": "b6jmw-iqaaa-aaaal-ai6uq-cai",
"production": "5mxvd-qaaaa-aaaal-ajbkq-cai",
"testing": "lotbt-qqaaa-aaaal-aduzq-cai"
},
"ui": {
"playground": "bxkhk-6yaaa-aaaal-ai6va-cai",
"testing": "l3uq6-ryaaa-aaaal-adu2a-cai"
}
}
2 changes: 0 additions & 2 deletions core/station/api/spec.did
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ type UserSpecifier = variant {
Any;
Id : vec UUID;
Group : vec UUID;
Owner;
Requester;
};

type ResourceSpecifier = variant {
Expand Down
2 changes: 0 additions & 2 deletions core/station/api/src/request_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ pub enum UserSpecifierDTO {
Any,
Group(Vec<UuidDTO>),
Id(Vec<UuidDTO>),
Owner,
Requester,
}

#[derive(CandidType, Deserialize, Debug, Clone)]
Expand Down
41 changes: 3 additions & 38 deletions core/station/impl/src/core/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use crate::{
request_specifier::{
Match, RequestSpecifier, UserInvolvedInPolicyRuleForRequestResource, UserSpecifier,
},
EvaluationStatus, Request, RequestId, RequestOperation, RequestStatusCode, User, UserId,
UserStatus,
EvaluationStatus, Request, RequestId, RequestStatusCode, User, UserId, UserStatus,
},
repositories::{
request_policy::REQUEST_POLICY_REPOSITORY, REQUEST_REPOSITORY, USER_REPOSITORY,
Expand Down Expand Up @@ -237,39 +236,6 @@ impl
UserSpecifier::Group(group_ids) => {
possible_approvers.groups.extend(group_ids.to_owned());

Ok(possible_approvers)
}
UserSpecifier::Requester => {
possible_approvers
.users
.insert(request.requested_by.to_owned());

Ok(possible_approvers)
}
UserSpecifier::Owner => {
match &request.operation {
RequestOperation::EditUser(operation) => {
possible_approvers
.users
.insert(operation.input.user_id.to_owned());
}
RequestOperation::EditAccount(_)
| RequestOperation::Transfer(_)
| RequestOperation::AddAccount(_)
| RequestOperation::AddAddressBookEntry(_)
| RequestOperation::AddRequestPolicy(_)
| RequestOperation::AddUser(_)
| RequestOperation::AddUserGroup(_)
| RequestOperation::EditAddressBookEntry(_)
| RequestOperation::RemoveAddressBookEntry(_)
| RequestOperation::EditPermission(_)
| RequestOperation::EditRequestPolicy(_)
| RequestOperation::EditUserGroup(_)
| RequestOperation::RemoveRequestPolicy(_)
| RequestOperation::RemoveUserGroup(_)
| RequestOperation::ChangeCanister(_) => {}
};

Ok(possible_approvers)
}
},
Expand Down Expand Up @@ -460,7 +426,7 @@ mod tests {
user_test_utils::{self, mock_user},
Account, AccountKey, AddUserGroupOperation, AddUserGroupOperationInput, Blockchain,
BlockchainStandard, EvaluatedRequestPolicyRule, Metadata, MetadataItem, Percentage,
RequestPolicy, RequestStatus, ADMIN_GROUP_ID,
RequestOperation, RequestPolicy, RequestStatus, ADMIN_GROUP_ID,
},
repositories::{
request_policy::REQUEST_POLICY_REPOSITORY, ACCOUNT_REPOSITORY,
Expand Down Expand Up @@ -508,8 +474,7 @@ mod tests {
REQUEST_REPOSITORY.insert(request.to_key(), request.clone());

policy.specifier = RequestSpecifier::AddUserGroup;
policy.rule =
RequestPolicyRule::QuorumPercentage(UserSpecifier::Requester, Percentage(100));
policy.rule = RequestPolicyRule::QuorumPercentage(UserSpecifier::Any, Percentage(100));

REQUEST_POLICY_REPOSITORY.insert(policy.id, policy.clone());

Expand Down
4 changes: 0 additions & 4 deletions core/station/impl/src/mappers/request_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ impl From<UserSpecifierDTO> for UserSpecifier {
.map(|id| *HelperMapper::to_uuid(id).expect("invalid uuid").as_bytes())
.collect(),
),
UserSpecifierDTO::Owner => UserSpecifier::Owner,
UserSpecifierDTO::Requester => UserSpecifier::Requester,
}
}
}
Expand All @@ -186,8 +184,6 @@ impl From<UserSpecifier> for UserSpecifierDTO {
.map(|id| Uuid::from_bytes(id).hyphenated().to_string())
.collect::<Vec<_>>(),
),
UserSpecifier::Owner => UserSpecifierDTO::Owner,
UserSpecifier::Requester => UserSpecifierDTO::Requester,
}
}
}
Expand Down
55 changes: 6 additions & 49 deletions core/station/impl/src/models/request_specifier.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use super::resource::{Resource, ResourceId, ResourceIds, UserResourceAction};
use super::{MetadataItem, Request, RequestId, RequestKey, RequestOperation, RequestOperationType};
use crate::errors::RecordValidationError;
use crate::models::user::User;
use crate::repositories::{ADDRESS_BOOK_REPOSITORY, REQUEST_REPOSITORY};

use super::resource::{Resource, ResourceIds};
use super::{MetadataItem, Request, RequestId, RequestOperation, RequestOperationType};
use crate::core::validation::{
EnsureAccount, EnsureAddressBookEntry, EnsureIdExists, EnsureRequestPolicy,
EnsureResourceIdExists, EnsureUser, EnsureUserGroup,
};
use crate::errors::RecordValidationError;
use crate::models::user::User;
use crate::repositories::ADDRESS_BOOK_REPOSITORY;
use crate::services::ACCOUNT_SERVICE;
use crate::{errors::MatchError, repositories::USER_REPOSITORY};
use anyhow::anyhow;
use orbit_essentials::model::{ModelValidator, ModelValidatorResult};
use orbit_essentials::repository::Repository;
use orbit_essentials::storable;
Expand All @@ -23,14 +21,12 @@ pub enum UserSpecifier {
Any,
Group(Vec<UUID>),
Id(Vec<UUID>),
Owner,
Requester,
}

impl ModelValidator<RecordValidationError> for UserSpecifier {
fn validate(&self) -> Result<(), RecordValidationError> {
match self {
UserSpecifier::Any | UserSpecifier::Owner | UserSpecifier::Requester => Ok(()),
UserSpecifier::Any => Ok(()),
UserSpecifier::Group(group_ids) => {
for group_id in group_ids {
EnsureUserGroup::id_exists(group_id)?;
Expand Down Expand Up @@ -195,34 +191,6 @@ impl Match<UserInvolvedInPolicyRuleForRequestResource> for UserMatcher {
Ok(false)
}
UserSpecifier::Id(ids) => Ok(ids.contains(&input.user_id)),
UserSpecifier::Owner => {
for resource in input.request_operation_resources {
let is_match = match resource {
Resource::User(UserResourceAction::Update(user_resource)) => {
match user_resource {
ResourceId::Any => false, // not a real match
ResourceId::Id(edit_user_id) => edit_user_id == input.user_id,
}
}
_ => false,
};

if is_match {
return Ok(true);
}
}

Ok(false)
}
UserSpecifier::Requester => {
if let Some(request) = REQUEST_REPOSITORY.get(&RequestKey {
id: input.request_id,
}) {
Ok(request.requested_by == input.user_id)
} else {
Err(MatchError::UnexpectedError(anyhow!("Request not found")))
}
}
}
}
}
Expand Down Expand Up @@ -497,11 +465,6 @@ mod tests {
[1; 16], // approver
UserSpecifier::Id(vec![[1; 16]]), // specifier
),
(
[0; 16], // requester
[0; 16], // approver
UserSpecifier::Requester, // specifier
),
];

for tc in tcs {
Expand All @@ -528,12 +491,6 @@ mod tests {
disable_mock_resource_validation();

UserSpecifier::Any.validate().expect("Any should be valid");
UserSpecifier::Owner
.validate()
.expect("Owner should be valid");
UserSpecifier::Requester
.validate()
.expect("Requester should be valid");
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ while [[ $# -gt 0 ]]; do
;;
--production)
shift
set_network prod
set_network production
exec_function setup_enviroment
identity_warning_confirmation
exec_function deploy_control_panel
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/src/transfer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ fn make_transfer_successful() {
},
transfer_request_policy: Some(RequestPolicyRuleDTO::QuorumPercentage(
QuorumPercentageDTO {
approvers: UserSpecifierDTO::Owner,
approvers: UserSpecifierDTO::Id(vec![user_dto.id.clone()]),
min_approved: 100,
},
)),
configs_request_policy: Some(RequestPolicyRuleDTO::QuorumPercentage(
QuorumPercentageDTO {
approvers: UserSpecifierDTO::Owner,
approvers: UserSpecifierDTO::Id(vec![user_dto.id.clone()]),
min_approved: 100,
},
)),
Expand Down

0 comments on commit 2d437ba

Please sign in to comment.