Skip to content

Commit

Permalink
Merge pull request #4194 from JoinColony/bug/4192-safe-control-permis…
Browse files Browse the repository at this point in the history
…sions

Update permissions for Safe Control actions
  • Loading branch information
ArmandoGraterol authored Feb 9, 2023
2 parents 02621bc + f09cc7f commit 31fb27a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 62 deletions.
8 changes: 4 additions & 4 deletions src/i18n/en-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const eventsMessageDescriptors = {
[`event.${ColonyAndExtensionsEvents.ColonyMetadata}.logo`]: `{initiator} changed this colony's logo`,
[`event.${ColonyAndExtensionsEvents.ColonyMetadata}.tokens`]: `{initiator} changed this colony's tokens`,
[`event.${ColonyAndExtensionsEvents.ColonyMetadata}.verifiedAddresses`]: `{initiator} updated this colony's address book`,
[`event.${ColonyAndExtensionsEvents.ColonyMetadata}.safeRemoved`]: `{initiator} removed {removedSafesString} using the Administration permission`,
[`event.${ColonyAndExtensionsEvents.ColonyMetadata}.safeAdded`]: `{initiator} added the Safe {addedSafeAddress} from {chainName} using the Administration permission`,
[`event.${ColonyAndExtensionsEvents.ColonyMetadata}.safeRemoved`]: `{initiator} removed {removedSafesString} using the Root permission`,
[`event.${ColonyAndExtensionsEvents.ColonyMetadata}.safeAdded`]: `{initiator} added the Safe {addedSafeAddress} from {chainName} using the Root permission`,
[`event.${ColonyAndExtensionsEvents.ColonyMetadata}.fallback`]: `{initiator} changed this colony's metadata, but the values are the same`,
[`event.${ColonyAndExtensionsEvents.DomainMetadata}.all`]: `{initiator} changed teams's name, description, color from {oldName}, {oldDescription}, {oldColor} to {domainName}, {domainPurpose}, {domainColor}`,
[`event.${ColonyAndExtensionsEvents.DomainMetadata}.nameDescription`]: `{initiator} changed teams's name and description from {oldName}, {oldDescription} to {domainName}, {domainPurpose}`,
Expand All @@ -44,11 +44,11 @@ const eventsMessageDescriptors = {
true {{safeTransactionRecipient}}
other {{safeTransactionRawTransactionAddress}}
}`,
[`event.${ColonyAndExtensionsEvents.ArbitraryTransaction}.transferFunds`]: `{safeName} made a payment using the Administration and Funding permissions to pay {safeTransactionAmount} from {fromDomain} to {isSafeTransactionRecipientUser, select,
[`event.${ColonyAndExtensionsEvents.ArbitraryTransaction}.transferFunds`]: `{safeName} made a payment using the Root permission to pay {safeTransactionAmount} to {isSafeTransactionRecipientUser, select,
true {{safeTransactionRecipient}}
other {{safeTransactionAddress}}
}`,
[`event.${ColonyAndExtensionsEvents.ArbitraryTransaction}.transferNFT`]: `{safeName} made a payment using the Administration and Funding permissions to pay with NFT token called {safeTransactionNftToken} from {fromDomain} to {isSafeTransactionRecipientUser, select,
[`event.${ColonyAndExtensionsEvents.ArbitraryTransaction}.transferNFT`]: `{safeName} made a payment using the Root permission to pay with NFT token called {safeTransactionNftToken} to {isSafeTransactionRecipientUser, select,
true {{safeTransactionRecipient}}
other {{safeTransactionAddress}}
}`,
Expand Down
5 changes: 1 addition & 4 deletions src/modules/dashboard/components/ActionsPage/staticMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ export const EVENT_ROLES_MAP: EventRolesMap = {
ColonyRole.Root,
ColonyRole.Arbitration,
],
[ColonyAndExtensionsEvents.ArbitraryTransaction]: [
ColonyRole.Root,
ColonyRole.Administration,
],
[ColonyAndExtensionsEvents.ArbitraryTransaction]: [ColonyRole.Root],
[ColonyAndExtensionsEvents.Generic]: [],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
canEnterRecoveryMode,
hasRoot,
canArchitect,
canFund,
canAdminister,
} from '~modules/users/checks';

const MSG = defineMessages({
Expand All @@ -24,7 +22,7 @@ const MSG = defineMessages({
},
permissionsText: {
id: 'dashboard.AdvancedDialog.permissionsText',
defaultMessage: `You must have the {permissionsList} permissions in the
defaultMessage: `You must have the {permission} permission in the
relevant teams, in order to take this action`,
},
managePermissionsTitle: {
Expand Down Expand Up @@ -65,8 +63,8 @@ const MSG = defineMessages({
defaultMessage:
'New colony network version available? Get your colony’s swole on here.',
},
upgradePermissionsList: {
id: 'dashboard.AdvancedDialog.upgradePermissionsList',
rootActionsPermission: {
id: 'dashboard.AdvancedDialog.rootActionsPermission',
defaultMessage: 'root',
},
editColonyDetailsTitle: {
Expand Down Expand Up @@ -95,10 +93,6 @@ const MSG = defineMessages({
defaultMessage:
'Control a Safe (multi-sig) on another chain with your colony',
},
adminFundingPermissions: {
id: 'dashboard.AdvancedDialog.adminFundingPermissions',
defaultMessage: 'funding and administration or root',
},
});

interface CustomWizardDialogProps extends ActionDialogProps {
Expand Down Expand Up @@ -146,10 +140,7 @@ const AdvancedDialog = ({
const { isVotingExtensionEnabled } = useEnabledExtensions({
colonyAddress: colony.colonyAddress,
});
const canManageSafes =
hasRegisteredProfile &&
canFund(allUserRoles) &&
(canAdminister(allUserRoles) || hasRoot(allUserRoles));
const canManageSafes = hasRegisteredProfile && hasRoot(allUserRoles);

const items = [
{
Expand All @@ -162,7 +153,7 @@ const AdvancedDialog = ({
),
permissionInfoText: MSG.permissionsText,
permissionInfoTextValues: {
permissionsList: (
permission: (
<FormattedMessage {...MSG.managePermissionsPermissionList} />
),
},
Expand All @@ -178,7 +169,7 @@ const AdvancedDialog = ({
permissionRequired: !canEnterRecovery,
permissionInfoText: MSG.permissionsText,
permissionInfoTextValues: {
permissionsList: <FormattedMessage {...MSG.recoveryPermissionsList} />,
permission: <FormattedMessage {...MSG.recoveryPermissionsList} />,
},
disabled: !isSupportedColonyVersion,
dataTest: 'recoveryDialogIndexItem',
Expand All @@ -190,7 +181,7 @@ const AdvancedDialog = ({
permissionRequired: !(hasRootPermission || isVotingExtensionEnabled),
permissionInfoText: MSG.permissionsText,
permissionInfoTextValues: {
permissionsList: <FormattedMessage {...MSG.upgradePermissionsList} />,
permission: <FormattedMessage {...MSG.rootActionsPermission} />,
},
onClick: () => callStep(nextStepVersionUpgrade),
},
Expand All @@ -201,7 +192,7 @@ const AdvancedDialog = ({
permissionRequired: !(hasRootPermission || isVotingExtensionEnabled),
permissionInfoText: MSG.permissionsText,
permissionInfoTextValues: {
permissionsList: <FormattedMessage {...MSG.upgradePermissionsList} />,
permission: <FormattedMessage {...MSG.rootActionsPermission} />,
},
onClick: () => callStep(nextStepEditDetails),
dataTest: 'updateColonyDialogIndexItem',
Expand All @@ -215,7 +206,7 @@ const AdvancedDialog = ({
permissionRequired: !canManageSafes,
permissionInfoText: MSG.permissionsText,
permissionInfoTextValues: {
permissionsList: <FormattedMessage {...MSG.adminFundingPermissions} />,
permission: <FormattedMessage {...MSG.rootActionsPermission} />,
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { defineMessages, FormattedMessage } from 'react-intl';
import { FieldArray, FieldArrayRenderProps, FormikProps } from 'formik';
import {
ColonyRole,
VotingReputationExtensionVersion,
ColonyVersion,
} from '@colony/colony-js';
Expand All @@ -20,12 +19,19 @@ import { SingleSafePicker, filterUserSelection } from '~core/SingleUserPicker';
import IconTooltip from '~core/IconTooltip';

import { SAFE_INTEGRATION_LEARN_MORE } from '~externalUrls';
import { Colony, ColonySafe, SafeTransaction } from '~data/index';
import {
Colony,
ColonySafe,
SafeTransaction,
useLoggedInUser,
} from '~data/index';
import { useDialogActionPermissions } from '~utils/hooks/useDialogActionPermissions';
import { PrimitiveType } from '~types/index';
import { SelectedSafe } from '~modules/dashboard/sagas/utils/safeHelpers';
import { debounce, isEmpty, isEqual, omit } from '~utils/lodash';
import { useHasPermission } from '~utils/hooks/useHasPermissions';
import { hasRoot } from '~modules/users/checks';
import { getAllUserRoles } from '~modules/transformers';
import { useTransformer } from '~utils/hooks';

import SafeTransactionPreview from './SafeTransactionPreview';
import {
Expand Down Expand Up @@ -170,14 +176,13 @@ const ControlSafeForm = ({
}: FormProps & FormikProps<FormValues>) => {
const [transactionTabStatus, setTransactionTabStatus] = useState([true]);
const [prevSafeAddress, setPrevSafeAddress] = useState<string>('');
const hasRoles = [
useHasPermission(colony, ColonyRole.Funding),
useHasPermission(colony, ColonyRole.Root),
].every((r) => r === true);
const { walletAddress } = useLoggedInUser();
const allUserRoles = useTransformer(getAllUserRoles, [colony, walletAddress]);
const canManageAndControlSafes = hasRoot(allUserRoles);

const [userHasPermission, onlyForceAction] = useDialogActionPermissions(
colony.colonyAddress,
hasRoles,
canManageAndControlSafes,
isVotingExtensionEnabled,
values.forceAction,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ColonyRole } from '@colony/colony-js';
import React from 'react';
import { defineMessages, FormattedMessage } from 'react-intl';

import { DialogProps, ActionDialogProps } from '~core/Dialog';
import IndexModal from '~core/IndexModal';
import { useLoggedInUser } from '~data/index';
import { getAllUserRoles } from '~modules/transformers';
import { userHasRole } from '~modules/users/checks';
import { hasRoot } from '~modules/users/checks';
import { useTransformer, WizardDialogType } from '~utils/hooks';

const MSG = defineMessages({
Expand Down Expand Up @@ -41,16 +40,12 @@ const MSG = defineMessages({
},
permissionText: {
id: 'dashboard.ManageSafeDialog.permissionsText',
defaultMessage: `You must have the {permissionsList} permissions in the
defaultMessage: `You must have the {permission} permission in the
relevant teams, in order to take this action`,
},
adminFundingPermissions: {
id: 'dashboard.ManageSafeDialog.adminFundingPermissions',
defaultMessage: 'administration and funding ',
},
rootFundingPermissions: {
id: 'dashboard.ManageSafeDialog.rootFundingPermissions',
defaultMessage: 'root and funding ',
manageSafePermission: {
id: 'dashboard.ManageSafeDialog.manageSafePermission',
defaultMessage: 'root',
},
});

Expand Down Expand Up @@ -79,15 +74,8 @@ const ManageSafeDialog = ({
const allUserRoles = useTransformer(getAllUserRoles, [colony, walletAddress]);

const hasRegisteredProfile = !!username && !ethereal;
const canAddRemoveSafes =
hasRegisteredProfile &&
userHasRole(allUserRoles, ColonyRole.Administration) &&
userHasRole(allUserRoles, ColonyRole.Funding);

const canControlSafes =
hasRegisteredProfile &&
userHasRole(allUserRoles, ColonyRole.Root) &&
userHasRole(allUserRoles, ColonyRole.Funding);
const canManageAndControlSafes =
hasRegisteredProfile && hasRoot(allUserRoles);

const items = [
{
Expand All @@ -96,10 +84,10 @@ const ManageSafeDialog = ({
icon: 'plus-heavy',
dataTest: 'addExistingSafeItem',
onClick: () => callStep(nextStepAddExistingSafe),
permissionRequired: !canAddRemoveSafes,
permissionRequired: !canManageAndControlSafes,
permissionInfoText: MSG.permissionText,
permissionInfoTextValues: {
permissionsList: <FormattedMessage {...MSG.adminFundingPermissions} />,
permission: <FormattedMessage {...MSG.manageSafePermission} />,
},
},
{
Expand All @@ -108,10 +96,10 @@ const ManageSafeDialog = ({
icon: 'trash-can',
dataTest: 'removeSafeItem',
onClick: () => callStep(nextStepRemoveSafe),
permissionRequired: !canAddRemoveSafes,
permissionRequired: !canManageAndControlSafes,
permissionInfoText: MSG.permissionText,
permissionInfoTextValues: {
permissionsList: <FormattedMessage {...MSG.adminFundingPermissions} />,
permission: <FormattedMessage {...MSG.manageSafePermission} />,
},
},
{
Expand All @@ -120,10 +108,10 @@ const ManageSafeDialog = ({
icon: 'joystick',
dataTest: 'controlSafeItem',
onClick: () => callStep(nextStepControlSafe),
permissionRequired: !canControlSafes,
permissionRequired: !canManageAndControlSafes,
permissionInfoText: MSG.permissionText,
permissionInfoTextValues: {
permissionsList: <FormattedMessage {...MSG.rootFundingPermissions} />,
permission: <FormattedMessage {...MSG.manageSafePermission} />,
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ActionDialogProps } from '~core/Dialog';
import { ColonySafe, useLoggedInUser } from '~data/index';
import { useTransformer } from '~utils/hooks';
import { getAllUserRoles } from '~modules/transformers';
import { canEnterRecoveryMode } from '~modules/users/checks';
import { hasRoot } from '~modules/users/checks';

import SafeListItem from './SafeListItem';
import { FormValues } from './RemoveSafeDialog';
Expand Down Expand Up @@ -47,8 +47,7 @@ const RemoveSafeDialogForm = ({
const { walletAddress, username, ethereal } = useLoggedInUser();
const allUserRoles = useTransformer(getAllUserRoles, [colony, walletAddress]);
const hasRegisteredProfile = !!username && !ethereal;
const userHasPermission =
hasRegisteredProfile && canEnterRecoveryMode(allUserRoles);
const userHasPermission = hasRegisteredProfile && hasRoot(allUserRoles);

return (
<>
Expand Down

0 comments on commit 31fb27a

Please sign in to comment.