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

Shoonya v2.6.2 Patch #1058

Merged
merged 30 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7358ddb
Merge branch 'dev' of https://github.com/AI4Bharat/Shoonya-Backend
Mar 16, 2024
4906592
updated the creation of notification task
Mar 18, 2024
4e2052b
updated the code with black linting
Mar 18, 2024
45e672c
updated the support feature of hyperlink in backend
Mar 20, 2024
d567454
Merge branch 'dev' of https://github.com/AI4Bharat/Shoonya-Backend in…
Mar 20, 2024
e491d3c
reformatted using black
Mar 21, 2024
95ba0ef
added a feature to remove user from all workspaces as workspace manag…
ishangujarathi Mar 27, 2024
2b4e4bd
Merge branch 'dev' into pursottam-dev
ishvindersethi22 Mar 28, 2024
0a8b56c
Merge pull request #1029 from AI4Bharat/pursottam-dev
ishvindersethi22 Mar 28, 2024
11e30f0
Merge branch 'dev' into remove_user_workspace
ishvindersethi22 Apr 1, 2024
41cd6eb
Merge pull request #1042 from AI4Bharat/remove_user_workspace
ishvindersethi22 Apr 1, 2024
d78dd13
Update tasks.py
ishvindersethi22 Apr 8, 2024
2293560
Merge pull request #1046 from AI4Bharat/quick-fix
aparna-aa Apr 8, 2024
f73d0df
added a feature to remove user as workspace member and manager when h…
ishangujarathi Apr 8, 2024
2d65be6
added backend.shoonya2.ai4bharat.org in allowed_hosts
KunalTiwary Apr 10, 2024
8e81a4c
Merge pull request #1049 from AI4Bharat/allowed_host_fix
aparna-aa Apr 10, 2024
6c2a68c
Merge pull request #1047 from AI4Bharat/remove_user
aparna-aa Apr 15, 2024
b064b78
Revert "added a feature to remove user as workspace member and manage…
ishvindersethi22 Apr 15, 2024
7b2a8f7
Merge pull request #1052 from AI4Bharat/revert-1047-remove_user
aparna-aa Apr 15, 2024
dc8ffc7
Revert "added a feature to remove user from all workspaces as workspa…
ishvindersethi22 Apr 15, 2024
ab578bd
Merge pull request #1053 from AI4Bharat/revert-1042-remove_user_works…
aparna-aa Apr 15, 2024
86e253e
added additional filtering for other fields in dataset download endpoint
KunalTiwary Apr 16, 2024
56a250d
Update settings.py
ishvindersethi22 Apr 16, 2024
d1674b1
Update settings.py
ishvindersethi22 Apr 16, 2024
54ed59b
Update settings.py
ishvindersethi22 Apr 18, 2024
5c52f88
Merge pull request #1056 from AI4Bharat/e-mail-settings
aparna-aa Apr 18, 2024
56669f4
Merge branch 'dev' into dataset_download_fix
ishvindersethi22 Apr 18, 2024
45666a8
Update views.py
ishvindersethi22 Apr 18, 2024
6049f85
Update views.py
ishvindersethi22 Apr 18, 2024
7de6582
Merge pull request #1055 from AI4Bharat/dataset_download_fix
ishvindersethi22 Apr 18, 2024
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
15 changes: 14 additions & 1 deletion backend/dataset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def download(self, request, pk):
URL: /data/instances/<instance-id>/download/
Accepted methods: GET
"""
export_type = request.GET.get("type", "csv")
export_type = request.GET.get("export_type", "csv").lower()
try:
# Get the dataset instance for the id
dataset_instance = DatasetInstance.objects.get(instance_id=pk)
Expand All @@ -314,6 +314,19 @@ def download(self, request, pk):

dataset_model = apps.get_model("dataset", dataset_instance.dataset_type)
data_items = dataset_model.objects.filter(instance_id=pk)
field_names = set([field.name for field in dataset_model._meta.get_fields()])
for key, value in request.GET.items():
if key in field_names:
kwargs = {f"{key}__icontains": value}
data_items = data_items.filter(**kwargs)
elif key == "export_type":
continue
else:
return Response(
{"message": "The corresponding column does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)

dataset_resource = resources.RESOURCE_MAP[dataset_instance.dataset_type]
exported_items = dataset_resource().export_as_generator(export_type, data_items)
if export_type == "tsv":
Expand Down
16 changes: 14 additions & 2 deletions backend/notifications/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@ def delete_excess_Notification(user):
return 0


@shared_task
def create_notification_handler(title, notification_type, users_ids):
# @shared_task
def create_notification_handler(
title, notification_type, users_ids, project_id=None, task_id=None
):
if not notification_aggregated(title, notification_type, users_ids):
notitification_url = (
f"/projects/{project_id}/task/{task_id}"
if project_id and task_id
else f"/projects/{project_id}"
if project_id
else f"/task/{task_id}"
if task_id
else None
)
new_notif = Notification(
notification_type=notification_type,
title=title,
metadata_json="null",
on_click=notitification_url,
)
try:
with transaction.atomic():
Expand Down
8 changes: 6 additions & 2 deletions backend/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
NOTIFICATION_CHANGED_STATE = {"message": "Notification changed state"}


def createNotification(title, notification_type, users_ids):
def createNotification(
title, notification_type, users_ids, project_id=None, task_id=None
):
"""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, project_id, task_id
)
print(f"Creating notifications title- {title} for users_ids- {users_ids}")
return 0

