Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e724194
chore: user store code refactor
anmolsinghbhatia Aug 10, 2024
e1471fe
chore: general unauthorized screen asset added
anmolsinghbhatia Aug 10, 2024
aa73ed1
chore: workspace setting sidebar options updated for guest and viewer
anmolsinghbhatia Aug 10, 2024
1089c2f
chore: NotAuthorizedView component code updated
anmolsinghbhatia Aug 10, 2024
acac14c
chore: project setting layout code refactor
anmolsinghbhatia Aug 10, 2024
0ff7f12
chore: workspace setting members and exports page permission validati…
anmolsinghbhatia Aug 10, 2024
b50ebd3
chore: workspace members and exports settings page improvement
anmolsinghbhatia Aug 10, 2024
8ae4c7c
chore: project invite modal updated
anmolsinghbhatia Aug 12, 2024
d2cf355
chore: workspace setting unauthorized access empty state
anmolsinghbhatia Aug 12, 2024
fa51873
chore: workspace setting unauthorized access empty state
anmolsinghbhatia Aug 12, 2024
f0906ae
chore: project settings sidebar permission updated
anmolsinghbhatia Aug 12, 2024
8818beb
fix: project settings user role permission updated
anmolsinghbhatia Aug 12, 2024
af31302
chore: app sidebar role permission validation updated
anmolsinghbhatia Aug 12, 2024
32e9eb5
chore: app sidebar role permission validation
anmolsinghbhatia Aug 12, 2024
f0242c2
chore: disabled page empty state validation
anmolsinghbhatia Aug 12, 2024
ca47377
chore: app sidebar add project improvement
anmolsinghbhatia Aug 12, 2024
bcf9364
chore: guest role changes
NarayanBavisetti Aug 12, 2024
ec96701
Merge branch 'fix-user-role-permission' of github.com:makeplane/plane…
NarayanBavisetti Aug 12, 2024
2eeeba3
fix: user favorite
anmolsinghbhatia Aug 12, 2024
c03c6f0
chore: changed pages permission
NarayanBavisetti Aug 12, 2024
4260e0e
chore: guest role changes
NarayanBavisetti Aug 13, 2024
c4a1cd4
fix: app sidebar project item permission
anmolsinghbhatia Aug 13, 2024
caef0d8
fix: project setting empty state flicker
anmolsinghbhatia Aug 13, 2024
8ad025e
fix: workspace setting empty state flicker
anmolsinghbhatia Aug 13, 2024
bc35949
chore: granted notification permission to viewer
NarayanBavisetti Aug 14, 2024
7bf6d59
Merge branch 'fix-user-role-permission' of github.com:makeplane/plane…
NarayanBavisetti Aug 14, 2024
50ce413
chore: project invite and edit validation updated
anmolsinghbhatia Aug 14, 2024
4349b5a
chore: favorite validation added for guest and viewer role
anmolsinghbhatia Aug 14, 2024
6c808c4
chore: create view validation updated
anmolsinghbhatia Aug 14, 2024
1e8698c
chore: views permission changes
NarayanBavisetti Aug 14, 2024
2a68a42
Merge branch 'fix-user-role-permission' of github.com:makeplane/plane…
NarayanBavisetti Aug 14, 2024
3151bce
chore: create view empty state validation updated
anmolsinghbhatia Aug 14, 2024
0cdb092
chore: created ENUM for permissions
NarayanBavisetti Aug 14, 2024
05dc43e
Merge branch 'fix-user-role-permission' of github.com:makeplane/plane…
NarayanBavisetti Aug 14, 2024
a91e94a
Merge branch 'preview' into fix-user-role-permission
NarayanBavisetti Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apiserver/plane/app/permissions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
ProjectMemberPermission,
ProjectLitePermission,
)
from .base import allow_permission, ROLE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused imports allow_permission and ROLE.

The imports allow_permission and ROLE from .base are currently unused in this module. Consider removing them or adding them to __all__ if they're intended to be part of the module's public API.

- from .base import allow_permission, ROLE
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from .base import allow_permission, ROLE
Tools
Ruff

15-15: .base.allow_permission imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


15-15: .base.ROLE imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

GitHub Check: Codacy Static Code Analysis

[notice] 15-15: apiserver/plane/app/permissions/init.py#L15
'.base.allow_permission' imported but unused (F401)

