Commit cb196342 authored by Leander Schulten's avatar Leander Schulten
Browse files

Users can now be deleted. Swipe in the login tab an entry to the right and click the delete button.

parent 6b724665
Pipeline #148852 passed with stage
in 1 minute and 20 seconds
......@@ -33,7 +33,13 @@ Item{
height: parent.height
//SwipeDelegate.onClicked:
background: Rectangle {
color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato"
color: deleteMouseArea.pressed ? Qt.darker("tomato", 1.1) : "tomato"
}
MouseArea{
id: deleteMouseArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onClicked: askToDeletePopup.deleteUser(modelData)
}
}
Timer{
......@@ -298,7 +304,16 @@ Item{
}
}
AskWhenRemovePopup{
id: askToDeletePopup
property var _user
text: "Do you really want to delete the user " + (_user ? '"' + _user.name + '"' : "error")
function deleteUser(user){
_user = user;
open();
}
onYesClicked: UserManagment.removeUser(_user);
}
Dialog{
modality: Qt.WindowModal
......
......@@ -40,6 +40,14 @@ bool UserManagment::removeUser(User *user, const QString &password){
return false;
}
bool UserManagment::removeUser(User *user){
if (currentUser->havePermission(Admin) && user != currentUser) {
users.remove_if([=](const auto & p){return p.get() == user;});
return true;
}
return false;
}
bool UserManagment::changeUserName(User *user, const QString &newName, const QString &password){
const auto hash = QCryptographicHash::hash(password.toUtf8(),QCryptographicHash::Sha3_256);
if(user->password==hash){
......
......@@ -71,6 +71,12 @@ public:
* @return true for success, false for failure
*/
Q_INVOKABLE bool removeUser(User * user,const QString &password);
/**
* @brief removeUser Removes an user, only successfull if the current user is an admin
* @param user the user to remove, not the current user
* @return true for success, false for failure
*/
Q_INVOKABLE bool removeUser(User * user);
/**
* @brief changeUserName change the username of a user
* @param user the User where to change the username
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment