From 622eb23fe00fe598512897aaeaba68ad69c5345e Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Thu, 20 Aug 2020 20:04:41 +0000 Subject: [PATCH] small fixes, highlight row when selected --- api/tacticalrmm/accounts/urls.py | 2 +- api/tacticalrmm/accounts/views.py | 21 +++++------ web/src/components/AdminManager.vue | 58 +++++++++++++---------------- web/src/store/admin.js | 6 +-- 4 files changed, 39 insertions(+), 48 deletions(-) diff --git a/api/tacticalrmm/accounts/urls.py b/api/tacticalrmm/accounts/urls.py index 703e4a2f..4ef64db2 100644 --- a/api/tacticalrmm/accounts/urls.py +++ b/api/tacticalrmm/accounts/urls.py @@ -3,7 +3,7 @@ from . import views urlpatterns = [ path("users/", views.GetAddUsers.as_view()), - path("users//", views.GetUpdateDeleteUser.as_view()), + path("/users/", views.GetUpdateDeleteUser.as_view()), path("users/reset/", views.UserActions.as_view()), path("users/reset_totp/", views.UserActions.as_view()), path("users/setup_totp/", views.TOTPSetup.as_view()), diff --git a/api/tacticalrmm/accounts/views.py b/api/tacticalrmm/accounts/views.py index 7a9c7ba6..d51a04c0 100644 --- a/api/tacticalrmm/accounts/views.py +++ b/api/tacticalrmm/accounts/views.py @@ -25,7 +25,7 @@ class CheckCreds(KnoxLoginView): serializer = AuthTokenSerializer(data=request.data) serializer.is_valid(raise_exception=True) - user = User.objects.get(username=request.data["username"]) + user = get_object_or_404(User, username=request.data["username"]) if not user.totp_key: return Response("totp not set") @@ -68,18 +68,15 @@ class GetAddUsers(APIView): def post(self, request): - # Remove password from serializer - password = request.data.pop("password") - - serializer = UserSerializer(data=request.data, partial=True) - serializer.is_valid(raise_exception=True) - user = serializer.save() + user = User.objects.create_user( + request.data["username"], request.data["email"], request.data["password"] + ) + user.first_name = request.data["first_name"] + user.last_name = request.data["last_name"] # Can be changed once permissions and groups are introduced user.is_superuser = True - user.set_password = password user.save() - return Response("ok") @@ -99,7 +96,7 @@ class GetUpdateDeleteUser(APIView): return Response("ok") def delete(self, request, pk): - User.objects.get(pk=pk).delete() + get_object_or_404(User, pk=pk).delete() return Response("ok") @@ -109,7 +106,7 @@ class UserActions(APIView): # reset password def post(self, request): - user = User.objects.get(pk=request.data["id"]) + user = get_object_or_404(User, pk=request.data["id"]) user.set_password(request.data["password"]) user.save() @@ -118,7 +115,7 @@ class UserActions(APIView): # reset two factor token def put(self, request): - user = User.objects.get(pk=request.data["id"]) + user = get_object_or_404(User, pk=request.data["id"]) user.totp_key = "" user.save() diff --git a/web/src/components/AdminManager.vue b/web/src/components/AdminManager.vue index bbb9a4ed..8a6c4264 100644 --- a/web/src/components/AdminManager.vue +++ b/web/src/components/AdminManager.vue @@ -80,7 +80,13 @@ @@ -195,24 +191,24 @@ export default { name: "name", label: "Name", field: "name", - align: "left" + align: "left", }, { name: "email", label: "Email", field: "email", - align: "left" + align: "left", }, { name: "last_login", label: "Last Login", field: "last_login", - align: "left" + align: "left", }, ], pagination: { - rowsPerPage: 9999 - } + rowsPerPage: 9999, + }, }; }, methods: { @@ -220,22 +216,22 @@ export default { this.$store.dispatch("admin/loadUsers"); }, clearRow() { - this.selected = [] + this.selected = []; }, refresh() { this.getUsers(); this.clearRow(); }, - deleteUser(id) { + deleteUser(data) { this.$q .dialog({ title: "Delete user?", cancel: true, - ok: { label: "Delete", color: "negative" } + ok: { label: "Delete", color: "negative" }, }) .onOk(() => { this.$store - .dispatch("admin/deleteUser", id) + .dispatch("admin/deleteUser", data.id) .then(response => { this.$q.notify(notifySuccessConfig("User was deleted!")); }) @@ -244,8 +240,8 @@ export default { }); }); }, - showEditUserModal(id) { - this.editUserId = id; + showEditUserModal(data) { + this.editUserId = data.id; this.showUserFormModal = true; }, closeUserFormModal() { @@ -257,12 +253,11 @@ export default { this.showUserFormModal = true; }, toggleEnabled(user) { - let text = user.is_active ? "User enabled successfully" : "User disabled successfully"; const data = { id: user.id, - is_active: user.is_active + is_active: user.is_active, }; this.$store @@ -283,9 +278,8 @@ export default { this.showResetPasswordModal = false; }, reset2FA(user) { - const data = { - id: user.id + id: user.id, }; this.$store @@ -296,15 +290,15 @@ export default { .catch(error => { this.$q.notify(notifyErrorConfig("An Error occured while resetting key")); }); - } + }, }, computed: { ...mapState({ - users: state => state.admin.users - }) + users: state => state.admin.users, + }), }, mounted() { this.refresh(); - } + }, }; \ No newline at end of file diff --git a/web/src/store/admin.js b/web/src/store/admin.js index a431be5b..6b319295 100644 --- a/web/src/store/admin.js +++ b/web/src/store/admin.js @@ -25,16 +25,16 @@ export default { }) }, loadUser(context, pk) { - return axios.get(`/accounts/users/${pk}/`); + return axios.get(`/accounts/${pk}/users/`); }, addUser(context, data) { return axios.post("/accounts/users/", data); }, editUser(context, data) { - return axios.put(`/accounts/users/${data.id}/`, data); + return axios.put(`/accounts/${data.id}/users/`, data); }, deleteUser(context, pk) { - return axios.delete(`/accounts/users/${pk}/`).then(r => { + return axios.delete(`/accounts/${pk}/users/`).then(r => { context.dispatch("loadUsers"); }); },