Skip to content

Commit

Permalink
Merge pull request #1696 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
devserv
  • Loading branch information
Aashish Vinu authored Dec 2, 2023
2 parents 2f21f40 + 99bea00 commit d974c02
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/dashboard/affiliation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Meta:
fields = ['id','title','organization_count', 'created_by', 'updated_by']

def get_organization_count(self,obj):
return obj.organizations.count()
return obj.organization_affiliation.count()



Expand Down
2 changes: 1 addition & 1 deletion api/dashboard/events/events_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Meta:
class EventsCUDSerializer(serializers.ModelSerializer):
class Meta:
model = Events
fields = ['name']
fields = ['name', 'description']

def create(self, validated_data):
user_id = self.context.get("user_id")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import datetime, timedelta

from db.learning_circle import UserCircleLink, LearningCircle


def get_today_start_end(date_time):
start_of_day = datetime(
Expand Down Expand Up @@ -41,3 +43,24 @@ def get_week_start_end(date_time):
)
return start_of_week, end_of_week


def is_learning_circle_member(user_id, circle_id):
user_circle_link = UserCircleLink.objects.filter(
user_id=user_id,
circle_id=circle_id,
accepted=True
).exists()

if user_circle_link:
return True
return False


def is_valid_learning_circle(circle_id):
learning_circle = LearningCircle.objects.filter(
id=circle_id
).exists()

if learning_circle:
return True
return False
3 changes: 2 additions & 1 deletion api/dashboard/lc/dash_lc_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from utils.types import OrganizationType
from utils.utils import DateTimeUtils
from utils.types import Lc
from .lc_support_functions import get_today_start_end, get_week_start_end
from .dash_ig_helper import get_today_start_end, get_week_start_end


class LearningCircleSerializer(serializers.ModelSerializer):
created_by = serializers.CharField(source='created_by.fullname')
Expand Down
66 changes: 55 additions & 11 deletions api/dashboard/lc/dash_lc_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
LearningCircleMemberListSerializer, MeetRecordsCreateEditDeleteSerializer, IgTaskDetailsSerializer, \
ScheduleMeetingSerializer, ListAllMeetRecordsSerializer, AddMemberSerializer

from .dash_ig_helper import is_learning_circle_member, is_valid_learning_circle, get_today_start_end, get_week_start_end

domain = config("FR_DOMAIN_NAME")
from_mail = config("FROM_MAIL")

Expand Down Expand Up @@ -250,23 +252,19 @@ class LearningCircleDetailsApi(APIView):
def get(self, request, circle_id, member_id=None):
user_id = JWTUtils.fetch_user_id(request)

user_circle_link = UserCircleLink.objects.filter(
user_id=user_id,
circle_id=circle_id,
accepted=True
).first()

if user_circle_link is None:
if not is_valid_learning_circle(circle_id):
return CustomResponse(
general_message='your are not a part of this learning circle circle'
general_message='invalid learning circle'
).get_failure_response()

if not LearningCircle.objects.filter(id=circle_id).exists():
if not is_learning_circle_member(user_id, circle_id):
return CustomResponse(
general_message='Learning Circle not found'
general_message='unauthorized access'
).get_failure_response()

learning_circle = LearningCircle.objects.filter(id=circle_id).first()
learning_circle = LearningCircle.objects.filter(
id=circle_id
).first()

serializer = LearningCircleDetailsSerializer(
learning_circle,
Expand Down Expand Up @@ -719,3 +717,49 @@ def post(self, request, circle_id):
return CustomResponse(
message=serializer.errors
).get_failure_response()


class ValidateUserMeetCreateAPI(APIView):
def get(self, request, circle_id):
user_id = JWTUtils.fetch_user_id(request)

if not is_valid_learning_circle(circle_id):
return CustomResponse(
general_message='invalid learning circle'
).get_failure_response()

if not is_learning_circle_member(user_id, circle_id):
return CustomResponse(
general_message='unauthorized access'
).get_failure_response()

today_date_time = DateTimeUtils.get_current_utc_time()

start_of_day, end_of_day = get_today_start_end(today_date_time)
start_of_week, end_of_week = get_week_start_end(today_date_time)

if CircleMeetingLog.objects.filter(
circle_id=circle_id,
meet_time__range=(
start_of_day,
end_of_day
)
).exists():
return CustomResponse(
general_message=f'Another meet already scheduled on {today_date_time.date()}'
).get_failure_response()

if CircleMeetingLog.objects.filter(
circle_id=circle_id,
meet_time__range=(
start_of_week,
end_of_week
)
).count() >= 5:
return CustomResponse(
general_message='you can create only 5 meeting in a week'
).get_failure_response()

return CustomResponse(
general_message='success'
).get_success_response()
5 changes: 4 additions & 1 deletion api/dashboard/lc/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

urlpatterns = [
path('user-list/', dash_lc_view.UserLearningCircleListApi.as_view(), name='main'), # list all lc's of user
# URL issue
path('list-all/<str:circle_code>/', dash_lc_view.TotalLearningCircleListApi.as_view(), name='list-all-search'),
path('<str:circle_id>/details/', dash_lc_view.LearningCircleDetailsApi.as_view(), name='lc-detailed'), # individual ls details
# dashboard search listing
path('<str:circle_id>/schedule-meet/', dash_lc_view.ScheduleMeetAPI.as_view(), name='schedule-meet'),
path('<str:circle_id>/report/create/', dash_lc_view.SingleReportDetailAPI.as_view(), name='create-report'),
path('<str:circle_id>/report/create/validate/', dash_lc_view.ValidateUserMeetCreateAPI.as_view(), name='validate-report'),
path('<str:circle_id>/report/<str:report_id>/show/', dash_lc_view.SingleReportDetailAPI.as_view(), name='show-report'),
path('<str:circle_id>/add-member/', dash_lc_view.AddMemberAPI.as_view(), name='add-member'),
path('create/', dash_lc_view.LearningCircleCreateApi.as_view(), name='create'),
Expand All @@ -22,7 +26,6 @@
path('<str:circle_id>/<str:member_id>/', dash_lc_view.LearningCircleDetailsApi.as_view()), # user accept or reject, also for removal
path('list/', dash_lc_view.LearningCircleMainApi.as_view(), name='list'), # public page listing
path('list-all/', dash_lc_view.TotalLearningCircleListApi.as_view(), name='list-all'), # dashboard search listing
path('list-all/<str:circle_code>/', dash_lc_view.TotalLearningCircleListApi.as_view(), name='list-all-search'), # dashboard search listing

# path('data/', dash_lc_view.LearningCircleDataAPI.as_view(), name='data'),
# path('list-members/<str:circle_id>/', dash_lc_view.LearningCircleListMembersApi.as_view(), name='list-members'),
Expand Down
2 changes: 1 addition & 1 deletion db/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Meta:

class College(models.Model):
id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4())
level = models.IntegerField(default=1)
level = models.IntegerField(default=0)
org = models.OneToOneField(Organization, on_delete=models.CASCADE, related_name='college_org', unique=True)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column='updated_by',
related_name='college_updated_by')
Expand Down
1 change: 1 addition & 0 deletions db/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class Meta:
class Events(models.Model):
id = models.CharField(primary_key=True, max_length=36, default=uuid.uuid4)
name = models.CharField(max_length=75)
description = models.CharField(max_length=200, null=True)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE, db_column="updated_by",
related_name="event_updated_by")
updated_at = models.DateTimeField(auto_now=True)
Expand Down

0 comments on commit d974c02

Please sign in to comment.