Skip to content

Commit

Permalink
Merge pull request #1818 from MZaFaRM:dev
Browse files Browse the repository at this point in the history
[PATCH] Some minor patches
  • Loading branch information
MZaFaRM authored Dec 13, 2023
2 parents 356c159 + 0060e3e commit 8b04426
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 107 deletions.
2 changes: 1 addition & 1 deletion api/dashboard/lc/dash_lc_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def get_interest_group(self, obj):
return obj.values('ig_id').distinct().count()

def get_total_no_of_users(self, obj):
return UserCircleLink.objects.all().count()
return UserCircleLink.objects.filter(accepted=True).count()

def get_learning_circle(self, obj):
return obj.count()
Expand Down
48 changes: 27 additions & 21 deletions api/dashboard/roles/dash_roles_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ def put(self, request, role_id):
return CustomResponse(response=serialized_users.data).get_success_response()

@role_required([RoleType.ADMIN.value])
def patch(self, request):
def post(self, request, role_id):
"""
Assigns a large bunch of users a certain role
"""
request_data = request.data.copy()
request_data["role"] = role_id
request_data["created_by"] = JWTUtils.fetch_user_id(request)
serialized_users = dash_roles_serializer.RoleAssignmentSerializer(
data=request_data
Expand All @@ -214,31 +215,34 @@ def patch(self, request):
return CustomResponse(response=serialized_users.errors).get_failure_response()

@role_required([RoleType.ADMIN.value])
def delete(self, request):
def patch(self, request, role_id):
"""
Removes a role from a large bunch of users
"""
role = Role.objects.get(pk=request.data.get("role"))
user_role_links = UserRoleLink.objects.filter(
user__pk__in=request.data.get("users"),
role=role,
)
number = user_role_links.count()
try:
role = Role.objects.get(pk=role_id)
user_role_links = UserRoleLink.objects.filter(
user__pk__in=request.data.get("users"),
role=role,
)
number = user_role_links.count()

DiscordWebhooks.general_updates(
WebHookCategory.BULK_ROLE.value,
WebHookActions.DELETE.value,
role.title,
",".join(list(user_role_links.values_list("user_id", flat=True))),
)
DiscordWebhooks.general_updates(
WebHookCategory.BULK_ROLE.value,
WebHookActions.DELETE.value,
role.title,
",".join(list(user_role_links.values_list("user_id", flat=True))),
)

user_role_links.delete()
user_role_links.delete()

return CustomResponse(
general_message=(
f"Successfully removed the '{role.title}' role from {number} users"
)
).get_success_response()
return CustomResponse(
general_message=(
f"Successfully removed the '{role.title}' role from {number} users"
)
).get_success_response()
except Role.DoesNotExist as e:
return CustomResponse(general_message=str(e)).get_failure_response()


class UserRole(APIView):
Expand Down Expand Up @@ -425,7 +429,9 @@ def post(self, request):
row["created_by_id"] = request_user_id
valid_rows.append(row)

users_by_role = {role_title: users for role_title, users in users_by_role.items() if users}
users_by_role = {
role_title: users for role_title, users in users_by_role.items() if users
}
user_roles_serializer = dash_roles_serializer.UserRoleBulkAssignSerializer(
data=valid_rows, many=True
)
Expand Down
21 changes: 11 additions & 10 deletions db/hackathon.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.db import models

from db.organization import Organization, District
from db.organization import District, Organization
from db.user import User
from decouple import config as decouple_config

from .helper import get_system_admin_id

# fmt: off
# noinspection PyPep8
Expand All @@ -26,9 +27,9 @@ class Hackathon(models.Model):
event_start = models.DateTimeField(blank=True, null=True)
event_end = models.DateTimeField(blank=True, null=True)
status = models.CharField(max_length=20, blank=True, null=True)
updated_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column='updated_by', related_name='hackathon_updated_by')
updated_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column='updated_by', related_name='hackathon_updated_by')
updated_at = models.DateTimeField(auto_now=True)
created_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column='created_by', related_name='hackathon_created_by')
created_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column='created_by', related_name='hackathon_created_by')
created_at = models.DateTimeField(auto_now_add=True)

class Meta:
Expand All @@ -42,9 +43,9 @@ class HackathonForm(models.Model):
field_name = models.CharField(max_length=255)
field_type = models.CharField(max_length=50)
is_required = models.BooleanField(default=False)
updated_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column='updated_by', related_name='hackathon_form_updated_by')
updated_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column='updated_by', related_name='hackathon_form_updated_by')
updated_at = models.DateTimeField(auto_now=True)
created_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column='created_by', related_name='hackathon_form_created_by')
created_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column='created_by', related_name='hackathon_form_created_by')
created_at = models.DateTimeField(auto_now_add=True)

