fix: prompt user on actions with no permission

This commit is contained in:
liyasthomas
2021-11-01 17:51:01 +05:30
parent 6314740f46
commit 94763dcb31
4 changed files with 86 additions and 70 deletions

View File

@@ -2,11 +2,20 @@
<div class="border border-divider rounded flex flex-col flex-1"> <div class="border border-divider rounded flex flex-col flex-1">
<div <div
class="flex flex-1 items-start" class="flex flex-1 items-start"
:class="{ :class="
'cursor-pointer hover:bg-primaryDark transition hover:border-dividerDark focus-visible:border-dividerDark': compact
compact && team.myRole === 'OWNER', ? team.myRole === 'OWNER'
}" ? 'cursor-pointer hover:bg-primaryDark transition hover:border-dividerDark focus-visible:border-dividerDark'
@click="compact && team.myRole === 'OWNER' ? $emit('invite-team') : ''" : 'cursor-not-allowed bg-primaryLight'
: ''
"
@click="
compact
? team.myRole === 'OWNER'
? $emit('invite-team')
: noPermission()
: ''
"
> >
<div class="p-4"> <div class="p-4">
<label <label
@@ -182,4 +191,10 @@ const exitTeam = () => {
) )
)() // Tasks (and TEs) are lazy, so call the function returned )() // Tasks (and TEs) are lazy, so call the function returned
} }
const noPermission = () => {
$toast.error(t("profile.no_permission").toString(), {
icon: "error_outline",
})
}
</script> </script>

View File

@@ -69,61 +69,63 @@ authIdToken$.subscribe(() => {
subscriptionClient.client.close() subscriptionClient.client.close()
}) })
const createHoppClient = () => createClient({ const createHoppClient = () =>
url: BACKEND_GQL_URL, createClient({
exchanges: [ url: BACKEND_GQL_URL,
devtoolsExchange, exchanges: [
dedupExchange, devtoolsExchange,
offlineExchange({ dedupExchange,
schema: schema as any, offlineExchange({
keys: keyDefs, schema: schema as any,
optimistic: optimisticDefs, keys: keyDefs,
updates: updatesDef, optimistic: optimisticDefs,
resolvers: resolversDef, updates: updatesDef,
storage, resolvers: resolversDef,
}), storage,
authExchange({ }),
addAuthToOperation({ authState, operation }) { authExchange({
if (!authState || !authState.authToken) { addAuthToOperation({ authState, operation }) {
return operation if (!authState || !authState.authToken) {
} return operation
}
const fetchOptions = const fetchOptions =
typeof operation.context.fetchOptions === "function" typeof operation.context.fetchOptions === "function"
? operation.context.fetchOptions() ? operation.context.fetchOptions()
: operation.context.fetchOptions || {} : operation.context.fetchOptions || {}
return makeOperation(operation.kind, operation, { return makeOperation(operation.kind, operation, {
...operation.context, ...operation.context,
fetchOptions: { fetchOptions: {
...fetchOptions, ...fetchOptions,
headers: { headers: {
...fetchOptions.headers, ...fetchOptions.headers,
Authorization: `Bearer ${authState.authToken}`, Authorization: `Bearer ${authState.authToken}`,
},
}, },
}, })
}) },
}, willAuthError({ authState }) {
willAuthError({ authState }) { return !authState || !authState.authToken
return !authState || !authState.authToken },
}, getAuth: async () => {
getAuth: async () => { if (!probableUser$.value) return { authToken: null }
if (!probableUser$.value) return { authToken: null }
await waitProbableLoginToConfirm() await waitProbableLoginToConfirm()
return { return {
authToken: getAuthIDToken(), authToken: getAuthIDToken(),
} }
}, },
}), }),
fetchExchange, fetchExchange,
subscriptionExchange({ subscriptionExchange({
// @ts-expect-error: An issue with the Urql typing // @ts-expect-error: An issue with the Urql typing
forwardSubscription: (operation) => subscriptionClient.request(operation), forwardSubscription: (operation) =>
}), subscriptionClient.request(operation),
], }),
}) ],
})
export const client = ref(createHoppClient()) export const client = ref(createHoppClient())
@@ -312,8 +314,7 @@ export const runMutation = <
pipe( pipe(
TE.tryCatch( TE.tryCatch(
() => () =>
client client.value
.value
.mutation(mutation, variables, { .mutation(mutation, variables, {
requestPolicy: "cache-and-network", requestPolicy: "cache-and-network",
...additionalConfig, ...additionalConfig,

View File

@@ -108,19 +108,18 @@ export const updatesDef: GraphCacheUpdaters = {
}, },
removeTeamMember: (_result, { teamID, userUid }, cache) => { removeTeamMember: (_result, { teamID, userUid }, cache) => {
const newMembers = ( const newMembers = (
cache.resolve( (cache.resolve(
{ {
__typename: "Team", __typename: "Team",
id: teamID, id: teamID,
}, },
"teamMembers" "teamMembers"
) as string[] ) as string[]) ?? []
) )
.map((x) => [x, cache.resolve(x, "user") as string]) .map((x) => [x, cache.resolve(x, "user") as string])
.map(([key, userKey]) => [key, cache.resolve(userKey, "uid") as string]) .map(([key, userKey]) => [key, cache.resolve(userKey, "uid") as string])
.filter(([_key, uid]) => uid !== userUid) .filter(([_key, uid]) => uid !== userUid)
.map(([key]) => key) .map(([key]) => key)
cache.link({ __typename: "Team", id: teamID }, "teamMembers", newMembers) cache.link({ __typename: "Team", id: teamID }, "teamMembers", newMembers)
}, },
createTeamInvitation: (result, _args, cache, _info) => { createTeamInvitation: (result, _args, cache, _info) => {

View File

@@ -261,6 +261,17 @@
"script": "Pre-Request Script", "script": "Pre-Request Script",
"snippets": "Snippets" "snippets": "Snippets"
}, },
"profile": {
"editor": "Editor",
"editor_description": "Editors can add, edit, and delete requests.",
"no_permission": "You do not have permission to perform this action.",
"owner": "Owner",
"owner_description": "Owners can add, edit, and delete requests, collections and team members.",
"roles": "Roles",
"roles_description": "Roles are used to control access to the shared collections.",
"viewer": "Viewer",
"viewer_description": "Viewers can only view and use requests."
},
"remove": { "remove": {
"star": "Remove star" "star": "Remove star"
}, },
@@ -310,16 +321,6 @@
"waiting_for_connection": "waiting for connection", "waiting_for_connection": "waiting for connection",
"xml": "XML" "xml": "XML"
}, },
"profile": {
"roles": "Roles",
"roles_description": "Roles are used to control access to the shared collections.",
"owner": "Owner",
"owner_description": "Owners can add, edit, and delete requests, collections and team members.",
"editor": "Editor",
"editor_description": "Editors can add, edit, and delete requests.",
"viewer": "Viewer",
"viewer_description": "Viewers can only view and use requests."
},
"settings": { "settings": {
"accent_color": "Accent color", "accent_color": "Accent color",
"account": "Account", "account": "Account",