From cf54720ed40b8b5a1ca9abce415e50ae03fda273 Mon Sep 17 00:00:00 2001 From: Pursottam6003 Date: Sun, 24 Mar 2024 17:16:03 +0530 Subject: [PATCH] updated the noficiation update from backend --- backend/anudesh_backend/urls.py | 1 + backend/dataset/admin.py | 2 +- backend/notifications/tasks.py | 2 +- backend/notifications/views.py | 4 ++-- backend/projects/views.py | 17 ++++++++++++++++- .../migrations/0034_user_notification_limit.py | 18 ++++++++++++++++++ backend/users/models.py | 8 +++++++- .../0017_alter_workspace_guest_workspace.py | 18 ++++++++++++++++++ 8 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 backend/users/migrations/0034_user_notification_limit.py create mode 100644 backend/workspaces/migrations/0017_alter_workspace_guest_workspace.py diff --git a/backend/anudesh_backend/urls.py b/backend/anudesh_backend/urls.py index b72b3d4d..8e67240e 100644 --- a/backend/anudesh_backend/urls.py +++ b/backend/anudesh_backend/urls.py @@ -44,6 +44,7 @@ def get_schema(self, request=None, public=False): path("workspaces/", include("workspaces.urls")), # path("/", include("tasks.urls")), path("tasks/", include("tasks.urls")), + path("notifications/", include("notifications.urls")), path("projects/", include("projects.urls")), path("functions/", include("functions.urls")), path("data/", include("dataset.urls")), diff --git a/backend/dataset/admin.py b/backend/dataset/admin.py index f0722494..1cc90467 100644 --- a/backend/dataset/admin.py +++ b/backend/dataset/admin.py @@ -1,4 +1,4 @@ -import resource +# import resource from django.contrib import admin from import_export.admin import ImportExportActionModelAdmin from .resources import * diff --git a/backend/notifications/tasks.py b/backend/notifications/tasks.py index a785394c..4fb177d2 100644 --- a/backend/notifications/tasks.py +++ b/backend/notifications/tasks.py @@ -22,7 +22,7 @@ def delete_excess_Notification(user): return 0 -@shared_task +# @shared_task def create_notification_handler(title, notification_type, users_ids): if not notification_aggregated(title, notification_type, users_ids): new_notif = Notification( diff --git a/backend/notifications/views.py b/backend/notifications/views.py index eab01998..f98d2780 100644 --- a/backend/notifications/views.py +++ b/backend/notifications/views.py @@ -4,7 +4,7 @@ from drf_yasg import openapi from drf_yasg.utils import swagger_auto_schema from rest_framework import status -from shoonya_backend.celery import celery_app +# from shoonya_backend.celery import celery_app from rest_framework.decorators import api_view from rest_framework.response import Response @@ -22,7 +22,7 @@ def createNotification(title, notification_type, users_ids): """calling shared task of notification creation from tasks""" - create_notification_handler.delay(title, notification_type, users_ids) + create_notification_handler(title, notification_type, users_ids) print(f"Creating notifications title- {title} for users_ids- {users_ids}") return 0 diff --git a/backend/projects/views.py b/backend/projects/views.py index 370e27b6..e58eafc0 100644 --- a/backend/projects/views.py +++ b/backend/projects/views.py @@ -37,6 +37,8 @@ from .models import * from .registry_helper import ProjectRegistry from dataset import models as dataset_models +import notifications + from .utils import ( get_annotations_for_project, get_status_from_query_params, @@ -84,7 +86,6 @@ from notifications.utils import get_userids_from_project_id # Create your views here. - EMAIL_REGEX = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b" PROJECT_IS_PUBLISHED_ERROR = {"message": "This project is already published!"} @@ -1438,6 +1439,20 @@ def remove_annotator(self, request, pk=None, freeze_user=True): if freeze_user == True: project.frozen_users.add(user) project.save() + + # Creating Notification + title = f"{project.title}:{project.id} Some annotators have been removed from this project" + notification_type = "remove_member" + notification_ids = get_userids_from_project_id( + project_id=pk, + annotators_bool=True, + reviewers_bool=True, + super_checkers_bool=True, + project_manager_bool=True, + ) + notification_ids.extend(ids) + notification_ids_set = list(set(notification_ids)) + createNotification(title, notification_type, notification_ids_set) return Response( {"message": "User removed from project"}, status=status.HTTP_201_CREATED, diff --git a/backend/users/migrations/0034_user_notification_limit.py b/backend/users/migrations/0034_user_notification_limit.py new file mode 100644 index 00000000..76d59e8e --- /dev/null +++ b/backend/users/migrations/0034_user_notification_limit.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.14 on 2024-03-23 16:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0033_auto_20240123_0310'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='notification_limit', + field=models.BigIntegerField(default=100, help_text='Indicates the number of maximum notifications a user will receive.', null=True), + ), + ] diff --git a/backend/users/models.py b/backend/users/models.py index 1361c70b..b9b8cc33 100644 --- a/backend/users/models.py +++ b/backend/users/models.py @@ -264,7 +264,13 @@ class User(AbstractBaseUser, PermissionsMixin): unverified_email = models.EmailField(blank=True) old_email_update_code = models.CharField(max_length=256, blank=True) new_email_verification_code = models.CharField(max_length=256, blank=True) - + notification_limit = models.BigIntegerField( + null=True, + default=100, + help_text=( + "Indicates the number of maximum notifications a user will receive." + ), + ) objects = UserManager() EMAIL_FIELD = "email" diff --git a/backend/workspaces/migrations/0017_alter_workspace_guest_workspace.py b/backend/workspaces/migrations/0017_alter_workspace_guest_workspace.py new file mode 100644 index 00000000..d4e3defe --- /dev/null +++ b/backend/workspaces/migrations/0017_alter_workspace_guest_workspace.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.14 on 2024-03-23 16:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('workspaces', '0016_workspace_workspace_password'), + ] + + operations = [ + migrations.AlterField( + model_name='workspace', + name='guest_workspace', + field=models.BooleanField(default=False, help_text='Indicates if the workspace is for guest-users.', verbose_name='guest_workspace'), + ), + ]