Skip to content

Commit

Permalink
UI: New administrative user view (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
KWMORALE committed May 6, 2021
1 parent b8b5093 commit df15e16
Show file tree
Hide file tree
Showing 15 changed files with 646 additions and 464 deletions.
2 changes: 2 additions & 0 deletions mwdb/schema/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class UserItemResponseSchema(UserLoginSchemaBase):
groups = fields.Nested(
GroupBasicResponseSchema, many=True, required=True, allow_none=False
)
capabilities = fields.List(fields.Str(), required=True, allow_none=False)

api_keys = fields.Nested(
APIKeyListItemResponseSchema, many=True, required=True, allow_none=False
)
Expand Down
4 changes: 4 additions & 0 deletions mwdb/web/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import {
faCopy,
faThumbtack,
faStar,
faEdit,
faSave,
} from "@fortawesome/free-solid-svg-icons";
import { faStar as farStar } from "@fortawesome/free-regular-svg-icons";

Expand Down Expand Up @@ -99,6 +101,8 @@ library.add(faCopy);
library.add(faThumbtack);
library.add(faStar);
library.add(farStar);
library.add(faEdit);
library.add(faSave);

function DefaultRoute() {
const location = useLocation();
Expand Down
11 changes: 8 additions & 3 deletions mwdb/web/src/commons/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,18 @@ function registerUser(login, email, additional_info, recaptcha) {
});
}

