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

mendersoftware / gui / 897326496

pending completion
897326496

Pull #3752

gitlab-ci

mzedel
chore(e2e): made use of shared timeout & login checking values to remove code duplication

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3752: chore(e2e-tests): slightly simplified log in test + separated log out test

4395 of 6392 branches covered (68.76%)

8060 of 9780 relevant lines covered (82.41%)

126.17 hits per line

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

71.7
/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 { connect } 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, 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 = props => {
5✔
34
  const { currentUser, getUserList, isEnterprise, passwordResetStart, roles, setSnackbar, users } = props;
8✔
35
  const [showCreate, setShowCreate] = useState(false);
8✔
36
  const [removeDialog, setRemoveDialog] = useState(false);
8✔
37
  const [user, setUser] = useState({});
8✔
38

39
  useEffect(() => {
8✔
40
    getUserList();
3✔
41
  }, []);
42

43
  useEffect(() => {
8✔
44
    getUserList();
3✔
45
  }, [currentUser.id, users.length]);
46

47
  const openEdit = user => {
8✔
48
    setUser(user);
3✔
49
    setRemoveDialog(false);
3✔
50
    setSnackbar('');
3✔
51
  };
52

53
  const openRemove = () => {
8✔
54
    setSnackbar('');
1✔
55
    setRemoveDialog(true);
1✔
56
  };
57

58
  const dialogDismiss = () => {
8✔
59
    setUser({});
1✔
60
    setShowCreate(false);
1✔
61
    setRemoveDialog(false);
1✔
62
  };
63

64
  const submit = (userData, type, id, passwordResetEmail) => {
8✔
65
    if (userData) {
1!
66
      let request = null;
1✔
67
      if (id) {
1!
68
        request = props[actions[type]](id, userData);
1✔
69
      } else {
70
        request = props[actions[type]](userData);
×
71
      }
72
      return request.then(() => {
1✔
73
        if (passwordResetEmail) {
×
74
          passwordResetStart(passwordResetEmail);
×
75
        }
76
        dialogDismiss();
×
77
      });
78
    }
79
    if (passwordResetEmail) {
×
80
      passwordResetStart(passwordResetEmail);
×
81
    }
82
    return dialogDismiss();
×
83
  };
84

85
  return (
8✔
86
    <div>
87
      <div className="flexbox centered space-between" style={{ marginLeft: '20px' }}>
88
        <h2>Users</h2>
89
        <Button variant="contained" color="primary" onClick={setShowCreate}>
90
          Create new user
91
        </Button>
92
      </div>
93

94
      <UserList {...props} editUser={openEdit} />
95
      {showCreate && <UserForm {...props} closeDialog={dialogDismiss} submit={submit} />}
8!
96
      <UserDefinition
97
        currentUser={currentUser}
98
        isEnterprise={isEnterprise}
99
        onRemove={openRemove}
100
        onCancel={dialogDismiss}
101
        onSubmit={submit}
102
        roles={roles}
103
        selectedUser={user}
104
      />
105
      {removeDialog && (
9✔
106
        <Dialog open>
107
          <DialogTitle>Remove user?</DialogTitle>
108
          <DialogContent style={{ overflow: 'hidden' }}>
109
            Are you sure you want to remove the user with email{' '}
110
            <b>
111
              <i>{user.email}</i>
112
            </b>
113
            ?
114
          </DialogContent>
115
          <DialogActions>
116
            <Button style={{ marginRight: 10 }} onClick={dialogDismiss}>
117
              Cancel
118
            </Button>
119
            <Button variant="contained" color="primary" onClick={() => submit(user, 'remove', user.id)}>
×
120
              Remove user
121
            </Button>
122
          </DialogActions>
123
        </Dialog>
124
      )}
125
    </div>
126
  );
127
};
128

129
const actionCreators = { createUser, editUser, getUserList, passwordResetStart, removeUser, setSnackbar };
5✔
130

131
const mapStateToProps = state => {
5✔
132
  const { canManageUsers } = getUserCapabilities(state);
3✔
133
  const { isHosted } = getFeatures(state);
3✔
134
  return {
3✔
135
    currentUser: getCurrentUser(state),
136
    canManageUsers,
137
    isEnterprise: getIsEnterprise(state),
138
    isHosted,
139
    roles: state.users.rolesById,
140
    users: Object.values(state.users.byId)
141
  };
142
};
143

144
export default connect(mapStateToProps, actionCreators)(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