class Meta:
Expand All @@ -56,9 +57,9 @@ class HackathonOrganiserLink(models.Model):
id = models.CharField(primary_key=True, max_length=36)
organiser = models.ForeignKey(User, on_delete=models.CASCADE)
hackathon = models.ForeignKey(Hackathon, on_delete=models.CASCADE)
updated_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column='updated_by', related_name='hackathon_organiser_link_updated_by')
updated_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column='updated_by', related_name='hackathon_organiser_link_updated_by')
updated_at = models.DateTimeField(auto_now=True)
created_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column='created_by', related_name='hackathon_organiser_link_created_by')
created_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column='created_by', related_name='hackathon_organiser_link_created_by')
created_at = models.DateTimeField(auto_now_add=True)

class Meta:
Expand All @@ -70,9 +71,9 @@ class HackathonUserSubmission(models.Model):
id = models.CharField(primary_key=True, max_length=36)
user = models.ForeignKey(User, on_delete=models.CASCADE)
hackathon = models.ForeignKey(Hackathon, on_delete=models.CASCADE)
updated_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column='updated_by', related_name='hackathon_submission_updated_by')
updated_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column='updated_by', related_name='hackathon_submission_updated_by')
updated_at = models.DateTimeField(auto_now=True)
created_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column='created_by', related_name='hackathon_submission_created_by')
created_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column='created_by', related_name='hackathon_submission_created_by')
created_at = models.DateTimeField(auto_now_add=True)
data = models.JSONField(max_length=2000, blank=True, null=True)

Expand Down
6 changes: 6 additions & 0 deletions db/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from decouple import config


def get_system_admin_id():
from db.user import User
return User.objects.get(pk=config("SYSTEM_ADMIN_ID"))
5 changes: 3 additions & 2 deletions db/integrations.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import uuid

from decouple import config as decouple_config
from django.db import models

from db.user import User

from .helper import get_system_admin_id

# fmt: off
# noinspection PyPep8

Expand All @@ -21,7 +22,7 @@ class Meta:
db_table = "integration"


#

class IntegrationAuthorization(models.Model):
id = models.CharField(max_length=36, primary_key=True, default=uuid.uuid4)
integration = models.ForeignKey(Integration, on_delete=models.CASCADE, null=False, related_name="integration_authorization_integration",)
Expand Down
10 changes: 5 additions & 5 deletions db/learning_circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from db.task import InterestGroup, Organization
from db.user import User
from decouple import config as decouple_config

from .helper import get_system_admin_id

# fmt: off
# noinspection PyPep8
Expand All @@ -22,10 +22,10 @@ class LearningCircle(models.Model):
meet_time = models.CharField(max_length=10, blank=True, null=True)
day = models.CharField(max_length=20, blank=True, null=True)
note = models.CharField(max_length=500, blank=True, null=True)
updated_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column="updated_by",
updated_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column="updated_by",
related_name="learning_circle_updated_by")
updated_at = models.DateTimeField(auto_now=True)
created_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column="created_by",
created_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column="created_by",
related_name="learning_circle_created_by")
created_at = models.DateTimeField(auto_now=True)

Expand Down Expand Up @@ -59,10 +59,10 @@ class CircleMeetingLog(models.Model):
attendees = models.CharField(max_length=216)
agenda = models.CharField(max_length=2000)
images = models.ImageField(max_length=200, upload_to='lc/meet-report')
created_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column='created_by',
created_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column='created_by',
related_name='circle_meeting_log_created_by')
created_at = models.DateTimeField(auto_now=True)
updated_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column='updated_by',
updated_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column='updated_by',
related_name='circle_meeting_log_updated_by')
updated_at = models.DateTimeField(auto_now=True)

Expand Down
5 changes: 3 additions & 2 deletions db/notification.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import uuid

from decouple import config as decouple_config
from django.db import models

from db.user import User

from .helper import get_system_admin_id

# fmt: off
# noinspection PyPep8

Expand All @@ -16,7 +17,7 @@ class Notification(models.Model):
button = models.CharField(max_length=10, blank=True, null=True)
url = models.CharField(max_length=100, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
created_by = models.ForeignKey(User, on_delete=models.SET(decouple_config("SYSTEM_ADMIN_ID")), db_column="created_by", related_name="created_notifications")
created_by = models.ForeignKey(User, on_delete=models.SET(get_system_admin_id), db_column="created_by", related_name="created_notifications")

class Meta:
managed = False
Expand Down
Loading

0 comments on commit 8b04426

Please sign in to comment.