Expand Down
2 changes: 1 addition & 1 deletion backend/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def create_parameters_for_task_creation(
tasks = create_tasks_from_dataitems(sampled_items, project)


# @shared_task
@shared_task
def export_project_in_place(
annotation_fields, project_id, project_type, get_request_data
) -> None:
Expand Down
18 changes: 10 additions & 8 deletions backend/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ def remove_annotator(self, request, pk=None, freeze_user=True):
)
notification_ids.extend(ids)
notification_ids_set = list(set(notification_ids))
createNotification(title, notification_type, notification_ids_set)
createNotification(title, notification_type, notification_ids_set, pk)

return Response(
{"message": "User removed from project"},
Expand Down Expand Up @@ -1728,7 +1728,9 @@ def remove_reviewer(self, request, pk=None, freeze_user=True):
)
notification_ids.extend(ids)
notification_ids_set = list(set(notification_ids))
createNotification(title, notification_type, notification_ids_set)
createNotification(
title, notification_type, notification_ids_set, project.id
)

return Response(
{"message": "User removed from the project"}, status=status.HTTP_200_OK
Expand Down Expand Up @@ -1808,7 +1810,7 @@ def remove_superchecker(self, request, pk=None, freeze_user=True):
)
notification_ids.extend(ids)
notification_ids_set = list(set(notification_ids))
createNotification(title, notification_type, notification_ids_set)
createNotification(title, notification_type, notification_ids_set, pk)

return Response(
{"message": "User removed from the project"}, status=status.HTTP_200_OK
Expand Down Expand Up @@ -2172,7 +2174,7 @@ def update(self, request, pk=None, *args, **kwargs):
super_checkers_bool=True,
project_manager_bool=True,
)
createNotification(title, notification_type, notification_ids)
createNotification(title, notification_type, notification_ids, pk)
return super().update(request, *args, **kwargs)

@is_project_editor
Expand Down Expand Up @@ -3594,7 +3596,7 @@ def add_project_annotators(self, request, pk=None, *args, **kwargs):
project_manager_bool=True,
)

createNotification(title, notification_type, notification_ids)
createNotification(title, notification_type, notification_ids, pk)

return Response(
{"message": "Annotator added to the project"}, status=status.HTTP_200_OK
Expand Down Expand Up @@ -3661,7 +3663,7 @@ def add_project_reviewers(self, request, pk, *args, **kwargs):
project_manager_bool=True,
)

createNotification(title, notification_type, notification_ids)
createNotification(title, notification_type, notification_ids, pk)

return Response({"message": "Reviewers added"}, status=status.HTTP_200_OK)
except Project.DoesNotExist:
Expand Down Expand Up @@ -3724,7 +3726,7 @@ def add_project_supercheckers(self, request, pk, *args, **kwargs):
project_manager_bool=True,
)

createNotification(title, notification_type, notification_ids)
createNotification(title, notification_type, notification_ids, pk)

