Skip to content

Commit

Permalink
refs #317: hide review buttons when user is not an editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Nov 16, 2016
1 parent 3aac2b5 commit a8176d3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
23 changes: 21 additions & 2 deletions src/plugins/signoff/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ import AdminLink from "../../components/AdminLink";
import { ProgressBar, ProgressStep } from "./ProgressBar.js";


function isEditor(sessionState, bucketState) {
if (typeof sessionState.serverInfo.user !== "object") {
return false;
}
const {serverInfo: {user, capabilities}} = sessionState;
if (user == null) {
return false;
}
const {signer={}} = capabilities;
const {editors_group: groupName} = signer;
const {id: userId} = user;
const {groups} = bucketState;
const editorGroup = groups.find(g => g.id === groupName);
if (!editorGroup) {
return false;
}
return editorGroup.members.includes(userId);
}

export default class SignoffToolBar extends React.Component {
props: {
sessionState: SessionState,
Expand Down Expand Up @@ -67,13 +86,13 @@ export default class SignoffToolBar extends React.Component {
<WorkInProgress label="Work in progress"
step={0}
currentStep={step}
canEdit={canEdit}
canEdit={canEdit && isEditor(sessionState, bucketState)}
requestReview={requestReview}
source={source} />
<Review label="Waiting review"
step={1}
currentStep={step}
canEdit={canEdit}
canEdit={canEdit && isEditor(sessionState, bucketState)}
approveChanges={approveChanges}
declineChanges={declineChanges}
source={source}
Expand Down
1 change: 0 additions & 1 deletion src/reducers/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const DEFAULT: SessionState = {
buckets: [],
serverInfo: {
capabilities: {},
user: {},
},
redirectURL: null,
};
Expand Down
3 changes: 2 additions & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export type Capabilities = {
history?: Object,
permissions_endpoint?: Object,
schema?: Object,
signer?: Object,
};

export type ClientError = {
Expand Down Expand Up @@ -253,7 +254,7 @@ export type SessionState = {
export type ServerInfo = {
capabilities: Capabilities,
user?: {
id?: string,
id: string,
bucket?: string,
}
};
Expand Down
1 change: 0 additions & 1 deletion test/reducers/sessions_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ describe("session reducer", () => {
redirectURL: null,
serverInfo: {
capabilities: {},
user: {},
},
});
});
Expand Down

0 comments on commit a8176d3

Please sign in to comment.