• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / gui / 919001084

pending completion
919001084

Pull #3839

gitlab-ci

mzedel
revert: "chore: bump node from 20.2.0-alpine to 20.3.1-alpine"

This reverts commit cbfcd7663.

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3839: Combined PRs

4399 of 6397 branches covered (68.77%)

8302 of 10074 relevant lines covered (82.41%)

162.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.76
/src/js/components/settings/user-management/usermanagement.js
1
// Copyright 2017 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14
import React, { useEffect, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16

17
// material ui
18
import { Button, Dialog, DialogActions, DialogContent, DialogTitle } from '@mui/material';
19

20
import { setSnackbar } from '../../../actions/appActions';
21
import { createUser, editUser, getUserList, passwordResetStart, removeUser } from '../../../actions/userActions';
22
import { getCurrentUser, getFeatures, getIsEnterprise, getRolesById, getUserCapabilities } from '../../../selectors';
23
import { UserDefinition } from './userdefinition';
24
import UserForm from './userform';
25
import UserList from './userlist';
26

27
const actions = {
5✔
28
  create: 'createUser',
29
  edit: 'editUser',
30
  remove: 'removeUser'
31
};
32

33
export const UserManagement = () => {
5✔
34
  const [showCreate, setShowCreate] = useState(false);
11✔
35
  const [removeDialog, setRemoveDialog] = useState(false);
10✔
36
  const [user, setUser] = useState({});
10✔
37
  const dispatch = useDispatch();
10✔
38

39
  const { canManageUsers } = useSelector(getUserCapabilities);
10✔
40
  const { isHosted } = useSelector(getFeatures);
10✔
41
  const isEnterprise = useSelector(getIsEnterprise);
10✔
42
  const currentUser = useSelector(getCurrentUser);
10✔
43
  const roles = useSelector(getRolesById);
10✔
44
  const users = useSelector(state => Object.values(state.users.byId));
10✔
45
  const props = {
10✔
46
    canManageUsers,
47
    createUser: userData => dispatch(createUser(userData)),
1✔
48
    currentUser,
49
    editUser: (id, userData) => dispatch(editUser(id, userData)),
1✔
50
    isEnterprise,
51
    isHosted,
52
    removeUser: id => dispatch(removeUser(id)),
×
53
    roles,
54
    users
55
  };
56

57
  useEffect(() => {
10✔
58
    dispatch(getUserList());
4✔
59
  }, []);
60

61
  useEffect(() => {
10✔
62
    dispatch(getUserList());
4✔
63
  }, [currentUser.id, users.length]);
64

65
  const openEdit = user => {
10✔
66
    setUser(user);
3✔
67
    setRemoveDialog(false);
3✔
68
    dispatch(setSnackbar(''));
3✔
69
  };
70

71
  const openRemove = () => {
10✔
72
    dispatch(setSnackbar(''));
1✔
73
    setRemoveDialog(true);
1✔
74
  };
75

76
  const dialogDismiss = () => {
10✔
77
    setUser({});
2✔
78
    setShowCreate(false);
2✔
79
    setRemoveDialog(false);
2✔
80
  };
81

82
  const submit = (userData, type, id, passwordResetEmail) => {
10✔
83
    if (userData) {
2!
84
      let request = null;
2✔
85
      if (id) {
2✔
86
        request = props[actions[type]](id, userData);
1✔
87
      } else {
88
        request = props[actions[type]](userData);
1✔
89
      }
90
      return request.then(() => {
2✔
91
        if (passwordResetEmail) {
1!
92
          dispatch(passwordResetStart(passwordResetEmail));
×
93
        }
94
        dialogDismiss();
1✔
95
      });
96
    }
97
    if (passwordResetEmail) {
×
98
      dispatch(passwordResetStart(passwordResetEmail));
×
99
    }
100
    return dialogDismiss();
×
101
  };
102

103
  return (
10✔
104
    <div>
105
      <div className="flexbox centered space-between" style={{ marginLeft: '20px' }}>
106
        <h2>Users</h2>
107
        <Button variant="contained" color="primary" onClick={setShowCreate}>
108
          Create new user
109
        </Button>
110
      </div>
111

112
      <UserList {...props} editUser={openEdit} />
113
      {showCreate && <UserForm {...props} closeDialog={dialogDismiss} submit={submit} />}
11✔
114
      <UserDefinition
115
        currentUser={currentUser}
116
        isEnterprise={isEnterprise}
117
        onRemove={openRemove}
118
        onCancel={dialogDismiss}
119
        onSubmit={submit}
120
        roles={roles}
121
        selectedUser={user}
122
      />
123
      {removeDialog && (
11✔
124
        <Dialog open>
125
          <DialogTitle>Remove user?</DialogTitle>
126
          <DialogContent style={{ overflow: 'hidden' }}>
127
            Are you sure you want to remove the user with email{' '}
128
            <b>
129
              <i>{user.email}</i>
130
            </b>
131
            ?
132
          </DialogContent>
133
          <DialogActions>
134
            <Button style={{ marginRight: 10 }} onClick={dialogDismiss}>
135
              Cancel
136
            </Button>
137
            <Button variant="contained" color="primary" onClick={() => submit(user, 'remove', user.id)}>
×
138
              Remove user
139
            </Button>
140
          </DialogActions>
141
        </Dialog>
142
      )}
143
    </div>
144
  );
145
};
146

147
export default UserManagement;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc