mirror of
https://github.com/wassname/talk.git
synced 2026-07-24 13:20:47 +08:00
Client Refactor
This commit is contained in:
@@ -2,7 +2,7 @@ import jwtDecode from 'jwt-decode';
|
||||
import bowser from 'bowser';
|
||||
import * as actions from '../constants/auth';
|
||||
import {notify} from 'coral-framework/actions/notification';
|
||||
|
||||
import {can} from 'coral-framework/services/perms';
|
||||
import t from 'coral-framework/services/i18n';
|
||||
|
||||
export const showSignInDialog = () => ({
|
||||
@@ -322,7 +322,7 @@ export const checkLogin = () => (dispatch, _, {rest, client, pym, storage}) => {
|
||||
pym.sendMessage('coral-auth-changed', JSON.stringify(result.user));
|
||||
|
||||
// Display create username dialog if necessary.
|
||||
if (result.user.canEditName && result.user.status !== 'BANNED') {
|
||||
if (can(result.user, 'EDIT_NAME') && result.user.status.banned.status) {
|
||||
dispatch(showCreateUsernameDialog());
|
||||
}
|
||||
})
|
||||
|
||||
@@ -217,8 +217,8 @@ class Stream extends React.Component {
|
||||
|
||||
const temporarilySuspended =
|
||||
user &&
|
||||
user.suspension.until &&
|
||||
new Date(user.suspension.until) > new Date();
|
||||
user.status.suspension.until &&
|
||||
new Date(user.status.suspension.until) > new Date();
|
||||
|
||||
const showCommentBox = loggedIn && ((!banned && !pending & !temporarilySuspended && !highlightedComment) || keepCommentBox);
|
||||
const slotProps = {data};
|
||||
@@ -257,12 +257,12 @@ class Stream extends React.Component {
|
||||
{t(
|
||||
'stream.temporarily_suspended',
|
||||
root.settings.organizationName,
|
||||
timeago(user.suspension.until)
|
||||
timeago(user.status.suspension.until)
|
||||
)}
|
||||
</RestrictedMessageBox>}
|
||||
{banned &&
|
||||
<SuspendedAccount
|
||||
canEditName={user && user.canEditName}
|
||||
canEditName={can(user, 'EDIT_NAME')}
|
||||
editName={editName}
|
||||
currentUsername={user.username}
|
||||
/>}
|
||||
|
||||
@@ -114,10 +114,18 @@ const USER_BANNED_SUBSCRIPTION = gql`
|
||||
subscription UserBanned($user_id: ID!) {
|
||||
userBanned(user_id: $user_id){
|
||||
id
|
||||
status
|
||||
canEditName
|
||||
suspension {
|
||||
until
|
||||
state {
|
||||
status {
|
||||
username {
|
||||
status
|
||||
}
|
||||
banned {
|
||||
status
|
||||
}
|
||||
suspension {
|
||||
until
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,10 +135,18 @@ const USER_SUSPENDED_SUBSCRIPTION = gql`
|
||||
subscription UserSuspended($user_id: ID!) {
|
||||
userSuspended(user_id: $user_id){
|
||||
id
|
||||
status
|
||||
canEditName
|
||||
suspension {
|
||||
until
|
||||
state {
|
||||
status {
|
||||
username {
|
||||
status
|
||||
}
|
||||
banned {
|
||||
status
|
||||
}
|
||||
suspension {
|
||||
until
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,10 +156,18 @@ const USERNAME_REJECTED_SUBSCRIPTION = gql`
|
||||
subscription UsernameRejected($user_id: ID!) {
|
||||
usernameRejected(user_id: $user_id){
|
||||
id
|
||||
status
|
||||
canEditName
|
||||
suspension {
|
||||
until
|
||||
state {
|
||||
status {
|
||||
username {
|
||||
status
|
||||
}
|
||||
banned {
|
||||
status
|
||||
}
|
||||
suspension {
|
||||
until
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,7 +189,19 @@ const EMBED_QUERY = gql`
|
||||
) {
|
||||
me {
|
||||
id
|
||||
status
|
||||
state {
|
||||
status {
|
||||
username {
|
||||
status
|
||||
}
|
||||
banned {
|
||||
status
|
||||
}
|
||||
suspension {
|
||||
until
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${getSlotFragmentSpreads(slots, 'root')}
|
||||
...${getDefinitionName(Stream.fragments.root)}
|
||||
|
||||
@@ -322,7 +322,19 @@ const fragments = {
|
||||
...${getDefinitionName(Comment.fragments.asset)}
|
||||
}
|
||||
me {
|
||||
status
|
||||
state {
|
||||
status {
|
||||
username {
|
||||
status
|
||||
}
|
||||
banned {
|
||||
status
|
||||
}
|
||||
suspension {
|
||||
until
|
||||
}
|
||||
}
|
||||
}
|
||||
ignoredUsers {
|
||||
id
|
||||
}
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
import intersection from 'lodash/intersection';
|
||||
|
||||
// =========================================================================
|
||||
// BASIC PERMISSIONS
|
||||
// =========================================================================
|
||||
|
||||
const basicPerms = {
|
||||
'INTERACT_WITH_COMMUNITY': (user) => {
|
||||
const banned = user.status.banned.status;
|
||||
const suspended = user.status.suspension.until && new Date(user.status.suspension.until) > new Date();
|
||||
|
||||
return !banned && !suspended;
|
||||
},
|
||||
'EDIT_NAME': (user) => {
|
||||
const usernameStatus = user.status.username.status;
|
||||
return usernameStatus === 'UNSET' || usernameStatus === 'REJECTED';
|
||||
}
|
||||
};
|
||||
|
||||
// =========================================================================
|
||||
// PERMISSIONS BY ROLE
|
||||
// =========================================================================
|
||||
|
||||
const basicRoles = {
|
||||
HAS_STAFF_TAG: ['ADMIN', 'MODERATOR', 'STAFF']
|
||||
};
|
||||
@@ -23,16 +44,18 @@ export const can = (user, ...perms) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
const banned = user.status === 'BANNED';
|
||||
const suspended = user.suspension.until && new Date(user.suspension.until) > new Date();
|
||||
|
||||
return perms.every((perm) => {
|
||||
if (perm === 'INTERACT_WITH_COMMUNITY') {
|
||||
return !banned && !suspended;
|
||||
|
||||
// Basic Permissions
|
||||
const permAction = basicPerms[perm];
|
||||
if (typeof permAction !== 'undefined') {
|
||||
return permAction(user);
|
||||
}
|
||||
|
||||
// Permissions by Role
|
||||
const role = roles[perm];
|
||||
if (typeof role === 'undefined') {
|
||||
throw new Error(`${perm} is not a valid role`);
|
||||
throw new Error(`${perm} is not a valid role or permission`);
|
||||
}
|
||||
|
||||
return intersection(role, user.roles).length > 0;
|
||||
|
||||
@@ -1460,18 +1460,7 @@ chai-nightwatch@~0.1.x:
|
||||
assertion-error "1.0.0"
|
||||
deep-eql "0.1.3"
|
||||
|
||||
chai@>1.9.0:
|
||||
version "4.1.2"
|
||||
resolved "https://registry.yarnpkg.com/chai/-/chai-4.1.2.tgz#0f64584ba642f0f2ace2806279f4f06ca23ad73c"
|
||||
dependencies:
|
||||
assertion-error "^1.0.1"
|
||||
check-error "^1.0.1"
|
||||
deep-eql "^3.0.0"
|
||||
get-func-name "^2.0.0"
|
||||
pathval "^1.0.0"
|
||||
type-detect "^4.0.0"
|
||||
|
||||
chai@^3.5.0:
|
||||
chai@>1.9.0, chai@^3.5.0:
|
||||
version "3.5.0"
|
||||
resolved "https://registry.yarnpkg.com/chai/-/chai-3.5.0.tgz#4d02637b067fe958bdbfdd3a40ec56fef7373247"
|
||||
dependencies:
|
||||
@@ -1483,7 +1472,7 @@ chain-function@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/chain-function/-/chain-function-1.0.0.tgz#0d4ab37e7e18ead0bdc47b920764118ce58733dc"
|
||||
|
||||
chalk@2.3.0, chalk@^2.1.0:
|
||||
chalk@2.3.0, chalk@^2.0.1:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba"
|
||||
dependencies:
|
||||
@@ -1501,7 +1490,7 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
|
||||
strip-ansi "^3.0.0"
|
||||
supports-color "^2.0.0"
|
||||
|
||||
chalk@^2.0.0, chalk@^2.0.1:
|
||||
chalk@^2.0.0, chalk@^2.1.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.2.0.tgz#477b3bf2f9b8fd5ca9e429747e37f724ee7af240"
|
||||
dependencies:
|
||||
@@ -1533,7 +1522,7 @@ chdir-promise@0.4.1:
|
||||
q "1.5.0"
|
||||
spots "0.5.0"
|
||||
|
||||
check-error@^1.0.1, check-error@^1.0.2:
|
||||
check-error@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
|
||||
|
||||
@@ -2280,12 +2269,6 @@ deep-eql@0.1.3, deep-eql@^0.1.3:
|
||||
dependencies:
|
||||
type-detect "0.1.1"
|
||||
|
||||
deep-eql@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
|
||||
dependencies:
|
||||
type-detect "^4.0.0"
|
||||
|
||||
deep-extend@~0.4.0:
|
||||
version "0.4.2"
|
||||
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.2.tgz#48b699c27e334bf89f10892be432f6e4c7d34a7f"
|
||||
@@ -3301,10 +3284,6 @@ get-caller-file@^1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5"
|
||||
|
||||
get-func-name@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
|
||||
|
||||
get-stream@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"
|
||||
@@ -6482,10 +6461,6 @@ path-type@^3.0.0:
|
||||
dependencies:
|
||||
pify "^3.0.0"
|
||||
|
||||
pathval@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0"
|
||||
|
||||
pause-stream@0.0.11:
|
||||
version "0.0.11"
|
||||
resolved "https://registry.yarnpkg.com/pause-stream/-/pause-stream-0.0.11.tgz#fe5a34b0cbce12b5aa6a2b403ee2e73b602f1445"
|
||||
@@ -7906,13 +7881,13 @@ right-pad@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.1.tgz#8ca08c2cbb5b55e74dafa96bf7fd1a27d568c8d0"
|
||||
|
||||
rimraf@2, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.6.1:
|
||||
rimraf@2, rimraf@^2.5.1, rimraf@^2.6.1:
|
||||
version "2.6.2"
|
||||
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
|
||||
dependencies:
|
||||
glob "^7.0.5"
|
||||
|
||||
rimraf@~2.5.2:
|
||||
rimraf@^2.2.8, rimraf@~2.5.2:
|
||||
version "2.5.4"
|
||||
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04"
|
||||
dependencies:
|
||||
|
||||
Reference in New Issue
Block a user