return Response(
{"message": "SuperCheckers added"}, status=status.HTTP_200_OK
Expand Down Expand Up @@ -4327,7 +4329,7 @@ def project_publish(self, request, pk=None, *args, **kwargs):
super_checkers_bool=True,
project_manager_bool=True,
)
createNotification(title, notification_type, notification_ids)
createNotification(title, notification_type, notification_ids, pk)
ret_dict = {"message": "This project is published"}
ret_status = status.HTTP_200_OK
except Exception as e:
Expand Down
6 changes: 4 additions & 2 deletions backend/shoonya_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"shoonya.ai4bharat.org",
"0.0.0.0",
"backend.shoonya.ai4bharat.org",
"backend.shoonya2.ai4bharat.org",
]

# Application definition
Expand Down Expand Up @@ -186,12 +187,13 @@


# Email Settings
EMAIL_BACKEND = "django_smtp_ssl.SSLEmailBackend"
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = os.getenv("EMAIL_HOST")
EMAIL_PORT = 465
EMAIL_PORT = os.getenv("EMAIL_PORT")
EMAIL_HOST_USER = os.getenv("SMTP_USERNAME")
EMAIL_HOST_PASSWORD = os.getenv("SMTP_PASSWORD")
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
DEFAULT_FROM_EMAIL = os.getenv("DEFAULT_FROM_EMAIL")

DOMAIN = "shoonya.ai4bharat.org"
Expand Down
54 changes: 54 additions & 0 deletions backend/tasks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
TaskAnnotationSerializer,
)
from tasks.utils import query_flower
from notifications.views import createNotification
from notifications.utils import get_userids_from_project_id

from users.models import User
from projects.models import Project, REVIEW_STAGE, ANNOTATION_STAGE, SUPERCHECK_STAGE
Expand Down Expand Up @@ -1510,6 +1512,41 @@ def get_audio_file(self, request):
return Response(data=encoded_audio_data, status=status.HTTP_200_OK)


def update_notification(annotation_obj, task):
project_id = task.project_id.id
project_name = task.project_id
notification_type = "task_update"

if annotation_obj.annotation_status == TO_BE_REVISED:
title = f"{project_name} : {project_id} Some tasks annotated by you in this project have been sent back for revision"
try:
notification_ids = get_userids_from_project_id(
project_id=project_id,
reviewers_bool=True,
project_manager_bool=True,
)
notification_ids_set = list(set(notification_ids))
createNotification(
title, notification_type, notification_ids_set, project_id, task.id
)
except Exception as e:
print(f"Error in creating notification: {e}")

elif annotation_obj.annotation_status == REJECTED:
title = f"{project_name} : {project_id} Some tasks reviewed by you in this project have been rejected by superchecker"
try:
notification_ids = get_userids_from_project_id(
project_id=project_id,
reviewers_bool=True,
project_manager_bool=True,
)
notification_type = "rejected task"
notification_ids_set = list(set(notification_ids))
createNotification(title, notification_type, notification_ids_set)
except Exception as e:
print(f"Error in creating notification: {e}")


class AnnotationViewSet(
mixins.CreateModelMixin,
mixins.UpdateModelMixin,
Expand Down Expand Up @@ -1673,6 +1710,11 @@ def partial_update(self, request, pk=None):
status=status.HTTP_400_BAD_REQUEST,
)

try:
task = Task.objects.get(pk=request.data["task_id"])
except:
print("task not found")

auto_save = False
if "auto_save" in request.data:
auto_save = True
Expand All @@ -1696,10 +1738,22 @@ def partial_update(self, request, pk=None):
if annotation_obj.annotation_type == REVIEWER_ANNOTATION:
is_revised = False
if annotation_obj.annotation_status == TO_BE_REVISED:
update_notification(annotation_obj, task)
is_revised = True
print(annotation_obj)
if "ids" in dict(request.data):
pass

else:
return Response(
{"message": "key doesnot match"},
status=status.HTTP_400_BAD_REQUEST,
)

elif annotation_obj.annotation_type == SUPER_CHECKER_ANNOTATION:
is_rejected = False
if annotation_obj.annotation_type == REJECTED:
update_notification(annotation_obj, task)
is_rejected = True

is_acoustic_project_type = (
Expand Down
Loading