Commit 1725570f authored by Shubham Tiwari's avatar Shubham Tiwari
Browse files

refactor(ui): add permission for dashboard

parent 81ef58b8
Pipeline #33765 passed with stage
......@@ -10,6 +10,7 @@ import {
Icon,
} from '../../../components'
import ConstantsContext from '../../../../app/constantsContext'
import PermissionsGate from '../../../common/PermissionsGate'
const SuccessText = styled.div`
align-content: center;
......@@ -93,15 +94,17 @@ export default ({
return (
<>
<Dropdown
dataTestId="bulk-update-accept"
direction="up"
disabled={selectedRows.length > 0 ? disabled : true}
itemsList={options}
primary
>
{s('pages.button.acceptUser')}
</Dropdown>
<PermissionsGate scopes={['accept-reject-user']}>
<Dropdown
dataTestId="bulk-update-accept"
direction="up"
disabled={selectedRows.length > 0 ? disabled : true}
itemsList={options}
primary
>
{s('pages.button.acceptUser')}
</Dropdown>
</PermissionsGate>
{!!selectedRows.length && (
<UpdateConfirmation
......
......@@ -7,6 +7,7 @@ import {
UpdateConfirmation,
Dropdown as uiDropdown,
} from '../../../components'
import PermissionsGate from '../../../common/PermissionsGate'
const Dropdown = styled(uiDropdown)`
background: white;
......@@ -84,15 +85,17 @@ export default ({
return (
<>
<Dropdown
dataTestId="bulk-update-teams"
direction="up"
disabled={selectedRows.length > 0 ? disabled : true}
itemsList={options}
primary
>
Assign Roles
</Dropdown>
<PermissionsGate scopes={['accept-reject-user']}>
<Dropdown
dataTestId="bulk-update-teams"
direction="up"
disabled={selectedRows.length > 0 ? disabled : true}
itemsList={options}
primary
>
Assign Roles
</Dropdown>
</PermissionsGate>
{!!selectedRows.length && (
<UpdateConfirmation
......
......@@ -12,6 +12,7 @@ import {
TextFieldComponent as UITextField,
ToggleComponent as UIToggle,
} from '../../../components/FormElements/FormikElements'
import PermissionsGate from '../../../common/PermissionsGate'
// #region styled
const Wrapper = styled.div`
......@@ -142,23 +143,24 @@ const Basic = props => {
)} */}
<ToggleGroup>
<div htmlFor="team">Organization Roles</div>
<PermissionsGate scopes={['edit-role-orgAdmin']}>
<div htmlFor="team">Organization Roles</div>
<div>
<Toggle
disabled={readOnly}
field={{ name: 'orgAdmin', value: values.orgAdmin }}
form={formProps}
label="Org admin"
/>
<Toggle
disabled={readOnly}
field={{ name: 'editor', value: values.editor }}
form={formProps}
label="Editor"
/>
</div>
<div>
<Toggle
disabled={readOnly}
field={{ name: 'orgAdmin', value: values.orgAdmin }}
form={formProps}
label="Org admin"
/>
<Toggle
disabled={readOnly}
field={{ name: 'editor', value: values.editor }}
form={formProps}
label="Editor"
/>
</div>
</PermissionsGate>
</ToggleGroup>
{isVerified && (
......
......@@ -18,6 +18,7 @@ import {
SelectList,
Icon,
} from '../../../components'
import PermissionsGate from '../../../common/PermissionsGate'
const Organization = styled.div`
border-left: 3px solid transparent;
......@@ -269,52 +270,54 @@ const Basic = ({
<ColumnWrapper>
<Column>
<RolesHeader>BCMS role</RolesHeader>
<PermissionsGate scopes={['edit-role-sysadmin']}>
<Checkbox
checked={values.admin}
label={s('form.sysAdmin')}
name="admin"
onChange={element => {
const newAdminValue = !values.admin
<Checkbox
checked={values.admin}
label={s('form.sysAdmin')}
name="admin"
onChange={element => {
const newAdminValue = !values.admin
if (newAdminValue === true)
setFieldValue('pdf2xmlVendor', false)
if (newAdminValue === true)
setFieldValue('pdf2xmlVendor', false)
setFieldValue('admin', newAdminValue)
setFieldValue('admin', newAdminValue)
if (!newAdminValue) removeAdminRoleInOrganizations()
}}
/>
<Checkbox
checked={values.pdf2xmlVendor}
label={s('form.pdf2xmlVendor')}
name="pdf2xmlVendor"
onChange={() => {
const newVendorValue = !values.pdf2xmlVendor
if (newVendorValue === true) {
setFieldValue('admin', false)
removeAdminRoleInOrganizations()
}
setFieldValue('pdf2xmlVendor', newVendorValue)
if (!newAdminValue) removeAdminRoleInOrganizations()
}}
/>
</PermissionsGate>
<PermissionsGate scopes={['edit-role-sysadmin']}>
<Checkbox
checked={values.pdf2xmlVendor}
label={s('form.pdf2xmlVendor')}
name="pdf2xmlVendor"
onChange={() => {
const newVendorValue = !values.pdf2xmlVendor
if (newVendorValue === true) {
setFieldValue('admin', false)
removeAdminRoleInOrganizations()
}
setFieldValue('pdf2xmlVendor', newVendorValue)
const teams = []
const teams = []
values.teams.forEach(team => {
const tmCloned = cloneDeep(team)
values.teams.forEach(team => {
const tmCloned = cloneDeep(team)
tmCloned.members = tmCloned.members.filter(
mb => mb.user.id !== values.id,
)
tmCloned.members = tmCloned.members.filter(
mb => mb.user.id !== values.id,
)
teams.push(tmCloned)
})
teams.push(tmCloned)
})
setFieldValue('teams', teams)
}}
/>
setFieldValue('teams', teams)
}}
/>
</PermissionsGate>
</Column>
<Column grow={0}>
......
......@@ -14,6 +14,7 @@ import {
import { getDisplayName } from '../../../common/utils'
import { UserForm } from '../Form'
import ConstantsContext from '../../../../app/constantsContext'
import PermissionsGate from '../../../common/PermissionsGate'
const Modal = styled(UIModal)`
max-height: 770px;
......@@ -100,14 +101,16 @@ export default props => {
{!isVerified && (
<>
<Button
data-test-id="accept-user-modal"
icon="check"
onClick={handleAccept}
status="primary"
>
Accept user
</Button>
<PermissionsGate scopes={['accept-reject-user']}>
<Button
data-test-id="accept-user-modal"
icon="check"
onClick={handleAccept}
status="primary"
>
Accept user
</Button>
</PermissionsGate>
<Button
data-test-id="reject-user-modal"
......
......@@ -129,19 +129,21 @@ const Organization = props => {
key: 'bookSettingsTemplates',
label: 'Book Templates',
content: (
<BookSettingsTemplateChooser
chapterProcessedTemplate={templates?.chapterProcessed}
chosenTemplate={chosenBookSettingsTemplate}
createTemplate={createTemplate}
isEditor={isEditor}
isOrgAdmin={isOrgAdmin}
isSaving={isSavingBookSettings}
isSysAdmin={isSysAdmin}
loading={loadingTemplates}
onChooseTemplate={handleChooseBookSettingsTemplate}
updateTemplate={updateTemplate}
wholeBookTemplate={templates?.wholeBook}
/>
<PermissionsGate scopes={['view-book-template']}>
<BookSettingsTemplateChooser
chapterProcessedTemplate={templates?.chapterProcessed}
chosenTemplate={chosenBookSettingsTemplate}
createTemplate={createTemplate}
isEditor={isEditor}
isOrgAdmin={isOrgAdmin}
isSaving={isSavingBookSettings}
isSysAdmin={isSysAdmin}
loading={loadingTemplates}
onChooseTemplate={handleChooseBookSettingsTemplate}
updateTemplate={updateTemplate}
wholeBookTemplate={templates?.wholeBook}
/>
</PermissionsGate>
),
}
......
......@@ -4,6 +4,7 @@ import { Redirect } from 'react-router-dom'
import { BooksCollectionsPage, OrganisationsList, AllUsersTab } from './Tabs'
import { Tabs } from '../../components'
import CurrentUserContext from '../../../app/userContext'
import PermissionsGate from '../../common/PermissionsGate'
const Root = styled.div`
display: flex;
......@@ -46,7 +47,11 @@ const SysAdminPage = props => {
{
key: '#users',
label: 'Users',
content: <AllUsersTab props={props} />,
content: (
<PermissionsGate scopes={['view-user-tab']}>
<AllUsersTab props={props} />
</PermissionsGate>
),
},
// {
// key: '#error_managment',
......
......@@ -15,6 +15,7 @@ import { TableWithToolbar } from '../../../components'
import ConstantsContext from '../../../../app/constantsContext'
import InviteUser from '../Modals/InviteUser'
import { getDisplayName } from '../../../common/utils'
import PermissionsGate from '../../../common/PermissionsGate'
// #region styled
const Root = styled.div`
......@@ -201,7 +202,9 @@ const UsersTab = props => {
return (
<Root>
<Top>
<InviteUser key={1} organization={organizationId} />
<PermissionsGate scopes={['invite-orgAdmin']}>
<InviteUser key={1} organization={organizationId} />
</PermissionsGate>
<TextField
data-test-id="search"
......
......@@ -25,6 +25,7 @@ export const SCOPES = {
// Dashboard
canViewDashboard: 'view-dashboard',
canViewOrganizationTab: 'view-organization-tab',
canViewOrganizationAccessTab: 'view-organization-access-tab',
canViewMetadataContentTab: 'view-metadata-content-tab',
canEditOrganizationSettings: 'edit-organization',
canViewOrganizationsTab: 'view-organizations-tab',
......@@ -32,7 +33,7 @@ export const SCOPES = {
canCreateOrganization: 'create-organization',
canCreateCollection: 'create-collection',
canViewUserTab: 'view-user-tab',
canAcceptRejectUser: 'accept-reject-user',
// canAcceptRejectUser: 'accept-reject-user',
canGiveRoleSysAdmin: 'edit-role-sysadmin',
canGiveRolePDF2XML: 'edit-role-PDF2XML',
canGiveRoleOrgAdmin: 'edit-role-orgAdmin',
......@@ -41,6 +42,7 @@ export const SCOPES = {
canGiveRolePreviewer: 'edit-role-previewer',
canInviteOrgAdmin: 'invite-orgAdmin',
canApproveUser: 'approve-user',
canViewBookTemplate: 'view-book-template',
canCreateBook: 'create-book',
canPublishBook: 'publish-book',
......@@ -150,6 +152,7 @@ export const PERMISSIONS = {
SCOPES.canGiveRoleAuthor,
SCOPES.canGiveRolePreviewer,
SCOPES.canInviteOrgAdmin,
SCOPES.canViewOrganizationAccessTab,
SCOPES.canViewOrganizationTab, // if member of more than one
// Collection Manager
......@@ -254,6 +257,7 @@ export const PERMISSIONS = {
SCOPES.canEditBookTeam,
SCOPES.canViewAllVersions,
SCOPES.canViewUserTab,
SCOPES.canViewOrganizationAccessTab,
// Book Component
SCOPES.canViewBookComponent,
SCOPES.canEditBookComponent,
......@@ -365,6 +369,7 @@ export const PERMISSIONS = {
[ROLES.authorForOrganisation]: [
// Dashboard
SCOPES.canDownloadBook, // if member of book team
SCOPES.canViewOrganizationAccessTab,
SCOPES.canViewOrganizationsTab, // if member of more than one
......@@ -428,7 +433,7 @@ export const PERMISSIONS = {
[ROLES.previewerForOrganisation]: [
// Dashboard
SCOPES.canViewOrganizationAccessTab,
SCOPES.canViewOrganizationsTab, // if member of more than one
// Book Component
......@@ -489,6 +494,7 @@ export const PERMISSIONS = {
[ROLES.PDF2XMLVendor]: [
// Dashboard
SCOPES.canDownloadBook,
SCOPES.canViewOrganizationTab,
// SCOPES.canViewOrganizationsTab,
// Book Manager
......@@ -530,4 +536,15 @@ export const PERMISSIONS = {
SCOPES.canCloseIssue,
SCOPES.canCommentOnIssue,
],
[ROLES.sysAdmin]: [
// Dashboard
SCOPES.canViewBookTemplate,
SCOPES.canGiveRoleSysAdmin,
SCOPES.canGiveRolePDF2XML,
SCOPES.canGiveRoleOrgAdmin,
SCOPES.canGiveRoleEditor,
SCOPES.canInviteOrgAdmin,
SCOPES.canAcceptRejectUser,
],
}
......@@ -15,6 +15,7 @@ import {
import DisplayInlineEditor from './wax/DisplayInlneEditor'
import Logo from '../../public/bcms-logo.png'
import PermissionsGate from '../common/PermissionsGate'
// #region styled
const Root = styled.nav`
......@@ -129,9 +130,11 @@ const AppBar = ({
<Side>
{canViewOrganizationAccess && (
<Button onClick={onClickOrganizationAccess} outlined>
Organization Access
</Button>
<PermissionsGate scopes={['view-organization-access-tab']}>
<Button onClick={onClickOrganizationAccess} outlined>
Organization Access
</Button>
</PermissionsGate>
)}
{userExists && (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment