Add userFlagged subscription

This commit is contained in:
Chi Vinh Le
2018-01-16 11:31:44 +01:00
parent 7885b025ee
commit 6aece16fd0
6 changed files with 35 additions and 4 deletions
+14 -4
View File
@@ -73,10 +73,20 @@ const createAction = async (
metadata,
});
if (action_type === 'FLAG' && item_type === 'COMMENTS') {
// The item is a comment, and this is a flag. Push that the comment was
// flagged, don't wait for it to finish.
pubsub.publish('commentFlagged', item);
if (action_type === 'FLAG') {
switch (item_type) {
case 'COMMENTS':
// The item is a comment, and this is a flag. Push that the comment was
// flagged, don't wait for it to finish.
pubsub.publish('commentFlagged', item);
break;
case 'USERS':
// The item is a user, and this is a flag. Push that the user was
// flagged, don't wait for it to finish.
pubsub.publish('userFlagged', item);
break;
default:
}
}
return action;
+3
View File
@@ -26,6 +26,9 @@ const Subscription = {
usernameRejected(user) {
return user;
},
usernameFlagged(user) {
return user;
},
};
module.exports = Subscription;
+11
View File
@@ -9,6 +9,7 @@ const {
SUBSCRIBE_ALL_USER_BANNED,
SUBSCRIBE_ALL_USERNAME_REJECTED,
SUBSCRIBE_ALL_USERNAME_APPROVED,
SUBSCRIBE_ALL_USERNAME_FLAGGED,
} = require('../perms/constants');
const merge = require('lodash/merge');
@@ -97,6 +98,16 @@ const setupFunctions = {
}
return !args.user_id || user.id === args.user_id;
},
usernameFlagged: (options, args, user, context) => {
if (
!context.user ||
(args.user_id !== user.id &&
!context.user.can(SUBSCRIBE_ALL_USERNAME_FLAGGED))
) {
return false;
}
return !args.user_id || user.id === args.user_id;
},
usernameRejected: (options, args, user, context) => {
if (
!context.user ||
+5
View File
@@ -1506,6 +1506,11 @@ type Subscription {
# users with the `ADMIN` or `MODERATOR` role.
userBanned(user_id: ID): User
# Get an update whenever a username was flagged.
# `user_id` must match id of current user except for
# users with the `ADMIN` or `MODERATOR` role.
usernameFlagged(user_id: ID): User
# Get an update whenever a username has been rejected.
# `user_id` must match id of current user except for
# users with the `ADMIN` or `MODERATOR` role.
+1
View File
@@ -9,4 +9,5 @@ module.exports = {
SUBSCRIBE_ALL_USER_BANNED: 'SUBSCRIBE_ALL_USER_BANNED',
SUBSCRIBE_ALL_USERNAME_REJECTED: 'SUBSCRIBE_ALL_USERNAME_REJECTED',
SUBSCRIBE_ALL_USERNAME_APPROVED: 'SUBSCRIBE_ALL_USERNAME_APPROVED',
SUBSCRIBE_ALL_USERNAME_FLAGGED: 'SUBSCRIBE_ALL_USERNAME_FLAGGED',
};
+1
View File
@@ -13,6 +13,7 @@ module.exports = (user, perm) => {
case types.SUBSCRIBE_ALL_USER_BANNED:
case types.SUBSCRIBE_ALL_USERNAME_REJECTED:
case types.SUBSCRIBE_ALL_USERNAME_APPROVED:
case types.SUBSCRIBE_ALL_USERNAME_FLAGGED:
return check(user, ['ADMIN', 'MODERATOR']);
default:
break;