Skip to content

Commit

Permalink
[#202] Fix convention. Add group input
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan authored and blcham committed Oct 9, 2024
1 parent 0d9cc29 commit 04dba99
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/components/record/Records.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { Alert, Button, Card } from "react-bootstrap";
import { injectIntl } from "react-intl";
import withI18n from "../../i18n/withI18n";
import { EXTENSION_CONSTANTS, ROLE } from "../../constants/DefaultConstants";
import { ROLE } from "../../constants/DefaultConstants";
import PropTypes from "prop-types";
import { processTypeaheadOptions } from "./TypeaheadAnswer";
import { EXTENSIONS } from "../../../config";
Expand Down
54 changes: 33 additions & 21 deletions src/components/user/User.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import withI18n from "../../i18n/withI18n";
import { injectIntl } from "react-intl";
import HorizontalInput from "../HorizontalInput";
import UserValidator from "../../validation/UserValidator";
import { ACTION_STATUS, ROLE, ROLE_TYPE } from "../../constants/DefaultConstants";
import { getRole, processInstitutions } from "../../utils/Utils";
import * as Vocabulary from "../../constants/Vocabulary";
import { ACTION_STATUS, GROUP, ROLE_TYPE } from "../../constants/DefaultConstants";
import { processInstitutions } from "../../utils/Utils";
import { LoaderCard, LoaderSmall } from "../Loader";
import HelpIcon from "../HelpIcon";
import PropTypes from "prop-types";
import { FaRandom } from "react-icons/fa";
import { isUsingOidcAuth } from "../../utils/OidcUtils";
import { getRoles, isAdmin } from "../../utils/SecurityUtils";
import { getRoles, isAdmin, roleToType } from "../../utils/SecurityUtils";
import RoleSelector from "../../RoleSelector.jsx";

class User extends React.Component {
Expand Down Expand Up @@ -57,17 +56,6 @@ class User extends React.Component {
this.props.handlers.onChange(change);
};

_onAdminStatusChange = (e) => {
const role = e.target.value;
let types = this.props.user.types.slice();
if (role === ROLE.ADMIN) {
types.push(Vocabulary.ADMIN_TYPE);
} else {
types.splice(types.indexOf(Vocabulary.ADMIN_TYPE), 1);
}
this.props.handlers.onChange({ types: types });
};

_generateInstitutionsOptions = () => {
let options = [];
const institutions = processInstitutions(this.props.institutions);
Expand All @@ -88,15 +76,21 @@ class User extends React.Component {
return options;
};

_generateRolesOptions = () => {
const roles = ROLE;
return Object.keys(roles).map((key) => {
_generateGroupOptions = () => {
let options = Object.keys(GROUP).map((key) => {
return (
<option key={roles[key]} value={roles[key]}>
{roles[key]}
<option key={"opt_" + key} value={key}>
{GROUP[key]}
</option>
);
});

options.unshift(
<option key="opt_default" value="" disabled style={{ display: "none" }}>
{this.i18n("select.default")}
</option>,
);
return options;
};

_passwordChangeButton() {
Expand Down Expand Up @@ -210,6 +204,10 @@ class User extends React.Component {
this.props.handlers.onChange({ types: types });
}

_onGroupSelected(group) {
this.props.handlers.onChange({ group: group });
}

_onSaveAndSendEmail() {
this.props.handlers.onSave();
this.setState({ savedWithEmail: true });
Expand Down Expand Up @@ -295,6 +293,20 @@ class User extends React.Component {
</div>
</div>
<div className="row">
<div className="col-12 col-sm-6">
<HorizontalInput
type="select"
name="group"
label={`${this.i18n("user.group")}*`}
disabled={(!isAdmin(currentUser) && currentUser.username !== user.username) || isUsingOidcAuth()}
value={user.group}
labelWidth={3}
inputWidth={8}
onChange={this._onGroupSelected}
>
{this._generateGroupOptions()}
</HorizontalInput>
</div>
{isAdmin(currentUser) && (
<div className="col-12 col-sm-6">
<HorizontalInput
Expand Down Expand Up @@ -332,7 +344,7 @@ class User extends React.Component {
selected={getRoles(user)}
handler={this._onRoleSelected}
readOnly={(!isAdmin(currentUser) && currentUser.username !== user.username) || isUsingOidcAuth()}
label={this.i18n("user.roles")}
label={`${this.i18n("user.roles")}*`}
/>
</div>
<div className="buttons-line-height mt-3 text-center">
Expand Down
6 changes: 6 additions & 0 deletions src/constants/DefaultConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export const ROLE = {
IMPORT_CODELISTS: "rm_import_codelists",
};

export const GROUP = {
OPERATOR: "Operator",
SUPPLIER: "Supplier",
EXTERNAL_USER: "External User",
};

export const TYPE_ROLE = {
[Vocabulary.ADMIN_TYPE]: ROLE.ADMIN,
[Vocabulary.DOCTOR_TYPE]: ROLE.DOCTOR,
Expand Down
23 changes: 12 additions & 11 deletions src/constants/Vocabulary.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
/**
* Ontological vocabulary used by JSON-LD responses we get.
*/
export const RECORD_MANAGER_URL = "http://onto.fel.cvut.cz/ontologies/record-manager";
export const RDFS_LABEL = "http://www.w3.org/2000/01/rdf-schema#label";
export const RDFS_COMMENT = "http://www.w3.org/2000/01/rdf-schema#comment";
export const ADMIN_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/administrator";
export const DOCTOR_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/doctor";
export const IMPERSONATOR_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/impersonator";
export const COMPLETE_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/record-complete";
export const REJECT_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/reject-records";
export const PUBLISH_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/publish-records";
export const DELETE_ALL_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/delete-all-records";
export const EDIT_ALL_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/edit-all-records";
export const VIEW_ALL_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/view-all-records";
export const COMPLETE_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/complete_records";
export const REJECT_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/reject_records";
export const PUBLISH_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/publish_records";
export const DELETE_ALL_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/delete_all_records";
export const EDIT_ALL_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/edit_all_records";
export const VIEW_ALL_RECORDS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/view_all_records";
export const DELETE_ORGANIZATION_RECORDS_TYPE =
"http://onto.fel.cvut.cz/ontologies/record-manager/delete-organization-records";
"http://onto.fel.cvut.cz/ontologies/record-manager/delete_organization_records";
export const EDIT_ORGANIZATION_RECORDS_TYPE =
"http://onto.fel.cvut.cz/ontologies/record-manager/edit-organization-records";
"http://onto.fel.cvut.cz/ontologies/record-manager/edit_organization_records";
export const VIEW_ORGANIZATION_RECORDS_TYPE =
"http://onto.fel.cvut.cz/ontologies/record-manager/view-organization-records";
export const EDIT_USERS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/edit-users";
export const IMPORT_CODELISTS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/import-codelists";
"http://onto.fel.cvut.cz/ontologies/record-manager/view_organization_records";
export const EDIT_USERS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/edit_users";
export const IMPORT_CODELISTS_TYPE = "http://onto.fel.cvut.cz/ontologies/record-manager/import_codelists";
1 change: 1 addition & 0 deletions src/i18n/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default {
"user.passwords-not-matching-tooltip": "Hesla se neshodují",
"user.role": "Role",
"user.roles": "Roles",
"user.group": "Skupina",
"user.save-success": "Uživatel úspěšně uložen",
"user.save-success-with-email": "Uživatel úspěšně uložen a informován emailem.",
"user.save-error": "Uživatele se nepodařilo uložit. {error}",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default {
"user.passwords-not-matching-tooltip": "Passwords don't match",
"user.role": "Role",
"user.roles": "Roles",
"user.group": "Group",
"user.save-success": "User saved successfully",
"user.save-success-with-email": "User saved successfully and informed by email.",
"user.save-error": "Unable to save user. {error}",
Expand Down
6 changes: 3 additions & 3 deletions tests/__tests__/components/User.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe("User", function () {
}
}
const selects = TestUtils.scryRenderedDOMComponentsWithTag(tree, "select");
expect(selects.length).toEqual(1);
expect(selects.length).toEqual(2);
const randomButton = TestUtils.scryRenderedDOMComponentsWithClass(tree, "button-random");
expect(randomButton.length).toEqual(1);
});
Expand Down Expand Up @@ -316,7 +316,7 @@ describe("User", function () {
}
}
const selects = TestUtils.scryRenderedDOMComponentsWithTag(tree, "select");
expect(selects.length).toEqual(1);
expect(selects.length).toEqual(2);
expect(selects[0].disabled).toBeFalsy();
const randomButton = TestUtils.scryRenderedDOMComponentsWithClass(tree, "glyphicon");
expect(randomButton.length).toEqual(0);
Expand Down Expand Up @@ -361,7 +361,7 @@ describe("User", function () {
}
}
const selects = TestUtils.scryRenderedDOMComponentsWithTag(tree, "select");
expect(selects.length).toEqual(1);
expect(selects.length).toEqual(2);
expect(selects[0].disabled).toBeFalsy();
});

Expand Down

0 comments on commit 04dba99

Please sign in to comment.