feat(src/dashboard/page_views): add board permissions management UI
Introduce views for creating, editing and deleting board role permissions and expose permission data in the project detail context.
This commit is contained in:
3 files changed
+66
-1
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
from .board_permission_views import *
|
||||||
from .epic_views import *
|
from .epic_views import *
|
||||||
from .external_views import *
|
from .external_views import *
|
||||||
from .notification_views import *
|
from .notification_views import *
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
from django.contrib import messages
|
||||||
|
from django.db import IntegrityError
|
||||||
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
|
from django.views.decorators.http import require_http_methods
|
||||||
|
|
||||||
|
from src.projects.models import BoardRolePermission, Project
|
||||||
|
|
||||||
|
|
||||||
|
@require_http_methods(["GET", "POST"])
|
||||||
|
def board_permissions(request, project_id):
|
||||||
|
project = get_object_or_404(Project, pk=project_id)
|
||||||
|
|
||||||
|
if not request.user.is_admin:
|
||||||
|
messages.error(
|
||||||
|
request, "You do not have permission to manage board permissions."
|
||||||
|
)
|
||||||
|
return redirect("project-board-project", project_id=project_id)
|
||||||
|
|
||||||
|
if request.method == "POST":
|
||||||
|
role = request.POST.get("role", "").strip()
|
||||||
|
status_ids = request.POST.getlist("move_to_statuses")
|
||||||
|
|
||||||
|
if role:
|
||||||
|
try:
|
||||||
|
perm, created = BoardRolePermission.objects.update_or_create(
|
||||||
|
project=project,
|
||||||
|
role=role,
|
||||||
|
)
|
||||||
|
perm.move_to_statuses.set(status_ids)
|
||||||
|
messages.success(request, f"Permission saved for role '{role}'.")
|
||||||
|
except IntegrityError:
|
||||||
|
messages.error(request, "This permission already exists.")
|
||||||
|
else:
|
||||||
|
messages.error(request, "Role is required.")
|
||||||
|
|
||||||
|
return redirect("project-board-project", project_id=project_id)
|
||||||
|
|
||||||
|
return redirect("project-board-project", project_id=project_id)
|
||||||
|
|
||||||
|
|
||||||
|
@require_http_methods(["POST"])
|
||||||
|
def board_permission_delete(request, project_id, permission_id):
|
||||||
|
project = get_object_or_404(Project, pk=project_id)
|
||||||
|
|
||||||
|
if not request.user.is_admin:
|
||||||
|
messages.error(
|
||||||
|
request, "You do not have permission to manage board permissions."
|
||||||
|
)
|
||||||
|
return redirect("project-board-project", project_id=project_id)
|
||||||
|
|
||||||
|
permission = get_object_or_404(
|
||||||
|
BoardRolePermission, pk=permission_id, project=project
|
||||||
|
)
|
||||||
|
permission.delete()
|
||||||
|
messages.success(request, "Permission deleted.")
|
||||||
|
|
||||||
|
return redirect("project-board-project", project_id=project_id)
|
||||||
@@ -10,9 +10,11 @@ from django.urls import reverse
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.views.decorators.http import require_http_methods
|
from django.views.decorators.http import require_http_methods
|
||||||
|
|
||||||
|
from src.accounts.models import ADMIN_ROLES
|
||||||
|
from src.accounts.models import User as AccountsUser
|
||||||
from src.epics.models import Epic
|
from src.epics.models import Epic
|
||||||
from src.notes.models import ProjectNote
|
from src.notes.models import ProjectNote
|
||||||
from src.projects.models import Project, ProjectMember
|
from src.projects.models import BoardRolePermission, Project, ProjectMember
|
||||||
from src.tickets.models import (
|
from src.tickets.models import (
|
||||||
Ticket,
|
Ticket,
|
||||||
TicketPriority,
|
TicketPriority,
|
||||||
@@ -291,6 +293,11 @@ def project_detail(request, project_id):
|
|||||||
"today": today,
|
"today": today,
|
||||||
"external_access": external_access,
|
"external_access": external_access,
|
||||||
"is_admin": request.user.is_admin,
|
"is_admin": request.user.is_admin,
|
||||||
|
"permissions": BoardRolePermission.objects.filter(project=project).order_by(
|
||||||
|
"role"
|
||||||
|
),
|
||||||
|
"role_choices": AccountsUser.ROLE_CHOICES,
|
||||||
|
"admin_roles": ADMIN_ROLES,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user