From a3efe27f2cf8431e5bc2f83877942dc11f527efb Mon Sep 17 00:00:00 2001 From: jelanmathewjames Date: Thu, 7 Dec 2023 23:01:46 +0530 Subject: [PATCH 1/4] Remove code for adding karma log entry on negative karma --- api/dashboard/profile/profile_serializer.py | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/api/dashboard/profile/profile_serializer.py b/api/dashboard/profile/profile_serializer.py index 50dc8b8d..c46c01f7 100644 --- a/api/dashboard/profile/profile_serializer.py +++ b/api/dashboard/profile/profile_serializer.py @@ -374,17 +374,18 @@ def update(self, instance, validated_data): def create_karma_activity_log(task_title, karma_value): task = TaskList.objects.filter(title=task_title).first() if task: - KarmaActivityLog.objects.create( - task_id=task.id, - karma=karma_value, - user_id=user_id, - updated_by_id=user_id, - created_by_id=user_id, - peer_approved=True, - peer_approved_by_id=user_id, - appraiser_approved_by_id=user_id, - appraiser_approved=True, - ) + if karma_value > 0: + KarmaActivityLog.objects.create( + task_id=task.id, + karma=karma_value, + user_id=user_id, + updated_by_id=user_id, + created_by_id=user_id, + peer_approved=True, + peer_approved_by_id=user_id, + appraiser_approved_by_id=user_id, + appraiser_approved=True, + ) Wallet.objects.filter(user_id=user_id).update( karma=F("karma") + karma_value, updated_by_id=user_id From 34bffb285ba4ff993e6a93766255b106a6e44d64 Mon Sep 17 00:00:00 2001 From: Adnan Kattekaden Date: Fri, 8 Dec 2023 21:27:41 +0530 Subject: [PATCH 2/4] events edit --- api/dashboard/events/events_serializer.py | 6 ++++-- api/dashboard/events/events_views.py | 13 +++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/api/dashboard/events/events_serializer.py b/api/dashboard/events/events_serializer.py index 6220693f..469207f7 100644 --- a/api/dashboard/events/events_serializer.py +++ b/api/dashboard/events/events_serializer.py @@ -12,6 +12,7 @@ class Meta: model = Events fields = "__all__" + class EventsCUDSerializer(serializers.ModelSerializer): class Meta: model = Events @@ -29,8 +30,9 @@ def update(self, instance, validated_data): user_id = self.context.get("user_id") instance.name = validated_data.get("name", instance.name) + instance.description = validated_data.get("description", instance.description) instance.updated_by_id = user_id instance.updated_at = DateTimeUtils.get_current_utc_time() instance.save() - - return instance \ No newline at end of file + + return instance diff --git a/api/dashboard/events/events_views.py b/api/dashboard/events/events_views.py index bf34a4d0..483acfb3 100644 --- a/api/dashboard/events/events_views.py +++ b/api/dashboard/events/events_views.py @@ -1,10 +1,10 @@ from rest_framework.views import APIView -from utils.permission import CustomizePermission, JWTUtils, role_required + +from db.task import Events +from utils.permission import CustomizePermission, JWTUtils from utils.response import CustomResponse -from utils.types import RoleType from utils.utils import CommonUtils from .events_serializer import EventsCUDSerializer, EventsListSerializer -from db.task import Events class EventAPI(APIView): @@ -30,7 +30,6 @@ def get(self, request): ) ) - def post(self, request): user_id = JWTUtils.fetch_user_id(request) @@ -52,7 +51,6 @@ def post(self, request): return CustomResponse( general_message=serializer.errors, ).get_failure_response() - def put(self, request, event_id): user_id = JWTUtils.fetch_user_id(request) @@ -80,10 +78,9 @@ def put(self, request, event_id): return CustomResponse( message=serializer.errors ).get_failure_response() - def delete(self, request, event_id): - + events = Events.objects.filter(id=event_id).first() if events is None: @@ -95,4 +92,4 @@ def delete(self, request, event_id): return CustomResponse( general_message=f"{events.name} Deleted Successfully" - ).get_success_response() \ No newline at end of file + ).get_success_response() From b8bd33d51eda598fb42bc9d2bac92e085b821700 Mon Sep 17 00:00:00 2001 From: jelanmathewjames Date: Fri, 8 Dec 2023 23:58:23 +0530 Subject: [PATCH 3/4] [FEAT] inform updation of karma through discord on social update --- api/dashboard/profile/profile_serializer.py | 60 ++++++++++++++------- utils/types.py | 1 + 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/api/dashboard/profile/profile_serializer.py b/api/dashboard/profile/profile_serializer.py index c46c01f7..919d778e 100644 --- a/api/dashboard/profile/profile_serializer.py +++ b/api/dashboard/profile/profile_serializer.py @@ -12,8 +12,8 @@ from db.user import User, UserSettings, Socials from utils.exception import CustomException from utils.permission import JWTUtils -from utils.types import OrganizationType, RoleType, MainRoles -from utils.utils import DateTimeUtils +from utils.types import OrganizationType, RoleType, MainRoles, WebHookActions, WebHookCategory +from utils.utils import DateTimeUtils, DiscordWebhooks BE_DOMAIN_NAME = decouple_config('BE_DOMAIN_NAME') @@ -35,8 +35,10 @@ class Meta: class UserProfileSerializer(serializers.ModelSerializer): joined = serializers.DateTimeField(source="created_at") - level = serializers.CharField(source="user_lvl_link_user.level.name", default=None) - is_public = serializers.BooleanField(source="user_settings_user.is_public", default=None) + level = serializers.CharField( + source="user_lvl_link_user.level.name", default=None) + is_public = serializers.BooleanField( + source="user_settings_user.is_public", default=None) karma = serializers.IntegerField(source="wallet_user.karma", default=None) roles = serializers.SerializerMethodField() college_id = serializers.SerializerMethodField() @@ -72,7 +74,8 @@ class Meta: def get_percentile(self, obj): try: - user_count = Wallet.objects.filter(karma__lt=obj.wallet_user.karma).count() + user_count = Wallet.objects.filter( + karma__lt=obj.wallet_user.karma).count() usr_count = User.objects.all().count() return 0 if usr_count == 0 else (user_count * 100) / usr_count except Exception as e: @@ -95,7 +98,8 @@ def get_college_id(self, obj): def get_org_district_id(self, obj): org_type = OrganizationType.COMPANY.value if MainRoles.MENTOR.value in self.get_roles( obj) else OrganizationType.COLLEGE.value - user_org_link = obj.user_organization_link_user.filter(org__org_type=org_type).first() + user_org_link = obj.user_organization_link_user.filter( + org__org_type=org_type).first() return user_org_link.org.district.id if user_org_link and hasattr(user_org_link.org, 'district') else None def get_college_code(self, obj): @@ -125,7 +129,8 @@ def get_rank(self, obj): ranks = ( Wallet.objects.filter(karma__gte=user_karma) .exclude( - Q(user__user_role_link_user__role__title__in=[RoleType.ENABLER.value, RoleType.MENTOR.value]) + Q(user__user_role_link_user__role__title__in=[ + RoleType.ENABLER.value, RoleType.MENTOR.value]) ).order_by('-karma') ) @@ -149,14 +154,14 @@ def get_interest_groups(self, obj): if KarmaActivityLog.objects.filter( task__ig=ig_link.ig, user=obj, appraiser_approved=True ) - .aggregate(Sum("karma")) - .get("karma__sum") - is None + .aggregate(Sum("karma")) + .get("karma__sum") + is None else KarmaActivityLog.objects.filter( task__ig=ig_link.ig, user=obj, appraiser_approved=True ) - .aggregate(Sum("karma")) - .get("karma__sum") + .aggregate(Sum("karma")) + .get("karma__sum") ) interest_groups.append( {"id": ig_link.ig.id, "name": ig_link.ig.name, "karma": total_ig_karma} @@ -173,13 +178,16 @@ class Meta: def get_tasks(self, obj): user_id = self.context.get("user_id") - user_lvl = UserLvlLink.objects.filter(user__id=user_id).first().level.level_order - user_igs = UserIgLink.objects.filter(user__id=user_id).values_list("ig__name", flat=True) + user_lvl = UserLvlLink.objects.filter( + user__id=user_id).first().level.level_order + user_igs = UserIgLink.objects.filter( + user__id=user_id).values_list("ig__name", flat=True) tasks = TaskList.objects.filter(level=obj) data = [] for task in tasks: - completed = KarmaActivityLog.objects.filter(user=user_id, task=task, appraiser_approved=True).exists() + completed = KarmaActivityLog.objects.filter( + user=user_id, task=task, appraiser_approved=True).exists() if task.active or completed: data.append( { @@ -203,7 +211,8 @@ class UserRankSerializer(ModelSerializer): class Meta: model = User - fields = ("first_name", "last_name", "role", "rank", "karma", "interest_groups") + fields = ("first_name", "last_name", "role", + "rank", "karma", "interest_groups") def get_role(self, obj): roles = self.context.get("roles") @@ -226,7 +235,8 @@ def get_rank(self, obj): ).count() else: ranks = ( - Wallet.objects.filter(karma__gte=user_karma, user__user_role_link_user__verified=True) + Wallet.objects.filter( + karma__gte=user_karma, user__user_role_link_user__verified=True) .exclude( Q( user__user_role_link_user__role__title__in=[ @@ -258,7 +268,8 @@ class Meta: def update(self, instance, validated_data): user_id = JWTUtils.fetch_user_id(self.context.get("request")) - instance.is_public = validated_data.get("is_public", instance.is_public) + instance.is_public = validated_data.get( + "is_public", instance.is_public) instance.updated_by_id = user_id instance.updated_at = DateTimeUtils.get_current_utc_time() instance.save() @@ -298,7 +309,8 @@ def update(self, instance, validated_data): for org_data in community_data ] - UserOrganizationLink.objects.bulk_create(user_organization_links) + UserOrganizationLink.objects.bulk_create( + user_organization_links) return super().update(instance, validated_data) @@ -386,6 +398,16 @@ def create_karma_activity_log(task_title, karma_value): appraiser_approved_by_id=user_id, appraiser_approved=True, ) + + dl = WebHookActions.SEPARATOR.value + discord_id = User.objects.get(id=user_id).discord_id + value = f"{task.hashtag}{dl}{karma_value}{dl}{discord_id}{dl}{task.id}" + + DiscordWebhooks.general_updates( + WebHookCategory.KARMA_INFO.value, + WebHookActions.UPDATE.value, + value + ) Wallet.objects.filter(user_id=user_id).update( karma=F("karma") + karma_value, updated_by_id=user_id diff --git a/utils/types.py b/utils/types.py index de9e8f9b..08fe766f 100644 --- a/utils/types.py +++ b/utils/types.py @@ -81,6 +81,7 @@ class WebHookCategory(Enum): USER_NAME = 'user-name' USER_PROFILE = 'user-profile' BULK_ROLE = 'bulk-role' + KARMA_INFO = 'karma-info' class RefferalType(Enum): From c2632cf06396477be776a79446898e2bf5a7861a Mon Sep 17 00:00:00 2001 From: Shaheen Hyder K Date: Sun, 10 Dec 2023 00:10:37 +0530 Subject: [PATCH 4/4] (fix): 1.42 migrate file fix --- alter-scripts/alter-1.42.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/alter-scripts/alter-1.42.py b/alter-scripts/alter-1.42.py index a74e0cad..cf02ed78 100644 --- a/alter-scripts/alter-1.42.py +++ b/alter-scripts/alter-1.42.py @@ -6,13 +6,14 @@ from decouple import config from connection import execute -from utils.types import OrganizationType os.chdir('..') sys.path.append(os.getcwd()) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mulearnbackend.settings') django.setup() + from collections import defaultdict +from utils.types import OrganizationType def clg_levels_check():