Skip to content

Commit

Permalink
updated the noficiation update from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Pursottam6003 committed Mar 24, 2024
1 parent 6fbacc2 commit cf54720
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 6 deletions.
1 change: 1 addition & 0 deletions backend/anudesh_backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
2 changes: 1 addition & 1 deletion backend/dataset/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import resource
# import resource
from django.contrib import admin
from import_export.admin import ImportExportActionModelAdmin
from .resources import *
Expand Down
2 changes: 1 addition & 1 deletion backend/notifications/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions backend/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
17 changes: 16 additions & 1 deletion backend/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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!"}
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions backend/users/migrations/0034_user_notification_limit.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
8 changes: 7 additions & 1 deletion backend/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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'),
),
]

0 comments on commit cf54720

Please sign in to comment.