-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Project-User Management and Accessibility (#275)
* Initial support for project owners * Added projects<->users many-to-many relationship * Auto-assign user as project owner when the user creates a project * Exposed current user's projects via users/me/ endpoint * Allowed add users to a project through the admin page * Added tests for project owner auto-assignment & user's project * fix: made the select user field optional & hide the project' users field in project list view * fix: show projects that a user is added to * Added public query parameter to filter current user's projects for /projects endpoint * feat: update project overview to handle user projects * style: move create button to header * Renamed users field to members and made it optional * Use user_id param for project filtering * Update the frontend to filter projects by user_id * Add project creator to members if they are not already a member * Added project model manager * Removed user projects from /me endpoint * Updated /projects user_id filter to just check if the filtering is for the current logged in user * Moved the logic for adding project owner to members to Project.save * feat: include selected view as query param * fix : add project owner to members when the project is created from admin page * Squashed migrations * Deleted old migration files * feat: function for ensuring the owner is a member --------- Co-authored-by: mohamedelabbas1996 <[email protected]> (primary author) Co-authored-by: Anna Viklund <[email protected]>
- Loading branch information
Showing
10 changed files
with
187 additions
and
16 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
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
39 changes: 39 additions & 0 deletions
39
ami/main/migrations/0039_project_users_squashed_0043_rename_users_project_members.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,39 @@ | ||
# Generated by Django 4.2.10 on 2025-01-23 10:37 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
replaces = [ | ||
("main", "0039_project_users"), | ||
("main", "0007_project_owner"), | ||
("main", "0040_merge_0007_project_owner_0039_project_users"), | ||
("main", "0041_alter_project_users"), | ||
("main", "0042_alter_project_users"), | ||
("main", "0043_rename_users_project_members"), | ||
] | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("main", "0038_alter_detection_path_alter_sourceimage_event_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="project", | ||
name="owner", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
related_name="projects", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="project", | ||
name="members", | ||
field=models.ManyToManyField(blank=True, related_name="user_projects", to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
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 |
---|---|---|
|
@@ -882,3 +882,25 @@ def test_project_devices(self): | |
exepcted_device_ids = {device.id for device in Device.objects.filter(project=project)} | ||
response_device_ids = {device.get("id") for device in response_data["results"]} | ||
self.assertEqual(response_device_ids, exepcted_device_ids) | ||
|
||
|
||
class TestProjectOwnerAutoAssignment(APITestCase): | ||
def setUp(self) -> None: | ||
self.user_1 = User.objects.create_user( | ||
email="[email protected]", | ||
is_staff=True, | ||
) | ||
self.user_2 = User.objects.create_user( | ||
email="[email protected]", | ||
is_staff=True, | ||
) | ||
self.factory = APIRequestFactory() | ||
self.client.force_authenticate(user=self.user_1) | ||
return super().setUp() | ||
|
||
def test_can_auto_assign_project_owner(self): | ||
project_endpoint = "/api/v2/projects/" | ||
request = {"name": "Test Project1234", "description": "Test Description"} | ||
self.client.post(project_endpoint, request) | ||
project = Project.objects.filter(name=request["name"]).first() | ||
self.assertEqual(self.user_1.id, project.owner.id) |
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 |
---|---|---|
|
@@ -79,7 +79,6 @@ export const Gallery = ({ | |
/> | ||
)) | ||
)} | ||
|
||
{!isLoading && items.length === 0 && <EmptyState />} | ||
</div> | ||
) | ||
|
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