Skip to content

Commit

Permalink
Site moderator promotions (#3190)
Browse files Browse the repository at this point in the history
* allow site moderators to promote other site moderators

* add todo

* allow modifying roles and scopes in one mutation

* Complete the existing site moderator role management

- Site moderators can promote new site moderators
- Org mods can promote/demote commenters, staff, site mods
- Admins can do anything they want

CORL-1364

* Make it so user's can't reassign their own roles

CORL-1364

* User GQLUSER_ROLE_RL generated types for roles

CORL-1364

* Clean up guard clauses and auth directives

CORL-1364

* Simplify viewer dependencies in UserRoleChange

CORL-1364

* fix: changes to promote/demote flow

* fix: revert changes to perm

* fix: revert changes to updateRole

* fix: revert changes to updateUserModerationScopes

Co-authored-by: nick-funk <[email protected]>
Co-authored-by: Wyatt Johnson <[email protected]>
Co-authored-by: Wyatt Johnson <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Oct 23, 2020
1 parent 75ff141 commit 81bb55f
Show file tree
Hide file tree
Showing 13 changed files with 768 additions and 31 deletions.
45 changes: 45 additions & 0 deletions src/core/client/admin/components/UserRole/DemoteUserMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { graphql } from "react-relay";
import { Environment } from "relay-runtime";

import {
commitMutationPromiseNormalized,
createMutation,
MutationInput,
} from "coral-framework/lib/relay";

import { DemoteUserMutation as MutationTypes } from "coral-admin/__generated__/DemoteUserMutation.graphql";

let clientMutationId = 0;

const DemoteUserMutation = createMutation(
"demoteUser",
(environment: Environment, input: MutationInput<MutationTypes>) =>
commitMutationPromiseNormalized<MutationTypes>(environment, {
mutation: graphql`
mutation DemoteUserMutation($input: DemoteUserInput!) {
demoteUser(input: $input) {
user {
id
role
moderationScopes {
scoped
sites {
id
name
}
}
}
clientMutationId
}
}
`,
variables: {
input: {
...input,
clientMutationId: (clientMutationId++).toString(),
},
},
})
);

export default DemoteUserMutation;
45 changes: 45 additions & 0 deletions src/core/client/admin/components/UserRole/PromoteUserMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { graphql } from "react-relay";
import { Environment } from "relay-runtime";

import {
commitMutationPromiseNormalized,
createMutation,
MutationInput,
} from "coral-framework/lib/relay";

import { PromoteUserMutation as MutationTypes } from "coral-admin/__generated__/PromoteUserMutation.graphql";

let clientMutationId = 0;

const PromoteUserMutation = createMutation(
"promoteUser",
(environment: Environment, input: MutationInput<MutationTypes>) =>
commitMutationPromiseNormalized<MutationTypes>(environment, {
mutation: graphql`
mutation PromoteUserMutation($input: PromoteUserInput!) {
promoteUser(input: $input) {
user {
id
role
moderationScopes {
scoped
sites {
id
name
}
}
}
clientMutationId
}
}
`,
variables: {
input: {
...input,
clientMutationId: (clientMutationId++).toString(),
},
},
})
);

export default PromoteUserMutation;
10 changes: 10 additions & 0 deletions src/core/client/admin/components/UserRole/SiteModeratorActions.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.button {
width: 100%;
justify-content: space-between;
padding: 0;
}

.modal {
max-width: 500px;
padding: var(--spacing-2) var(--spacing-3) var(--spacing-3) var(--spacing-3);
}
Loading

0 comments on commit 81bb55f

Please sign in to comment.