Skip to content

Commit

Permalink
fix: Adjust permissions logic for view / manage groups (#3679)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Apr 8, 2024
1 parent 2df29c4 commit 5ba3083
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 107 deletions.
2 changes: 1 addition & 1 deletion frontend/common/stores/account-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const controller = {

store.saved()
if (isLoginPage) {
window.location.href = `/projects`
window.location.href = `/organisation-settings`
}
})
.catch((e) => {
Expand Down
21 changes: 17 additions & 4 deletions frontend/web/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import Icon from './Icon'
import AccountStore from 'common/stores/account-store'
import InfoMessage from './InfoMessage'
import OrganisationLimit from './OrganisationLimit'
import OrganisationLink from './OrganisationLink'
import GithubStar from './GithubStar'
import Tooltip from './Tooltip'

Expand Down Expand Up @@ -168,7 +167,7 @@ const App = class extends Component {
id: lastEnv.orgId,
})
if (!lastOrg) {
this.context.router.history.replace('/projects')
this.context.router.history.replace('/organisation-settings')
return
}

Expand All @@ -184,7 +183,7 @@ const App = class extends Component {
return
}

this.context.router.history.replace('/projects')
this.context.router.history.replace('/organisation-settings')
})
}
}
Expand Down Expand Up @@ -349,7 +348,21 @@ const App = class extends Component {
<React.Fragment>
<nav className='my-3 my-md-0 hidden-xs-down flex-row navbar-right space'>
<Row>
<OrganisationLink />
<NavLink
id='org-settings-link'
activeClassName='active'
className='nav-link'
to='/organisation-settings'
>
<span className='mr-1'>
<Icon
name='layout'
width={20}
fill='#9DA4AE'
/>
</span>
{'Organisation'}
</NavLink>
</Row>
<Row>
<NavLink
Expand Down
44 changes: 0 additions & 44 deletions frontend/web/components/OrganisationLink.tsx

This file was deleted.

13 changes: 8 additions & 5 deletions frontend/web/components/UserGroupList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ const CreateGroup = require('./modals/CreateGroup')
import Button from './base/forms/Button'
import AccountStore from 'common/stores/account-store'
import { UserGroup, GroupPermission } from 'common/types/responses'
import { useDeleteGroupMutation } from 'common/services/useGroup'
import {
useDeleteGroupMutation,
useGetGroupsQuery,
} from 'common/services/useGroup'
import { useGetUserGroupPermissionQuery } from 'common/services/useUserGroupPermission'
import PanelSearch from './PanelSearch'
import { sortBy } from 'lodash'
import InfoMessage from './InfoMessage' // we need this to make JSX compile
import Icon from './Icon'
import { useGetGroupSummariesQuery } from 'common/services/useGroupSummary'
import Panel from './base/grid/Panel'
import PermissionsSummaryList from './PermissionsSummaryList'

Expand Down Expand Up @@ -135,8 +137,9 @@ const UserGroupsList: FC<UserGroupsListType> = ({
showRemove,
}) => {
const [page, setPage] = useState(1)
const { data: userGroups, isLoading } = useGetGroupSummariesQuery({
const { data: userGroups, isLoading } = useGetGroupsQuery({
orgId: `${orgId}`,
page,
})
const { data: userGroupsPermission, isLoading: userGroupPermissionLoading } =
useGetUserGroupPermissionQuery(
Expand All @@ -153,7 +156,7 @@ const UserGroupsList: FC<UserGroupsListType> = ({
: []

if (userGroupsPermission?.length > 0) {
userGroups?.forEach((group) => {
userGroups?.results.forEach((group) => {
const existingPermissionIndex =
mergeduserGroupsPermissionWithUserGroups.findIndex(
(userGroupPermission) => userGroupPermission.group.id === group.id,
Expand Down Expand Up @@ -186,7 +189,7 @@ const UserGroupsList: FC<UserGroupsListType> = ({
items={
userGroupsPermission
? sortBy(mergeduserGroupsPermissionWithUserGroups, 'group.name')
: sortBy(userGroups, 'name')
: sortBy(userGroups?.results, 'name')
}
paging={mergeduserGroupsPermissionWithUserGroups || userGroups}
nextPage={() => setPage(page + 1)}
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/modals/Payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const PaymentButton = (props) => {
success: (res) => {
AppActions.updateSubscription(res)
if (this.props.isDisableAccount) {
window.location.href = `/projects`
window.location.href = `/organisation-settings`
}
},
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/pages/ConfirmEmailPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const InvitePage = class extends Component {

onSave = (id) => {
AppActions.selectOrganisation(id)
this.context.router.history.replace('/projects?new=1')
this.context.router.history.replace('/organisation-settings')
}

render() {
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/pages/CreateOrganisationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CreateOrganisationPage extends Component {
onSave = (id) => {
AppActions.selectOrganisation(id)
API.setCookie('organisation', `${id}`)
this.context.router.history.push('/projects')
this.context.router.history.push('/organisation-settings')
}

render() {
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/pages/EnvironmentSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const EnvironmentSettingsPage = class extends Component {

onRemove = () => {
toast('Your project has been removed')
this.context.router.history.replace('/projects')
this.context.router.history.replace('/organisation-settings')
}

confirmRemove = (environment, cb) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/pages/InvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const InvitePage = class extends Component {

onSave = (id) => {
AppActions.selectOrganisation(id)
this.context.router.history.replace('/projects?new=1')
this.context.router.history.replace('/organisation-settings')
}

render() {
Expand Down
7 changes: 4 additions & 3 deletions frontend/web/components/pages/OrganisationSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const OrganisationSettingsPage = class extends Component {
onRemove = () => {
toast('Your organisation has been removed')
if (AccountStore.getOrganisation()) {
this.context.router.history.replace('/projects')
this.context.router.history.replace('/organisation-settings')
} else {
this.context.router.history.replace('/create')
}
Expand Down Expand Up @@ -333,8 +333,6 @@ const OrganisationSettingsPage = class extends Component {
const verifySeatsLimit = Utils.getFlagsmithHasFeature(
'verify_seats_limit_for_invite_links',
)
const canManageGroups =
this.state.permissions.includes('MANAGE_USER_GROUPS')

return (
<div className='app-container container'>
Expand All @@ -348,6 +346,7 @@ const OrganisationSettingsPage = class extends Component {
<OrganisationProvider>
{({
error,
groups,
invalidateInviteLink,
inviteLinks,
invites,
Expand All @@ -356,6 +355,7 @@ const OrganisationSettingsPage = class extends Component {
subscriptionMeta,
users,
}) => {
const canManageGroups = !!groups?.length
const { max_seats } = subscriptionMeta ||
organisation.subscription || { max_seats: 1 }
const isAWS =
Expand Down Expand Up @@ -398,6 +398,7 @@ const OrganisationSettingsPage = class extends Component {
</div>

<Tabs
hideNavOnSingleTab
value={this.state.tab || 0}
onChange={(tab) => this.setState({ tab })}
className='mt-0'
Expand Down
4 changes: 3 additions & 1 deletion frontend/web/components/pages/ProjectSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ const ProjectSettingsPage = class extends Component {
<Button
onClick={() =>
this.confirmRemove(project, () => {
this.context.router.history.replace('/projects')
this.context.router.history.replace(
'/organisation-settings',
)
deleteProject(this.props.match.params.projectId)
})
}
Expand Down
40 changes: 0 additions & 40 deletions frontend/web/components/pages/ProjectsPage.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/web/components/pages/SegmentsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const SegmentsPage: FC<SegmentsPageType> = (props) => {
useEffect(() => {
if (error) {
// Kick user back out to projects
props.router.history.replace('/projects')
props.router.history.replace('/organisation-settings')
}
}, [error, props.router.history])
const newSegment = () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ setTimeout(() => {
(document.location.pathname.indexOf('/project/') !== -1 ||
document.location.pathname.indexOf('/create') !== -1 ||
document.location.pathname.indexOf('/invite') !== -1 ||
document.location.pathname.indexOf('/projects') !== -1) &&
document.location.pathname.indexOf('/organisation-settings') !== -1) &&
!AccountStore.getUser()
) {
API.setRedirect(
Expand Down
2 changes: 0 additions & 2 deletions frontend/web/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import AuditLogPage from './components/pages/AuditLogPage'
import ComparePage from './components/pages/ComparePage'
import WidgetPage from './components/pages/WidgetPage'
import BrokenPage from './components/pages/BrokenPage'
import ProjectsPage from './components/pages/ProjectsPage'
import AuditLogItemPage from './components/pages/AuditLogItemPage'
import FeatureHistoryPage from './components/pages/FeatureHistoryPage'

Expand All @@ -41,7 +40,6 @@ export default (
<Route path='/signup' exact component={HomePage} />
<Route path='/signup' exact component={HomePage} />
<Route path='/home' exact component={HomePage} />
<Route path='/projects' exact component={ProjectsPage} />
<Route path='/maintenance' exact component={Maintenance} />
<Route
path='/password-reset/confirm/:uid/:token/'
Expand Down

0 comments on commit 5ba3083

Please sign in to comment.