61 changes: 61 additions & 0 deletions apiserver/plane/app/permissions/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from plane.db.models import WorkspaceMember, ProjectMember
from functools import wraps
from rest_framework.response import Response
from rest_framework import status

from enum import Enum

class ROLE(Enum):
ADMIN = 20
MEMBER = 15
VIEWER = 10
GUEST = 5


def allow_permission(allowed_roles, level="PROJECT", creator=False, model=None):
def decorator(view_func):
@wraps(view_func)
def _wrapped_view(instance, request, *args, **kwargs):

# Check for creator if required
if creator and model:
obj = model.objects.filter(
id=kwargs["pk"], created_by=request.user
).exists()
if obj:
return view_func(instance, request, *args, **kwargs)

# Convert allowed_roles to their values if they are enum members
allowed_role_values = [
role.value if isinstance(role, ROLE) else role
for role in allowed_roles
]

# Check role permissions
if level == "WORKSPACE":
if WorkspaceMember.objects.filter(
member=request.user,
workspace__slug=kwargs["slug"],
role__in=allowed_role_values,
is_active=True,
).exists():
return view_func(instance, request, *args, **kwargs)
else:
if ProjectMember.objects.filter(
member=request.user,
workspace__slug=kwargs["slug"],
project_id=kwargs["project_id"],
role__in=allowed_role_values,
is_active=True,
).exists():
return view_func(instance, request, *args, **kwargs)

# Return permission denied if no conditions are met
return Response(
{"error": "You don't have the required permissions."},
status=status.HTTP_401_UNAUTHORIZED,
)

return _wrapped_view

