Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: merge AppP and ModC body roles #517

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions community/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUp(self):
self.test_body_2 = create_body()

self.body_1_role = BodyRole.objects.create(
name="Body1Role", body=self.test_body_1, permissions="AppP,ModC"
name="Body1Role", body=self.test_body_1, permissions="ModC"
)
self.user1.profile.roles.add(self.body_1_role)

Expand Down Expand Up @@ -89,7 +89,9 @@ def test_communitypost_yourlist(self):
self.assertEqual(
response.data["count"],
CommunityPost.objects.filter(
thread_rank=1, posted_by=self.user1.profile, community=self.test_community_1
thread_rank=1,
posted_by=self.user1.profile,
community=self.test_community_1,
).count(),
)
self.assertListEqual(
Expand Down
13 changes: 5 additions & 8 deletions community/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ def change_status(self, request, pk):
post = self.get_community_post(pk)

if (
user_has_privilege(request.user.profile, post.community.body.id, "AppP")
and post.thread_rank == 1
) or (
user_has_privilege(request.user.profile, post.community.body.id, "ModC")
and post.thread_rank > 1
and post.thread_rank > 0
):
# Get query param
status = request.data["status"]
Expand Down Expand Up @@ -72,7 +69,7 @@ def retrieve_full(self, request, pk):
)
post = self.get_community_post(pk)
return_for_mod = False
if user_has_privilege(request.user.profile, post.community.body.id, "AppP"):
if user_has_privilege(request.user.profile, post.community.body.id, "ModC"):
return_for_mod = True
serialized = CommunityPostSerializers(
post, context={"return_for_mod": return_for_mod}
Expand Down Expand Up @@ -112,7 +109,7 @@ def list(self, request):
queryset = query_search(request, 3, queryset, ["content"], "posts")
queryset = query_from_num(request, 20, queryset)
return_for_mod = False
if user_has_privilege(request.user.profile, community.body.id, "AppP"):
if user_has_privilege(request.user.profile, community.body.id, "ModC"):
return_for_mod = True

serializer = CommunityPostSerializerMin(
Expand Down Expand Up @@ -153,7 +150,7 @@ def perform_action(self, request, action, pk):
if all(
[
user_has_privilege(
request.user.profile, post.community.body.id, "AppP"
request.user.profile, post.community.body.id, "ModC"
)
]
):
Expand Down Expand Up @@ -184,7 +181,7 @@ def perform_action(self, request, action, pk):
if all(
[
user_has_privilege(
request.user.profile, post.community.body.id, "AppP"
request.user.profile, post.community.body.id, "ModC"
)
]
):
Expand Down
2 changes: 1 addition & 1 deletion other/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def notify_new_commpostadmin(pk):
roles = instance.community.body.roles.all()
users = []
for role in roles:
if "AppP" in role.permissions:
if "ModC" in role.permissions:
users.extend(map(lambda user: user.user, role.users.all()))
print(users)
notify.send(
Expand Down
40 changes: 40 additions & 0 deletions roles/migrations/0022_alter_bodyrole_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 3.2.16 on 2023-12-16 12:02

from django.db import migrations
import multiselectfield.db.fields


def migrate_AppP_role_to_ModC_role(apps, schema_editor):
BodyRole = apps.get_model("roles", "BodyRole")

for obj in BodyRole.objects.filter(permissions__contains="AppP"):
obj.permissions.remove("AppP")
if "ModC" not in obj.permissions:
obj.permissions.append("ModC")
obj.save()


class Migration(migrations.Migration):
dependencies = [
("roles", "0021_delete_communityrole"),
]

operations = [
migrations.AlterField(
model_name="bodyrole",
name="permissions",
field=multiselectfield.db.fields.MultiSelectField(
choices=[
("AddE", "Add Event"),
("UpdE", "Update Event"),
("DelE", "Delete Event"),
("UpdB", "Update Body"),
("Role", "Modify Roles"),
("VerA", "Verify Achievements"),
("ModC", "Moderate Community"),
],
max_length=34,
),
),
migrations.RunPython(migrate_AppP_role_to_ModC_role),
]
3 changes: 1 addition & 2 deletions roles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
("UpdB", "Update Body"),
("Role", "Modify Roles"),
("VerA", "Verify Achievements"),
("AppP", "Moderate Post"),
("ModC", "Moderate Comment"),
("ModC", "Moderate Community"),
)


Expand Down
Loading