From 13865ff29e11aa50e38e71b6ec65f4585b94f981 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 27 Nov 2017 11:51:39 -0700 Subject: [PATCH] roles -> role, null -> COMMENTER for user roles --- bin/cli-users | 18 ++---- .../src/components/CommentLabels.js | 2 +- .../src/containers/CommentLabels.js | 2 +- .../src/routes/Community/components/Table.js | 2 +- .../Community/containers/FlaggedUser.js | 2 +- client/coral-framework/services/perms.js | 3 +- graph/mutators/user.js | 14 ++--- graph/resolvers/root_mutation.js | 7 +-- graph/resolvers/user.js | 4 +- graph/typeDefs.graphql | 12 ++-- middleware/authorization.js | 4 +- migrations/1511801783_user_roles.js | 56 +++++++++++++++++++ models/enum/user_roles.js | 3 +- models/user.js | 13 ++--- package.json | 2 +- perms/utils.js | 5 +- .../client/components/ApproveCommentAction.js | 2 +- services/tags.js | 2 +- services/users.js | 21 +------ test/server/graph/context.js | 2 +- test/server/graph/loaders/metrics.js | 4 +- test/server/graph/mutations/addTag.js | 4 +- test/server/graph/mutations/changeUsername.js | 19 ++++--- test/server/graph/mutations/createComment.js | 13 ++--- test/server/graph/mutations/removeTag.js | 4 +- .../graph/mutations/setUserBanStatus.js | 23 ++++---- .../mutations/setUserSuspensionStatus.js | 23 ++++---- .../graph/mutations/setUserUsernameStatus.js | 23 ++++---- .../graph/mutations/updateAssetSettings.js | 13 +++-- .../graph/mutations/updateAssetStatus.js | 12 ++-- test/server/graph/mutations/updateSettings.js | 19 +++---- test/server/graph/queries/settings.js | 18 ++---- test/server/graph/queries/user.js | 14 ++--- test/server/middleware/authorization.js | 12 ++-- test/server/routes/api/assets/index.js | 14 ++--- test/server/routes/api/settings/index.js | 8 +-- test/server/routes/api/user/index.js | 4 +- test/server/services/users.js | 2 +- 38 files changed, 206 insertions(+), 199 deletions(-) create mode 100644 migrations/1511801783_user_roles.js diff --git a/bin/cli-users b/bin/cli-users index 248bea523..35ae78ba5 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -34,11 +34,11 @@ function getUserCreateAnswers(options) { password: options.password, confirmPassword: options.password, username: options.name, - roles: [] + role: 'COMMENTER' }; if (options.role && USER_ROLES.indexOf(options.role) > -1) { - user.roles = [options.role]; + user.roles = options.role; } return Promise.resolve(user); @@ -87,9 +87,9 @@ function getUserCreateAnswers(options) { } }, { - name: 'roles', + name: 'role', message: 'User Role', - type: 'checkbox', + type: 'list', choices: USER_ROLES } ]); @@ -106,13 +106,7 @@ async function createUser(options) { } const user = await UsersService.createLocalUser(answers.email.trim(), answers.password.trim(), answers.username.trim()); - - if (answers.roles.length > 0) { - for (const role of answers.roles) { - await UsersService.addRoleToUser(user.id, role); - } - } - + await UsersService.setRole(user.id, answers.role); await UsersService.sendEmailConfirmation(user, answers.email.trim()); console.log(`Created User ${user.id}.`); @@ -250,7 +244,7 @@ function listUsers() { user.id, user.username, user.profiles.map((p) => p.provider).join(', '), - user.roles.join(', '), + user.role, user.status, state ]); diff --git a/client/coral-admin/src/components/CommentLabels.js b/client/coral-admin/src/components/CommentLabels.js index bff4f575a..a40777c40 100644 --- a/client/coral-admin/src/components/CommentLabels.js +++ b/client/coral-admin/src/components/CommentLabels.js @@ -17,7 +17,7 @@ function getUserFlaggedType(actions) { .some((action) => action.__typename === 'FlagAction' && action.user && - action.user.roles.some((role) => staffRoles.includes(role)) + staffRoles.includes(action.user.role) ) ? 'Staff' : 'User'; } diff --git a/client/coral-admin/src/containers/CommentLabels.js b/client/coral-admin/src/containers/CommentLabels.js index 1d57aa526..abc7d0bed 100644 --- a/client/coral-admin/src/containers/CommentLabels.js +++ b/client/coral-admin/src/containers/CommentLabels.js @@ -25,7 +25,7 @@ export default withFragments({ } user { id - roles + role } } ${getSlotFragmentSpreads(slots, 'comment')} diff --git a/client/coral-admin/src/routes/Community/components/Table.js b/client/coral-admin/src/routes/Community/components/Table.js index 97b1db996..ac9d43a0e 100644 --- a/client/coral-admin/src/routes/Community/components/Table.js +++ b/client/coral-admin/src/routes/Community/components/Table.js @@ -66,7 +66,7 @@ const Table = ({users, setRole, onHeaderClickHandler, setUserBanStatus, viewUser setRole(row.id, role)}>