return decorator
2 changes: 1 addition & 1 deletion apiserver/plane/app/urls/inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
name="inbox-issue",
),
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/inbox-issues/<uuid:issue_id>/",
"workspaces/<str:slug>/projects/<uuid:project_id>/inbox-issues/<uuid:pk>/",
InboxIssueViewSet.as_view(
{
"get": "retrieve",
Expand Down
34 changes: 16 additions & 18 deletions apiserver/plane/app/views/analytic/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
from rest_framework import status
from rest_framework.response import Response

# Module imports
from plane.app.permissions import WorkSpaceAdminPermission
from plane.app.serializers import AnalyticViewSerializer

# Module imports
from plane.app.views.base import BaseAPIView, BaseViewSet
from plane.bgtasks.analytic_plot_export import analytic_export_task
from plane.db.models import AnalyticView, Issue, Workspace
from plane.utils.analytics_plot import build_graph_plot
from plane.utils.issue_filters import issue_filters
from plane.app.permissions import allow_permission, ROLE


class AnalyticsEndpoint(BaseAPIView):
permission_classes = [
WorkSpaceAdminPermission,
]

@allow_permission(
[ROLE.ADMIN, ROLE.MEMBER, ROLE.VIEWER], level="WORKSPACE"
)
def get(self, request, slug):
x_axis = request.GET.get("x_axis", False)
y_axis = request.GET.get("y_axis", False)
Expand Down Expand Up @@ -201,10 +201,10 @@ def get_queryset(self):


class SavedAnalyticEndpoint(BaseAPIView):
permission_classes = [
WorkSpaceAdminPermission,
]

@allow_permission(
[ROLE.ADMIN, ROLE.MEMBER, ROLE.VIEWER], level="WORKSPACE"
)
def get(self, request, slug, analytic_id):
analytic_view = AnalyticView.objects.get(
pk=analytic_id, workspace__slug=slug
Expand Down Expand Up @@ -234,10 +234,10 @@ def get(self, request, slug, analytic_id):


class ExportAnalyticsEndpoint(BaseAPIView):
permission_classes = [
WorkSpaceAdminPermission,
]

@allow_permission(
[ROLE.ADMIN, ROLE.MEMBER, ROLE.VIEWER], level="WORKSPACE"
)
def post(self, request, slug):
x_axis = request.data.get("x_axis", False)
y_axis = request.data.get("y_axis", False)
Expand Down Expand Up @@ -301,10 +301,10 @@ def post(self, request, slug):


class DefaultAnalyticsEndpoint(BaseAPIView):
permission_classes = [
WorkSpaceAdminPermission,
]

@allow_permission(
[ROLE.ADMIN, ROLE.MEMBER, ROLE.VIEWER, ROLE.GUEST], level="WORKSPACE"
)
def get(self, request, slug):
filters = issue_filters(request.GET, "GET")
base_issues = Issue.issue_objects.filter(
Expand Down Expand Up @@ -380,12 +380,10 @@ def get(self, request, slug):
.order_by("-count")
)

open_estimate_sum = open_issues_queryset.aggregate(
sum=Sum("point")
)["sum"]
total_estimate_sum = base_issues.aggregate(sum=Sum("point"))[
open_estimate_sum = open_issues_queryset.aggregate(sum=Sum("point"))[
"sum"
]
total_estimate_sum = base_issues.aggregate(sum=Sum("point"))["sum"]

return Response(
{
Expand Down
9 changes: 4 additions & 5 deletions apiserver/plane/app/views/cycle/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Third party imports
from rest_framework import status
from rest_framework.response import Response
from plane.app.permissions import ProjectEntityPermission
from plane.app.permissions import allow_permission, ROLE
from plane.db.models import Cycle, UserFavorite, Issue, Label, User, Project
from plane.utils.analytics_plot import burndown_plot

Expand All @@ -34,10 +34,6 @@

class CycleArchiveUnarchiveEndpoint(BaseAPIView):

permission_classes = [
ProjectEntityPermission,
]

def get_queryset(self):
favorite_subquery = UserFavorite.objects.filter(
user=self.request.user,
Expand Down Expand Up @@ -292,6 +288,7 @@ def get_queryset(self):
.distinct()
)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.VIEWER])
def get(self, request, slug, project_id, pk=None):
if pk is None:
queryset = (
Expand Down Expand Up @@ -596,6 +593,7 @@ def get(self, request, slug, project_id, pk=None):
status=status.HTTP_200_OK,
)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def post(self, request, slug, project_id, cycle_id):
cycle = Cycle.objects.get(
pk=cycle_id, project_id=project_id, workspace__slug=slug
Expand All @@ -614,6 +612,7 @@ def post(self, request, slug, project_id, cycle_id):
status=status.HTTP_200_OK,
)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def delete(self, request, slug, project_id, cycle_id):
cycle = Cycle.objects.get(
pk=cycle_id, project_id=project_id, workspace__slug=slug
Expand Down
32 changes: 12 additions & 20 deletions apiserver/plane/app/views/cycle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
from rest_framework import status
from rest_framework.response import Response
from plane.app.permissions import (
ProjectEntityPermission,
ProjectLitePermission,
allow_permission, ROLE
)
from plane.app.serializers import (
CycleSerializer,
Expand Down Expand Up @@ -60,15 +59,6 @@ class CycleViewSet(BaseViewSet):
serializer_class = CycleSerializer
model = Cycle
webhook_event = "cycle"
permission_classes = [
ProjectEntityPermission,
]

def perform_create(self, serializer):
serializer.save(
project_id=self.kwargs.get("project_id"),
owned_by=self.request.user,
)

def get_queryset(self):
favorite_subquery = UserFavorite.objects.filter(
Expand Down Expand Up @@ -325,6 +315,7 @@ def get_queryset(self):
.distinct()
)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.VIEWER, ROLE.GUEST])
def list(self, request, slug, project_id):
queryset = self.get_queryset().filter(archived_at__isnull=True)
cycle_view = request.GET.get("cycle_view", "all")
Expand Down Expand Up @@ -611,6 +602,7 @@ def list(self, request, slug, project_id):
)
return Response(data, status=status.HTTP_200_OK)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def create(self, request, slug, project_id):
if (
request.data.get("start_date", None) is None
Expand Down Expand Up @@ -684,6 +676,7 @@ def create(self, request, slug, project_id):
status=status.HTTP_400_BAD_REQUEST,
)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def partial_update(self, request, slug, project_id, pk):
queryset = self.get_queryset().filter(
workspace__slug=slug, project_id=project_id, pk=pk
Expand Down Expand Up @@ -771,6 +764,7 @@ def partial_update(self, request, slug, project_id, pk):
return Response(cycle, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.VIEWER])
def retrieve(self, request, slug, project_id, pk):
queryset = (
self.get_queryset().filter(archived_at__isnull=True).filter(pk=pk)
Expand Down Expand Up @@ -1039,6 +1033,7 @@ def retrieve(self, request, slug, project_id, pk):
status=status.HTTP_200_OK,
)

@allow_permission([ROLE.ADMIN], creator=True, model=Cycle)
def destroy(self, request, slug, project_id, pk):
cycle = Cycle.objects.get(
workspace__slug=slug, project_id=project_id, pk=pk
Expand Down Expand Up @@ -1097,10 +1092,8 @@ def destroy(self, request, slug, project_id, pk):


class CycleDateCheckEndpoint(BaseAPIView):
permission_classes = [
ProjectEntityPermission,
]

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def post(self, request, slug, project_id):
start_date = request.data.get("start_date", False)
end_date = request.data.get("end_date", False)
Expand Down Expand Up @@ -1144,6 +1137,7 @@ def get_queryset(self):
.select_related("cycle", "cycle__owned_by")
)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def create(self, request, slug, project_id):
_ = UserFavorite.objects.create(
project_id=project_id,
Expand All @@ -1153,6 +1147,7 @@ def create(self, request, slug, project_id):
)
return Response(status=status.HTTP_204_NO_CONTENT)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def destroy(self, request, slug, project_id, cycle_id):
cycle_favorite = UserFavorite.objects.get(
project=project_id,
Expand All @@ -1166,10 +1161,8 @@ def destroy(self, request, slug, project_id, cycle_id):


class TransferCycleIssueEndpoint(BaseAPIView):
permission_classes = [
ProjectEntityPermission,
]

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def post(self, request, slug, project_id, cycle_id):
new_cycle_id = request.data.get("new_cycle_id", False)

Expand Down Expand Up @@ -1579,10 +1572,8 @@ def post(self, request, slug, project_id, cycle_id):


class CycleUserPropertiesEndpoint(BaseAPIView):
permission_classes = [
ProjectLitePermission,
]

@allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.VIEWER, ROLE.GUEST])
def patch(self, request, slug, project_id, cycle_id):
cycle_properties = CycleUserProperties.objects.get(
user=request.user,
Expand All @@ -1605,6 +1596,7 @@ def patch(self, request, slug, project_id, cycle_id):
serializer = CycleUserPropertiesSerializer(cycle_properties)
return Response(serializer.data, status=status.HTTP_201_CREATED)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.VIEWER, ROLE.GUEST])
def get(self, request, slug, project_id, cycle_id):
cycle_properties, _ = CycleUserProperties.objects.get_or_create(
user=request.user,
Expand Down
19 changes: 5 additions & 14 deletions apiserver/plane/app/views/cycle/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@

# Django imports
from django.core import serializers
from django.db.models import (
F,
Func,
OuterRef,
Q,
)
from django.db.models import F, Func, OuterRef, Q
from django.utils import timezone
from django.utils.decorators import method_decorator
from django.views.decorators.gzip import gzip_page
Expand All @@ -17,10 +12,6 @@
from rest_framework import status
from rest_framework.response import Response

from plane.app.permissions import (
ProjectEntityPermission,
)

# Module imports
from .. import BaseViewSet
from plane.app.serializers import (
Expand All @@ -45,6 +36,7 @@
GroupedOffsetPaginator,
SubGroupedOffsetPaginator,
)
from plane.app.permissions import allow_permission, ROLE


class CycleIssueViewSet(BaseViewSet):
Expand All @@ -54,10 +46,6 @@ class CycleIssueViewSet(BaseViewSet):
webhook_event = "cycle_issue"
bulk = True

permission_classes = [
ProjectEntityPermission,
]

filterset_fields = [
"issue__labels__id",
"issue__assignees__id",
Expand Down Expand Up @@ -92,6 +80,7 @@ def get_queryset(self):
)

@method_decorator(gzip_page)
@allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.VIEWER])
def list(self, request, slug, project_id, cycle_id):
order_by_param = request.GET.get("order_by", "created_at")
filters = issue_filters(request.query_params, "GET")
Expand Down Expand Up @@ -238,6 +227,7 @@ def list(self, request, slug, project_id, cycle_id):
),
)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def create(self, request, slug, project_id, cycle_id):
issues = request.data.get("issues", [])

Expand Down Expand Up @@ -333,6 +323,7 @@ def create(self, request, slug, project_id, cycle_id):
)
return Response({"message": "success"}, status=status.HTTP_201_CREATED)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def destroy(self, request, slug, project_id, cycle_id, issue_id):
cycle_issue = CycleIssue.objects.filter(
issue_id=issue_id,
Expand Down
Loading