generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement user_permissions model, api, and test (#342)
* Implemented user_permissions model, API, and test * Added rank field to permission_type and modified the initial migration file Note: people who already have the old initial data will need to roll back and re-apply the migration
- Loading branch information
1 parent
edee44d
commit b2398e1
Showing
12 changed files
with
283 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
global_admin = "globalAdmin" | ||
admin_project = "adminProject" | ||
practice_lead_project = "practiceLeadProject" | ||
member_project = "memberProject" | ||
self_value = "self" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
app/core/migrations/0026_permissiontype_rank_alter_permissiontype_name_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Generated by Django 4.2.11 on 2024-08-30 05:51 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("core", "0025_stackelement_delete_technology"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="permissiontype", | ||
name="rank", | ||
field=models.IntegerField(default=0, unique=True), | ||
), | ||
migrations.AlterField( | ||
model_name="permissiontype", | ||
name="name", | ||
field=models.CharField(max_length=255, unique=True), | ||
), | ||
migrations.CreateModel( | ||
name="UserPermission", | ||
fields=[ | ||
( | ||
"uuid", | ||
models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
primary_key=True, | ||
serialize=False, | ||
unique=True, | ||
), | ||
), | ||
( | ||
"created_at", | ||
models.DateTimeField(auto_now_add=True, verbose_name="Created at"), | ||
), | ||
( | ||
"updated_at", | ||
models.DateTimeField(auto_now=True, verbose_name="Updated at"), | ||
), | ||
( | ||
"permission_type", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="core.permissiontype", | ||
), | ||
), | ||
( | ||
"practice_area", | ||
models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="core.practicearea", | ||
), | ||
), | ||
( | ||
"project", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="core.project" | ||
), | ||
), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="permissions", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
migrations.AddConstraint( | ||
model_name="userpermission", | ||
constraint=models.UniqueConstraint( | ||
fields=("user", "permission_type", "project", "practice_area"), | ||
name="unique_user_permission", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0025_stackelement_delete_technology | ||
0026_permissiontype_rank_alter_permissiontype_name_and_more |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import pytest | ||
from rest_framework.test import APIClient | ||
|
||
from constants import admin_project | ||
from constants import practice_lead_project | ||
|
||
from ..models import Affiliate | ||
from ..models import Affiliation | ||
from ..models import CheckType | ||
|
@@ -16,6 +19,75 @@ | |
from ..models import Skill | ||
from ..models import StackElement | ||
from ..models import StackElementType | ||
from ..models import User | ||
from ..models import UserPermission | ||
|
||
|
||
@pytest.fixture | ||
def user_superuser_admin(): | ||
return User.objects.create_user( | ||
username="AdminUser", | ||
email="[email protected]", | ||
password="adminuser", | ||
is_superuser=True, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def user_permissions(): | ||
user1 = User.objects.create(username="TestUser1", email="[email protected]") | ||
user2 = User.objects.create(username="TestUser2", email="[email protected]") | ||
project = Project.objects.create(name="Test Project") | ||
permission_type = PermissionType.objects.first() | ||
practice_area = PracticeArea.objects.first() | ||
user1_permission = UserPermission.objects.create( | ||
user=user1, | ||
permission_type=permission_type, | ||
project=project, | ||
practice_area=practice_area, | ||
) | ||
user2_permissions = UserPermission.objects.create( | ||
user=user2, | ||
project=project, | ||
permission_type=permission_type, | ||
practice_area=practice_area, | ||
) | ||
return [user1_permission, user2_permissions] | ||
|
||
|
||
@pytest.fixture | ||
def user_permission_admin_project(): | ||
user = User.objects.create( | ||
username="TestUser Admin Project", email="[email protected]" | ||
) | ||
project = Project.objects.create(name="Test Project Admin Project") | ||
permission_type = PermissionType.objects.filter(name=admin_project).first() | ||
user_permission = UserPermission.objects.create( | ||
user=user, | ||
permission_type=permission_type, | ||
project=project, | ||
) | ||
|
||
return user_permission | ||
|
||
|
||
@pytest.fixture | ||
def user_permission_practice_lead_project(): | ||
user = User.objects.create( | ||
username="TestUser Practie Lead Project", | ||
email="[email protected]", | ||
) | ||
permission_type = PermissionType.objects.filter(name=practice_lead_project).first() | ||
project = Project.objects.create(name="Test Project Admin Project") | ||
practice_area = PracticeArea.objects.first() | ||
user_permission = UserPermission.objects.create( | ||
user=user, | ||
permission_type=permission_type, | ||
project=project, | ||
practice_area=practice_area, | ||
) | ||
|
||
return user_permission | ||
|
||
|
||
@pytest.fixture | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.