Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/frontend/vite-4.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
robines authored Sep 24, 2024
2 parents 6e3ae32 + cc8f3d2 commit 150380e
Show file tree
Hide file tree
Showing 38 changed files with 1,371 additions and 187 deletions.
55 changes: 55 additions & 0 deletions .github/ISSUE_TEMPLATE/1-feature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 🚀 Feature Request
description: Suggest an idea for this project
title: "[FEATURE] <title>"
labels: ["feature"]
body:
- type: checkboxes
attributes:
label: 👀 Is there an existing feature request for this?
description: Please search to see if a feature request already exists for the feature you are suggesting.
options:
- label: I have searched the existing feature requests
required: true
- type: textarea
attributes:
label: 🌟 Feature statement
description: What is your feature request? Please describe.
placeholder: A clear and concise description of what the feature is.
validations:
required: true
- type: textarea
attributes:
label: 👨‍👩‍👦 Is the feature related to some other issue or PR?
description: Pleas give the isse or PR-number.
placeholder: "#issue-number" or "#PR-number"
validations:
required: false
- type: textarea
attributes:
label: 💡 Proposed Solution
description: Describe the solution you'd like
placeholder: A clear and concise description of what you want to happen.
validations:
required: true
- type: textarea
attributes:
label: 🔦 Additional Context
description: Add any other context or screenshots about the feature request here.
validations:
required: false
- type: textarea
attributes:
label: 🗺️ Where on Samfundet4 do you want the feature?
description: Pleas give a file, or general "area" of Samfundet4
validations:
required: true
- type: dropdown
attributes:
label: Priority
description: How important is this feature to you?
options:
- Nice to have
- Important
- Critical
validations:
required: true
59 changes: 59 additions & 0 deletions .github/ISSUE_TEMPLATE/2-bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: 🐞 Bug
description: File a bug/issue
title: "[BUG] <title>"
labels: ["Bug"]
body:
- type: checkboxes
attributes:
label: 👀 Is there an existing issue for this?
description: Please search to see if an issue already exists for the bug you encountered.
options:
- label: I have searched the existing issues
required: true
- type: textarea
attributes:
label: 🚫 Current Behavior
description: A concise description of what you're experiencing.
validations:
required: true
- type: textarea
attributes:
label: ✅ Expected Behavior
description: A concise description of what you expected to happen.
validations:
required: true
- type: textarea
attributes:
label: 🧩 Steps To Reproduce
description: Steps to reproduce the behavior.
placeholder: |
1. In this environment...
1. With this config...
1. Run '...'
1. See error...
validations:
required: true
- type: textarea
attributes:
label: 🐼 Environment
description: |
examples:
- **OS**: Ubuntu 20.04
- **Node**: 13.14.0
- **npm**: 7.6.3
value: |
- OS:
- Node:
- npm:
render: markdown
validations:
required: false
- type: textarea
attributes:
label: 🦮 Anything else?
description: |
Links? References? Anything that will give us more context about the issue you are encountering!
Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
validations:
required: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Technologies used on Samf4 🤖](/docs/technical/Samf4Tech.md)
- [Project Specific Commands](/docs/docker-project-specific-commands.md)
- [Useful Docker aliases](/docs/docker-project-specific-commands.md)
- [🌐 API documentation](/docs/api-docs.md)

## Installation

Expand Down
2 changes: 1 addition & 1 deletion backend/aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ alias poetry-run-migrations-apply='poetry run python manage.py migrate' # Apply
alias poetry-run-collectstatic='poetry run python manage.py collectstatic --noinput' # Collect static files from apps to root of project.

alias poetry-run-pytest-run='poetry run pytest' # Run pytest on project.
alias poetry-run-pipeline='poetry-mypy-run && poetry-ruff-check && poetry-ruff-format-check && poetry-migrations-verify && poetry-pytest-run' # Run all checks in pipeline.
alias poetry-run-pipeline='poetry-run-mypy-run && poetry-run-ruff-check && poetry-run-ruff-format-check && poetry-run-migrations-verify && poetry-run-pytest-run' # Run all checks in pipeline.
alias poetry-run-seed='poetry run python manage.py seed' # Apply seed of database.
297 changes: 263 additions & 34 deletions backend/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ debugpy = "1.*"
requests = "2.*"
pytest = "8.*"
pytest-django = "4.*"
drf-spectacular = "0.27.*"

[build-system]
requires = ["poetry-core"]
Expand Down
11 changes: 11 additions & 0 deletions backend/root/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
'corsheaders',
'root', # Register to enable management.commands.
'samfundet',
'drf_spectacular',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -129,6 +130,7 @@

AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend', # default
'samfundet.backend.RoleAuthBackend',
]

# Password validation
Expand Down Expand Up @@ -177,9 +179,18 @@
'root.custom_classes.permission_classes.SuperUserPermission',
# 'root.custom_classes.permission_classes.CustomDjangoObjectPermissions',
],
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}
### End: DRF ###

SPECTACULAR_SETTINGS = {
'TITLE': 'Samfundet4 API',
'DESCRIPTION': 'Samfundet4 is the new webpage of Studentersamfundet in Trondhjem',
'VERSION': '1.0.0',
'SERVE_INCLUDE_SCHEMA': False,
# OTHER SETTINGS
}

### django-guardian ###
INSTALLED_APPS += [
'guardian',
Expand Down
20 changes: 20 additions & 0 deletions backend/root/utils/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@
SAMFUNDET_DELETE_RESERVATION = 'samfundet.delete_reservation'
SAMFUNDET_VIEW_RESERVATION = 'samfundet.view_reservation'

SAMFUNDET_ADD_ROLE = 'samfundet.add_role'
SAMFUNDET_CHANGE_ROLE = 'samfundet.change_role'
SAMFUNDET_DELETE_ROLE = 'samfundet.delete_role'
SAMFUNDET_VIEW_ROLE = 'samfundet.view_role'

SAMFUNDET_ADD_SAKSDOKUMENT = 'samfundet.add_saksdokument'
SAMFUNDET_CHANGE_SAKSDOKUMENT = 'samfundet.change_saksdokument'
SAMFUNDET_DELETE_SAKSDOKUMENT = 'samfundet.delete_saksdokument'
Expand Down Expand Up @@ -310,6 +315,21 @@
SAMFUNDET_DELETE_USERFEEDBACKMODEL = 'samfundet.delete_userfeedbackmodel'
SAMFUNDET_VIEW_USERFEEDBACKMODEL = 'samfundet.view_userfeedbackmodel'

SAMFUNDET_ADD_USERGANGROLE = 'samfundet.add_usergangrole'
SAMFUNDET_CHANGE_USERGANGROLE = 'samfundet.change_usergangrole'
SAMFUNDET_DELETE_USERGANGROLE = 'samfundet.delete_usergangrole'
SAMFUNDET_VIEW_USERGANGROLE = 'samfundet.view_usergangrole'

SAMFUNDET_ADD_USERGANGSECTIONROLE = 'samfundet.add_usergangsectionrole'
SAMFUNDET_CHANGE_USERGANGSECTIONROLE = 'samfundet.change_usergangsectionrole'
SAMFUNDET_DELETE_USERGANGSECTIONROLE = 'samfundet.delete_usergangsectionrole'
SAMFUNDET_VIEW_USERGANGSECTIONROLE = 'samfundet.view_usergangsectionrole'

SAMFUNDET_ADD_USERORGROLE = 'samfundet.add_userorgrole'
SAMFUNDET_CHANGE_USERORGROLE = 'samfundet.change_userorgrole'
SAMFUNDET_DELETE_USERORGROLE = 'samfundet.delete_userorgrole'
SAMFUNDET_VIEW_USERORGROLE = 'samfundet.view_userorgrole'

SAMFUNDET_ADD_USERPREFERENCE = 'samfundet.add_userpreference'
SAMFUNDET_CHANGE_USERPREFERENCE = 'samfundet.change_userpreference'
SAMFUNDET_DELETE_USERPREFERENCE = 'samfundet.delete_userpreference'
Expand Down
24 changes: 24 additions & 0 deletions backend/root/utils/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@
admin__auth_group_delete = 'admin:auth_group_delete'
admin__auth_group_change = 'admin:auth_group_change'
adminauthgroup__objectId = ''
admin__samfundet_role_changelist = 'admin:samfundet_role_changelist'
admin__samfundet_role_add = 'admin:samfundet_role_add'
admin__samfundet_role_history = 'admin:samfundet_role_history'
admin__samfundet_role_delete = 'admin:samfundet_role_delete'
admin__samfundet_role_change = 'admin:samfundet_role_change'
adminsamfundetrole__objectId = ''
admin__samfundet_userorgrole_changelist = 'admin:samfundet_userorgrole_changelist'
admin__samfundet_userorgrole_add = 'admin:samfundet_userorgrole_add'
admin__samfundet_userorgrole_history = 'admin:samfundet_userorgrole_history'
admin__samfundet_userorgrole_delete = 'admin:samfundet_userorgrole_delete'
admin__samfundet_userorgrole_change = 'admin:samfundet_userorgrole_change'
adminsamfundetuserorgrole__objectId = ''
admin__samfundet_usergangrole_changelist = 'admin:samfundet_usergangrole_changelist'
admin__samfundet_usergangrole_add = 'admin:samfundet_usergangrole_add'
admin__samfundet_usergangrole_history = 'admin:samfundet_usergangrole_history'
admin__samfundet_usergangrole_delete = 'admin:samfundet_usergangrole_delete'
admin__samfundet_usergangrole_change = 'admin:samfundet_usergangrole_change'
adminsamfundetusergangrole__objectId = ''
admin__samfundet_usergangsectionrole_changelist = 'admin:samfundet_usergangsectionrole_changelist'
admin__samfundet_usergangsectionrole_add = 'admin:samfundet_usergangsectionrole_add'
admin__samfundet_usergangsectionrole_history = 'admin:samfundet_usergangsectionrole_history'
admin__samfundet_usergangsectionrole_delete = 'admin:samfundet_usergangsectionrole_delete'
admin__samfundet_usergangsectionrole_change = 'admin:samfundet_usergangsectionrole_change'
adminsamfundetusergangsectionrole__objectId = ''
admin__auth_permission_permissions = 'admin:auth_permission_permissions'
admin__auth_permission_permissions_manage_user = 'admin:auth_permission_permissions_manage_user'
admin__auth_permission_permissions_manage_group = 'admin:auth_permission_permissions_manage_group'
Expand Down
22 changes: 22 additions & 0 deletions backend/samfundet/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CustomGuardedModelAdmin,
)

