Skip to content

Commit

Permalink
Merge pull request #108 from gravitl/kwesi/net-348-bug-user-permissio…
Browse files Browse the repository at this point in the history
…ns-not-working

fix(NET-348): disable buggy user mgmt settings
  • Loading branch information
afeiszli authored Jun 19, 2023
2 parents 3e03fb5 + f274de2 commit 4383ac3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 393 deletions.
66 changes: 4 additions & 62 deletions src/components/modals/add-user-modal/AddUserModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Col, Divider, Form, Input, Modal, notification, Row, Select, Switch } from 'antd';
import { MouseEvent, useCallback, useEffect, useMemo, useState } from 'react';
import { Button, Col, Divider, Form, Input, Modal, notification, Row, Switch } from 'antd';
import { MouseEvent, useCallback, useEffect, useState } from 'react';
import { useStore } from '@/store/store';
import '../CustomModal.scss';
import { extractErrorMsg } from '@/utils/ServiceUtils';
Expand All @@ -24,12 +24,6 @@ export default function AddUserModal({ isOpen, onCreateUser, onCancel }: AddUser
const isAdminVal = Form.useWatch('isadmin', form);
const passwordVal = Form.useWatch('password', form);

const userGroups = useMemo(() => {
const groups = new Set<string>();
users.forEach((u) => u.groups?.forEach((g) => groups.add(g)));
return Array.from(groups);
}, [users]);

const resetModal = () => {
form.resetFields();
};
Expand Down Expand Up @@ -88,7 +82,7 @@ export default function AddUserModal({ isOpen, onCreateUser, onCancel }: AddUser
>
<Divider style={{ margin: '0px 0px 2rem 0px' }} />
<div className="CustomModalBody">
<Form name="add-user-form" form={form} layout="vertical" initialValues={{ groups: ['*'] }}>
<Form name="add-user-form" form={form} layout="vertical" initialValues={{ groups: ['*'], isadmin: true }}>
<Form.Item label="Username" name="username" rules={[{ required: true }]}>
<Input placeholder="Username" />
</Form.Item>
Expand Down Expand Up @@ -119,6 +113,7 @@ export default function AddUserModal({ isOpen, onCreateUser, onCancel }: AddUser

<Form.Item label="Is admin" name="isadmin" valuePropName="checked">
<Switch
disabled
onChange={(newVal) => {
if (newVal) {
form.setFieldValue('networks', []);
Expand All @@ -127,59 +122,6 @@ export default function AddUserModal({ isOpen, onCreateUser, onCancel }: AddUser
/>
</Form.Item>

{isServerEE && (
<Form.Item label="User groups">
<Row>
<Col xs={18}>
<Form.Item name="groups" noStyle>
<Select
mode="multiple"
placeholder="Groups"
options={userGroups.map((g) => ({ label: g, value: g }))}
/>
</Form.Item>
</Col>
<Col xs={6} style={{ textAlign: 'right' }}>
<Button
onClick={() => {
form.setFieldValue('groups', userGroups);
}}
>
Select All
</Button>
</Col>
</Row>
</Form.Item>
)}

<Form.Item label="Allowed Networks">
<Row>
<Col xs={18}>
<Form.Item name="networks" noStyle>
<Select
disabled={isAdminVal}
mode="multiple"
placeholder="Networks"
options={store.networks.map((n) => ({ label: n.netid, value: n.netid }))}
/>
</Form.Item>
</Col>
<Col xs={6} style={{ textAlign: 'right' }}>
<Button
disabled={isAdminVal}
onClick={() => {
form.setFieldValue(
'networks',
store.networks.map((n) => n.netid)
);
}}
>
Select All
</Button>
</Col>
</Row>
</Form.Item>

<Row>
<Col xs={24} style={{ textAlign: 'right' }}>
<Form.Item>
Expand Down
Loading

0 comments on commit 4383ac3

Please sign in to comment.