switch from ownCloud to minIO
buttons in table are buttons and do edit and delete properly
This commit is contained in:
+19
-1
@@ -1,15 +1,20 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.views import LoginView
|
||||
from django.http import HttpResponseForbidden, JsonResponse
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
from django.views.generic import TemplateView, FormView, ListView, UpdateView
|
||||
from rest_framework.generics import get_object_or_404
|
||||
|
||||
from accounts.forms import LoginForm, RegisterForm
|
||||
from accounts.models import DepotUser
|
||||
|
||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||
from django.contrib.auth.mixins import AccessMixin
|
||||
from django.contrib.auth.mixins import AccessMixin, LoginRequiredMixin
|
||||
|
||||
|
||||
# Create your views here.
|
||||
|
||||
|
||||
@@ -165,5 +170,18 @@ class UserUpdateView(UpdateView):
|
||||
|
||||
return form
|
||||
|
||||
class UserActiveView(LoginRequiredMixin, View):
|
||||
success_url = reverse_lazy('user_list')
|
||||
|
||||
def post(self, request, pk, *args, **kwargs):
|
||||
user = request.user
|
||||
if not (user.is_superuser or getattr(user, 'user_type', None) == DepotUser.UserType.COMPANY_ADMIN):
|
||||
return HttpResponseForbidden("You do not have permission to perform this action.")
|
||||
|
||||
target_user = get_object_or_404(get_user_model(), pk=pk)
|
||||
if target_user == user:
|
||||
return HttpResponseForbidden("You cannot change your own active status.")
|
||||
|
||||
target_user.is_active = not target_user.is_active
|
||||
target_user.save()
|
||||
return JsonResponse({'success': True, 'is_active': target_user.is_active})
|
||||
Reference in New Issue
Block a user