Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 9 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ ic-certification = { git = "https://github.com/dfinity/response-verification", r
ic-certified-assets = { git = "https://github.com/dfinity/sdk.git", rev = "d65717bd6d0c172247c37dd23395c9fb13b2ba20" }
ic-http-certification = { git = "https://github.com/dfinity/response-verification", rev = "da70db93832f88ecc556ae082612aedec47d3816" }
ic-representation-independent-hash = { git = "https://github.com/dfinity/response-verification", rev = "da70db93832f88ecc556ae082612aedec47d3816" }
ic-cdk = "0.16.0"
ic-cdk-macros = "0.16.0"
ic-cdk = "0.17.1"
ic-cdk-macros = "0.17.1"
ic-cdk-timers = "0.11.0"
ic-ledger-types = "0.14.0"
ic-stable-structures = "0.6.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@ describe('CanisterIcSettingsForm', () => {

expect(canisterIdInput.exists()).toBe(true);
});

it('shows three select items for log visibility', () => {
const form = mount(CanisterIcSettingsForm, {
props: {
modelValue: { canisterId: Principal.anonymous(), log_visibility: { public: null } },
display: { canisterId: true },
},
});

const select = form.findComponent({ name: 'VSelect' });

expect(select.exists()).toBe(true);
expect(select.vm.items.length).toEqual(3);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
:hint="$t('external_canisters.native_settings.freezing_threshold_hint')"
/>
<VSelect
v-model="model.log_visibility"
v-model="logVisibilitySelected"
:items="logVisibilityItems"
:label="$t('external_canisters.native_settings.log_visibility')"
:hint="$t('external_canisters.native_settings.log_visibility_hint')"
Expand All @@ -189,6 +189,78 @@
item-value="value"
item-title="text"
/>
<VCard
v-if="!!model.log_visibility && variantIs(model.log_visibility, 'allowed_viewers')"
variant="elevated"
>
<template #subtitle>
{{ $t('terms.allowed_viewers') }}
</template>
<template #text>
<VTable density="compact" hover>
<tbody>
<tr v-for="(principal, idx) in model.log_visibility.allowed_viewers" :key="idx">
<td class="pa-2 w-100">
<div :class="{ 'd-inline': !app.isMobile }">
<TextOverflow
:text="principal.toText()"
:max-length="app.isMobile ? 24 : 64"
/>

<VBtn
size="x-small"
variant="text"
:icon="mdiContentCopy"
@click="
copyToClipboard({
textToCopy: principal.toText(),
sendNotification: true,
})
"
/>
</div>
</td>
<td v-if="!props.readonly" class="px-1 min-height-100 text-right">
<VBtn
size="small"
variant="text"
density="comfortable"
:icon="mdiTrashCanOutline"
@click="model.log_visibility.allowed_viewers.splice(idx, 1)"
/>
</td>
</tr>
</tbody>
</VTable>
<VTextField
v-if="!props.readonly"
v-model="newLogPrincipalString"
:label="$t('external_canisters.add_principal')"
name="new_log_principal"
density="comfortable"
class="mt-2"
:rules="[validPrincipalRule, uniqueRule(existingPrincipals)]"
@keydown.enter.stop.prevent="canAddLogPrincipal ? addLogPrincipal() : undefined"
>
<template #append>
<VBtn
:disabled="!canAddLogPrincipal"
color="primary"
variant="flat"
size="small"
:icon="mdiPlus"
@click="addLogPrincipal"
/>
</template>
</VTextField>
<span
v-if="props.readonly && !model.log_visibility.allowed_viewers.length"
class="mt-2"
>
{{ $t('external_canisters.no_controllers') }}
</span>
</template>
</VCard>
</VCol>
</VRow>
</VContainer>
Expand Down Expand Up @@ -220,8 +292,8 @@ import { numberRangeRule, requiredRule, uniqueRule, validPrincipalRule } from '~
import TextOverflow from '../TextOverflow.vue';
import CanisterIdField from '../inputs/CanisterIdField.vue';
import { CanisterIcSettingsModel } from './external-canisters.types';
import { LogVisibility } from '~/generated/station/station.did';
import { useI18n } from 'vue-i18n';
import { variantIs } from '~/utils/helper.utils.ts';

const props = withDefaults(
defineProps<{
Expand Down Expand Up @@ -253,6 +325,7 @@ const valid = ref(true);
const i18n = useI18n();
const fieldsWithErrors = ref<string[]>([]);
const newController = ref<string>('');
const newLogPrincipalString = ref<string>('');
const app = useAppStore();
const station = useStationStore();
const initialModel = ref<string>('');
Expand Down Expand Up @@ -329,7 +402,7 @@ const hasMaxControllers = computed(
const canAddController = computed(
() =>
form.value?.errors.find(error => error.id === 'new_controller') === undefined &&
newControllerPrincipal.value &&
newLogPrincipalString.value &&
!hasMaxControllers.value,
);

Expand Down Expand Up @@ -366,12 +439,92 @@ const addController = () => {
newController.value = '';
};

const logVisibilityItems = computed<SelectItem<LogVisibility>[]>(() => [
{ value: { controllers: null }, text: i18n.t('terms.controllers') },
{ value: { public: null }, text: i18n.t('terms.public') },
const existingControllers = computed(() => model.value.controllers?.map(c => c.toText()) || []);

enum LogVisibilityEnum {
Controllers = 'controllers',
Public = 'public',
AllowedViewers = 'allowed_viewers',
}

// temporary parsing of the log_visibility field to support the new variant type
const logVisibilitySelected = computed({
get: () => {
if (model.value.log_visibility) {
if (LogVisibilityEnum.AllowedViewers in model.value.log_visibility) {
return LogVisibilityEnum.AllowedViewers;
}
if (LogVisibilityEnum.Public in model.value.log_visibility) {
return LogVisibilityEnum.Public;
}
if (LogVisibilityEnum.Controllers in model.value.log_visibility) {
return LogVisibilityEnum.Controllers;
}
}

return null;
},
set: newValue => {
if (newValue) {
switch (newValue) {
case LogVisibilityEnum.Controllers:
model.value.log_visibility = { controllers: null };
break;
case LogVisibilityEnum.Public:
model.value.log_visibility = { public: null };
break;
case LogVisibilityEnum.AllowedViewers:
model.value.log_visibility = { allowed_viewers: [] };
break;
}
}
},
});

const logVisibilityItems = computed<SelectItem[]>(() => [
{ value: LogVisibilityEnum.Controllers, text: i18n.t('terms.controllers') },
{ value: LogVisibilityEnum.Public, text: i18n.t('terms.public') },
{ value: LogVisibilityEnum.AllowedViewers, text: i18n.t('terms.allowed_viewers') },
]);

const existingControllers = computed(() => model.value.controllers?.map(c => c.toText()) || []);
const canAddLogPrincipal = computed(
() =>
form.value?.errors.find(error => error.id === 'new_log_principal') === undefined &&
newLogPrincipalString.value,
);

const addLogPrincipal = () => {
if (
!newLogPrincipal.value ||
!model.value.log_visibility ||
!('allowed_viewers' in model.value.log_visibility)
) {
logger.warn('Unexpected code path, newLogPrincipalString should be defined');
return;
}

const currentPrincipals = model.value.log_visibility.allowed_viewers || [];

model.value.log_visibility.allowed_viewers = [...currentPrincipals, newLogPrincipal.value];

newLogPrincipalString.value = '';
};

const newLogPrincipal = computed(() => {
try {
return Principal.fromText(newLogPrincipalString.value);
} catch {
return undefined;
}
});

const existingPrincipals = computed(
() =>
(model.value.log_visibility &&
'allowed_viewers' in model.value.log_visibility &&
model.value.log_visibility.allowed_viewers?.map(p => p.toText())) ||
[],
);

const revalidate = async (): Promise<boolean> => {
const { valid: isValid, errors } = form.value
Expand Down
1 change: 1 addition & 0 deletions apps/wallet/src/generated/station/station.did
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,7 @@ type CanisterStatusInput = record {
type LogVisibility = variant {
public;
controllers;
allowed_viewers: vec principal;
};

type DefiniteCanisterSettings = record {
Expand Down
3 changes: 2 additions & 1 deletion apps/wallet/src/generated/station/station.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,8 @@ export type ListUsersResult = {
} |
{ 'Err' : Error };
export type LogVisibility = { 'controllers' : null } |
{ 'public' : null };
{ 'public' : null } |
{ 'allowed_viewers' : Array<Principal> };
export interface ManageSystemInfoOperation {
'input' : ManageSystemInfoOperationInput,
}
Expand Down
1 change: 1 addition & 0 deletions apps/wallet/src/generated/station/station.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ export const idlFactory = ({ IDL }) => {
const LogVisibility = IDL.Variant({
'controllers' : IDL.Null,
'public' : IDL.Null,
'allowed_viewers' : IDL.Vec(IDL.Principal),
});
const DefiniteCanisterSettingsInput = IDL.Record({
'freezing_threshold' : IDL.Opt(IDL.Nat),
Expand Down
2 changes: 2 additions & 0 deletions apps/wallet/src/locales/en.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ export default {
top_up_hint: 'Amount of cycles to add to the target canister.',
monitor_hint: 'Configuration for automated monitoring of cycles.',
add_controller: 'Add controller',
add_principal: 'Add principal',
no_controllers: 'No controllers',
self_controller: 'Self controlled',
non_orbit_controllers_warning:
Expand Down Expand Up @@ -667,6 +668,7 @@ export default {
controllers: 'Controllers',
restore: 'Restore',
public: 'Public',
allowed_viewers: 'Allowed viewers',
execute: 'Execute',
error: 'Error',
self: 'Self',
Expand Down
Loading
Loading