from .models.role import Role, UserOrgRole, UserGangRole, UserGangSectionRole
from .models.event import Event, EventGroup, EventRegistration, PurchaseFeedbackModel
from .models.general import (
Tag,
Expand Down Expand Up @@ -161,6 +162,27 @@ def members(self, obj: Group) -> int:
return n


@admin.register(Role)
class RoleAdmin(admin.ModelAdmin):
list_display = ('name',)
filter_horizontal = ['permissions']


@admin.register(UserOrgRole)
class UserOrgRoleAdmin(admin.ModelAdmin):
list_display = ('user', 'role', 'obj')


@admin.register(UserGangRole)
class UserGangRoleAdmin(admin.ModelAdmin):
list_display = ('user', 'role', 'obj')


@admin.register(UserGangSectionRole)
class UserGangSectionRoleAdmin(admin.ModelAdmin):
list_display = ('user', 'role', 'obj')


@admin.register(Permission)
class PermissionAdmin(CustomGuardedModelAdmin):
# ordering = []
Expand Down
37 changes: 37 additions & 0 deletions backend/samfundet/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

from typing import Any

from django.contrib.auth.backends import BaseBackend

from samfundet.utils import get_perm
from samfundet.models import User
from samfundet.models.role import UserOrgRole, UserGangRole, UserGangSectionRole


class RoleAuthBackend(BaseBackend):
def has_perm(self, user_obj: User, perm: str, obj: Any = None) -> bool: # noqa: C901
if not user_obj.is_active or obj is None:
return False

if user_obj.is_superuser:
return True

permission = get_perm(perm=perm, model=obj)

if hasattr(obj, 'resolve_org'):
org_id = obj.resolve_org(return_id=True)
if org_id is not None and UserOrgRole.objects.filter(user=user_obj, obj__id=org_id, role__permissions=permission).exists():
return True

if hasattr(obj, 'resolve_gang'):
gang_id = obj.resolve_gang(return_id=True)
if gang_id is not None and UserGangRole.objects.filter(user=user_obj, obj__id=gang_id, role__permissions=permission).exists():
return True

if hasattr(obj, 'resolve_section'):
section_id = obj.resolve_section(return_id=True)
if section_id is not None and UserGangSectionRole.objects.filter(user=user_obj, obj__id=section_id, role__permissions=permission).exists():
return True

return False
Loading

0 comments on commit 150380e

Please sign in to comment.