Skip to content

Commit

Permalink
Merge pull request #7448 from TheThingsNetwork/fix/user-magament-errors
Browse files Browse the repository at this point in the history
Fix error handling in user magament in the Console
  • Loading branch information
ryaplots authored Jan 14, 2025
2 parents c731df3 + 49e5ee3 commit 35720e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pkg/webui/console/containers/user-data-form/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Yup from '@ttn-lw/lib/yup'
import createPasswordValidationSchema from '@ttn-lw/lib/create-password-validation-schema'
import { userId as userIdRegexp } from '@ttn-lw/lib/regexp'
import capitalizeMessage from '@ttn-lw/lib/capitalize-message'
import attachPromise from '@ttn-lw/lib/store/actions/attach-promise'

import { createUser } from '@console/store/actions/users'

Expand Down Expand Up @@ -73,7 +74,10 @@ const UserDataFormAdd = () => {
const validationSchema = baseValidationSchema.concat(
createPasswordValidationSchema(passwordRequirements),
)
const createUserAction = useCallback(values => dispatch(createUser(values)), [dispatch])
const createUserAction = useCallback(
values => dispatch(attachPromise(createUser(values))),
[dispatch],
)

const { formatMessage } = intl

Expand Down
10 changes: 8 additions & 2 deletions pkg/webui/console/containers/users-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ import PropTypes from '@ttn-lw/lib/prop-types'
import { getUserId } from '@ttn-lw/lib/selectors/id'
import attachPromise from '@ttn-lw/lib/store/actions/attach-promise'

import { checkFromState, mayManageUsers, maySendInvites } from '@console/lib/feature-checks'
import {
checkFromState,
mayCreateUsers,
mayManageUsers,
mayPerformAllUserActions,
maySendInvites,
} from '@console/lib/feature-checks'

import {
getUsersList,
Expand Down Expand Up @@ -329,7 +335,7 @@ const UsersTable = props => {
(users, totalCount) => ({
users,
totalCount,
mayAdd: mayManageUsers,
mayAdd: mayManageUsers && (mayPerformAllUserActions || mayCreateUsers),
}),
)

Expand Down
9 changes: 9 additions & 0 deletions pkg/webui/console/lib/feature-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export const checkFromState = (featureCheck, state) =>
featureCheck.check(featureCheck.rightsSelector(state))

// User related feature checks.
export const mayPerformAllUserActions = {
rightsSelector: selectUserRights,
check: rights => rights.includes('RIGHT_USER_ALL'),
}
export const mayViewApplicationsOfUser = {
rightsSelector: selectUserRights,
check: rights => rights.includes('RIGHT_USER_APPLICATIONS_LIST'),
Expand Down Expand Up @@ -92,6 +96,11 @@ export const mayViewOrEditUserApiKeys = {
check: rights => rights.includes('RIGHT_USER_SETTINGS_API_KEYS'),
}

export const mayCreateUsers = {
rightsSelector: selectUserRights,
check: rights => rights.includes('RIGHT_USER_CREATE'),
}

// Application related feature checks.
export const mayViewApplicationInfo = {
rightsSelector: selectApplicationRights,
Expand Down

0 comments on commit 35720e1

Please sign in to comment.