Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handling in user magament in the Console #7448

Open
wants to merge 2 commits into
base: v3.33
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -34,6 +34,7 @@ import capitalizeMessage from '@ttn-lw/lib/capitalize-message'
import { createUser } from '@console/store/actions/users'

import { selectPasswordRequirements } from '@console/store/selectors/identity-server'
import attachPromise from '@ttn-lw/lib/store/actions/attach-promise'

const approvalStates = [
'STATE_REQUESTED',
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
Loading