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

mendersoftware / gui / 1350829378

27 Jun 2024 01:46PM UTC coverage: 83.494% (-16.5%) from 99.965%
1350829378

Pull #4465

gitlab-ci

mzedel
chore: test fixes

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #4465: MEN-7169 - feat: added multi sorting capabilities to devices view

4506 of 6430 branches covered (70.08%)

81 of 100 new or added lines in 14 files covered. (81.0%)

1661 existing lines in 163 files now uncovered.

8574 of 10269 relevant lines covered (83.49%)

160.6 hits per line

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

85.71
/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
import { Add as AddIcon } from '@mui/icons-material';
18
// material ui
19
import { Button, Chip, Dialog, DialogActions, DialogContent, DialogTitle } from '@mui/material';
20

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

28
const actions = {
4✔
29
  add: 'addUser',
30
  create: 'createUser',
31
  edit: 'editUser',
32
  remove: 'removeUser'
33
};
34

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

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

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

81
  useEffect(() => {
15✔
82
    dispatch(getUserList());
4✔
83
  }, [dispatch]);
84

85
  useEffect(() => {
15✔
86
    dispatch(getUserList());
4✔
87
  }, [currentUser.id, dispatch, users.length]);
88

89
  const openEdit = user => {
15✔
90
    setUser(user);
3✔
91
    setRemoveDialog(false);
3✔
92
    dispatch(setSnackbar(''));
3✔
93
  };
94

95
  const openRemove = () => {
15✔
96
    dispatch(setSnackbar(''));
1✔
97
    setRemoveDialog(true);
1✔
98
  };
99

100
  const dialogDismiss = () => {
15✔
101
    setUser({});
3✔
102
    setShowCreate(false);
3✔
103
    setRemoveDialog(false);
3✔
104
  };
105

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

127
  return (
15✔
128
    <div>
129
      <div className="flexbox centered space-between" style={{ marginLeft: '20px' }}>
130
        <h2>Users</h2>
131
      </div>
132

133
      <UserList {...props} editUser={openEdit} />
134
      <Chip color="primary" icon={<AddIcon />} label="Add new user" onClick={setShowCreate} />
135
      {showCreate && <UserForm {...props} closeDialog={dialogDismiss} submit={submit} />}
17✔
136
      <UserDefinition
137
        currentUser={currentUser}
138
        isEnterprise={isEnterprise}
139
        onRemove={openRemove}
140
        onCancel={dialogDismiss}
141
        onSubmit={submit}
142
        roles={roles}
143
        selectedUser={user}
144
      />
145
      <DeleteUserDialog dismiss={dialogDismiss} open={removeDialog} submit={submit} user={user} />
146
    </div>
147
  );
148
};
149

150
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