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

mendersoftware / gui / 1057188406

01 Nov 2023 04:24AM UTC coverage: 82.824% (-17.1%) from 99.964%
1057188406

Pull #4134

gitlab-ci

web-flow
chore: Bump uuid from 9.0.0 to 9.0.1

Bumps [uuid](https://github.com/uuidjs/uuid) from 9.0.0 to 9.0.1.
- [Changelog](https://github.com/uuidjs/uuid/blob/main/CHANGELOG.md)
- [Commits](https://github.com/uuidjs/uuid/compare/v9.0.0...v9.0.1)

---
updated-dependencies:
- dependency-name: uuid
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #4134: chore: Bump uuid from 9.0.0 to 9.0.1

4349 of 6284 branches covered (0.0%)

8313 of 10037 relevant lines covered (82.82%)

200.97 hits per line

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

87.5
/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
const DeleteUserDialog = ({ dismiss, open, submit, user }) => (
5✔
34
  <Dialog open={open}>
14✔
35
    <DialogTitle>Delete user?</DialogTitle>
36
    <DialogContent style={{ overflow: 'hidden' }}>
37
      Are you sure you want to delete the user with email{' '}
38
      <b>
39
        <i>{user.email}</i>
40
      </b>
41
      ?
42
    </DialogContent>
43
    <DialogActions>
44
      <Button style={{ marginRight: 10 }} onClick={dismiss}>
45
        Cancel
46
      </Button>
47
      <Button variant="contained" color="primary" onClick={() => submit(user, 'remove', user.id)}>
×
48
        Delete user
49
      </Button>
50
    </DialogActions>
51
  </Dialog>
52
);
53

54
export const UserManagement = () => {
5✔
55
  const [showCreate, setShowCreate] = useState(false);
15✔
56
  const [removeDialog, setRemoveDialog] = useState(false);
14✔
57
  const [user, setUser] = useState({});
14✔
58
  const dispatch = useDispatch();
14✔
59

60
  const { canManageUsers } = useSelector(getUserCapabilities);
14✔
61
  const { isHosted } = useSelector(getFeatures);
14✔
62
  const isEnterprise = useSelector(getIsEnterprise);
14✔
63
  const currentUser = useSelector(getCurrentUser);
14✔
64
  const roles = useSelector(getRolesById);
14✔
65
  const users = useSelector(state => Object.values(state.users.byId));
26✔
66
  const props = {
14✔
67
    canManageUsers,
68
    createUser: userData => dispatch(createUser(userData)),
1✔
69
    currentUser,
70
    editUser: (id, userData) => dispatch(editUser(id, userData)),
1✔
71
    isEnterprise,
72
    isHosted,
73
    removeUser: id => dispatch(removeUser(id)),
×
74
    roles,
75
    users
76
  };
77

78
  useEffect(() => {
14✔
79
    dispatch(getUserList());
4✔
80
  }, [dispatch]);
81

82
  useEffect(() => {
14✔
83
    dispatch(getUserList());
5✔
84
  }, [currentUser.id, dispatch, users.length]);
85

86
  const openEdit = user => {
14✔
87
    setUser(user);
3✔
88
    setRemoveDialog(false);
3✔
89
    dispatch(setSnackbar(''));
3✔
90
  };
91

92
  const openRemove = () => {
14✔
93
    dispatch(setSnackbar(''));
1✔
94
    setRemoveDialog(true);
1✔
95
  };
96

97
  const dialogDismiss = () => {
14✔
98
    setUser({});
2✔
99
    setShowCreate(false);
2✔
100
    setRemoveDialog(false);
2✔
101
  };
102

103
  const submit = (userData, type, id, passwordResetEmail) => {
14✔
104
    if (userData) {
2!
105
      let request = null;
2✔
106
      if (id) {
2✔
107
        request = props[actions[type]](id, userData);
1✔
108
      } else {
109
        request = props[actions[type]](userData);
1✔
110
      }
111
      return request.then(() => {
2✔
112
        if (passwordResetEmail) {
1!
113
          dispatch(passwordResetStart(passwordResetEmail));
×
114
        }
115
        dialogDismiss();
1✔
116
      });
117
    }
118
    if (passwordResetEmail) {
×
119
      dispatch(passwordResetStart(passwordResetEmail));
×
120
    }
121
    return dialogDismiss();
×
122
  };
123

124
  return (
14✔
125
    <div>
126
      <div className="flexbox centered space-between" style={{ marginLeft: '20px' }}>
127
        <h2>Users</h2>
128
        <Button variant="contained" color="primary" onClick={setShowCreate}>
129
          Create new user
130
        </Button>
131
      </div>
132

133
      <UserList {...props} editUser={openEdit} />
134
      {showCreate && <UserForm {...props} closeDialog={dialogDismiss} submit={submit} />}
19✔
135
      <UserDefinition
136
        currentUser={currentUser}
137
        isEnterprise={isEnterprise}
138
        onRemove={openRemove}
139
        onCancel={dialogDismiss}
140
        onSubmit={submit}
141
        roles={roles}
142
        selectedUser={user}
143
      />
144
      <DeleteUserDialog dismiss={dialogDismiss} open={removeDialog} submit={submit} user={user} />
145
    </div>
146
  );
147
};
148

149
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