function updateUser(login, email, additional_info, feed_quality) {
function updateUser(login, { email, additionalInfo, feedQuality }) {
return axios.put(`/user/${login}`, {
email,
additional_info,
feed_quality,
additional_info: additionalInfo,
feed_quality: feedQuality,
});
}

function removeUser(login) {
return axios.delete(`/user/${login}`);
}

function getReadableMetakeyDefinitions() {
return axios.get("/meta/list/read");
}
Expand Down Expand Up @@ -498,6 +502,7 @@ export default {
createUser,
registerUser,
updateUser,
removeUser,
getReadableMetakeyDefinitions,
getSettableMetakeyDefinitions,
getMetakeyDefinitions,
Expand Down
18 changes: 10 additions & 8 deletions mwdb/web/src/components/Profile/Views/ProfileAPIKeys.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from "react";
import { CopyToClipboard } from "react-copy-to-clipboard";
import { useHistory } from "react-router-dom";
import { useHistory, useLocation } from "react-router-dom";

import {
faCopy,
Expand All @@ -21,6 +21,7 @@ import {

export default function ProfileAPIKeys({ profile, updateProfile }) {
const history = useHistory();
const location = useLocation();
const [currentApiToken, setCurrentApiToken] = useState({});
const [apiKeyToRemove, setApiKeyToRemove] = useState();
const [removeModalOpened, setRemoveModalOpened] = useState(false);
Expand All @@ -34,7 +35,7 @@ export default function ProfileAPIKeys({ profile, updateProfile }) {
setCurrentApiToken(response.data);
} catch (error) {
history.push({
pathname: "/profile/api-keys",
pathname: location.pathname,
state: { error: getErrorMessage(error) },
});
}
Expand All @@ -46,15 +47,15 @@ export default function ProfileAPIKeys({ profile, updateProfile }) {
setCurrentApiToken(response.data);
updateProfile();
history.push({
pathname: "/profile/api-keys",
pathname: location.pathname,
state: {
success: "New API key successfully added",
addedKey: response.data.id,
},
});
} catch (error) {
history.push({
pathname: "/profile/api-keys",
pathname: location.pathname,
state: { error: getErrorMessage(error) },
});
}
Expand All @@ -68,22 +69,23 @@ export default function ProfileAPIKeys({ profile, updateProfile }) {
updateProfile();
setRemoveModalOpened(false);
history.push({
pathname: "/profile/api-keys",
pathname: location.pathname,
state: {
success: "API key successfully removed",
},
});
} catch (error) {
history.push({
pathname: "/profile/api-keys",
pathname: location.pathname,
state: { error: getErrorMessage(error) },
});
}
}

if (Object.keys(profile).length === 0) return [];

return (
<div>
<h5>API keys</h5>
<div className="container">
{!profile.api_keys.length ? (
<p>
<i>
Expand Down
3 changes: 1 addition & 2 deletions mwdb/web/src/components/Profile/Views/ProfileCapabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ function CapabilitiesTable({ profile }) {

export default function ProfileCapabilities({ profile }) {
return (
<div>
<h4>Account capabilities</h4>
<div className="container">
<CapabilitiesTable profile={profile} />
</div>
);
Expand Down
12 changes: 9 additions & 3 deletions mwdb/web/src/components/Settings/SettingsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import ShowPendingUsers from "./Views/ShowPendingUsers";
import ManageAttributes from "./Views/ManageAttributes";
import AttributeUpdate from "./Views/AttributeUpdate";
import GroupUpdate from "./Views/GroupUpdate";
import UserUpdate from "./Views/UserUpdate";
import UserCreate from "./Views/UserCreate";
import GroupRegister from "./Views/GroupRegister";
import AttributeDefine from "./Views/AttributeDefine";
import UserView from "./Views/UserView";

function SettingsNav() {
const auth = useContext(AuthContext);
Expand Down Expand Up @@ -138,9 +138,15 @@ export default function SettingsView(props) {
</AdministrativeRoute>
<AdministrativeRoute
exact
path="/admin/user/:login"
path={[
"/admin/user/:login",
"/admin/user/:login/password",
"/admin/user/:login/capabilities",
"/admin/user/:login/api-keys",
"/admin/user/:login/groups",
]}
>
<UserUpdate />
<UserView />
</AdministrativeRoute>

<AdministrativeRoute exact path="/admin/groups">
Expand Down
4 changes: 2 additions & 2 deletions mwdb/web/src/components/Settings/Views/AttributeDefine.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AttributeDefine extends Component {
this.state.template,
this.state.hidden
);
this.props.history.push(`/attribute/${this.state.metakey}`);
this.props.history.push(`/admin/attribute/${this.state.metakey}`);
} catch (error) {
this.setState({ ...this.initialState, error });
}
Expand Down Expand Up @@ -132,7 +132,7 @@ class AttributeDefine extends Component {
<label
htmlFor="hidden_checkbox"
className="bg-primary"
></label>
/>
</div>
<div className="form-hint">
Hidden attributes have protected values. Attribute
Expand Down
2 changes: 1 addition & 1 deletion mwdb/web/src/components/Settings/Views/AttributeUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class AttributeUpdate extends Component {
this.setState({ disabledModalButton: true });
try {
await api.removeMetakeyDefinition(metakey);
this.props.history.push("/attributes");
this.props.history.push("/admin/attributes");
} catch (error) {
this.setState({
disabledModalButton: false,
Expand Down
6 changes: 3 additions & 3 deletions mwdb/web/src/components/Settings/Views/ShowUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from "react";
import { Link } from "react-router-dom";

import api from "@mwdb-web/commons/api";
import { PagedList, View, HighlightText } from "@mwdb-web/commons/ui";
import { PagedList, HighlightText } from "@mwdb-web/commons/ui";

import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faUser, faRobot } from "@fortawesome/free-solid-svg-icons";
Expand Down Expand Up @@ -51,7 +51,7 @@ class ShowUsers extends Component {

render() {
return (
<View fluid ident="showUsers" error={this.state.error}>
<div>
<Link to="/admin/user/new">
<button type="button" className="btn btn-success">
Register user
Expand All @@ -70,7 +70,7 @@ class ShowUsers extends Component {
onPageChange={this.handlePageChange}
onFilterChange={this.handleFilterChange}
/>
</View>
</div>
);
}
}
Expand Down

0 comments on commit df15e16

Please sign in to comment.