Ejemplo n.º 1
0
 def post(self, request, id):
     team = get_team(request, id)
     user = request.data.get('user')
     try:
         user = UserProfile.objects.get(id=user)
     except:
         return Response(status=status.HTTP_400_BAD_REQUEST)
     if team not in user.teams.all():
         return Response(status=status.HTTP_400_BAD_REQUEST)
     if team.members.count() == 1:
         return Response(
             {
                 "detail":
                 "Team should have at least one member. You can delete the team instead of removing the only member."
             },
             status=status.HTTP_406_NOT_ACCEPTABLE)
     team.members.remove(user)
     #sending email to the person who was removed
     mail_body = f"{request.user.profile.name} removed you from the team {team.name}."
     mail_subject = "You were removed from a team"
     send_email_to(user.user.email, mail_body, mail_subject)
     #sending email to all team members
     mail_body = f"{user.name} was removed from the team {team.name} by {request.user.profile.name}."
     mail_subject = "A member was removed from your team"
     send_email_to_team_members(team, mail_body, mail_subject)
     #-------
     return Response({"detail": "Member was removed successfully."})
Ejemplo n.º 2
0
 def patch(self, request, id):
     board = get_board(request, id)
     if request.user.profile not in board.admins.all():
         return Response(
             {
                 "detail":
                 "You are not an admin of the board so you are not allowed to perform this action"
             },
             status=status.HTTP_403_FORBIDDEN)
     member = request.data.get('member')
     try:
         member = board.members.get(id=member)
     except:
         return Response({"detail": "No such member found."},
                         status=status.HTTP_400_BAD_REQUEST)
     if member in board.admins.all():
         board.admins.remove(member)
         mail_body = f"You are no longer the admin of board {board.name}."
         Activity.objects.create(
             description=
             f"{member.name} is no longer the admin of {board.name}",
             user=member,
             board=board)
     else:
         board.admins.add(member)
         mail_body = f"You are now an admin of board {board.name}"
         Activity.objects.create(
             description=f"{member.name} is now an admin of {board.name}",
             user=member,
             board=board)
     mail_subject = f"{board.name}(board)"
     send_email_to(member.user.email, mail_body, mail_subject)
     return Response(
         {"detail": "changed permission of member successfully"})
Ejemplo n.º 3
0
 def post(self, request, id):  #add multiple members
     board = get_board(request, id)
     if board.preference.pref_invitation == models.Preference.invitations.members or request.user.profile in board.admins.all(
     ):
         members = request.data.get("members", None)
         if members is not None:
             for member in members:
                 try:
                     user = models.UserProfile.objects.get(
                         user__email=member)
                 except:
                     print("user does not exist")
                     continue
                 if member in board.members.all():
                     continue
                 board.members.add(user)
                 mail_body = f"{request.user.profile.name} added you to board {board.name}.\n If you don't want to be in that board you can leave the board anytime."
                 mail_subject = f"You are invited to join board"
                 send_email_to(member, mail_body, mail_subject)
             mail_body = f"{request.user.profile.name} added some members to the board {board.name}.\n You are receiving this email because you are watching the board {board.name}. If you don't want to receive such emails, you can unwatch the board."
             mail_subject = f"{board.name}(Board)"
             send_email_to_object_watchers(board, mail_body, mail_subject)
             #activity creation
             Activity.objects.create(
                 description="{} added some members in {}.".format(
                     request.user.profile.name, board.name),
                 user=request.user.profile,
                 board=board)
             return Response({"detail": "Members were added"},
                             status=status.HTTP_200_OK)
         return Response(status=status.HTTP_400_BAD_REQUEST)
     return Response(status=status.HTTP_403_FORBIDDEN)
Ejemplo n.º 4
0
 def put(self, request, card_id):
     card = self.get_card(card_id)
     members = request.data['members']
     if not (request.user.profile in card.list.board.members.all()):
         return Response(status=status.HTTP_403_FORBIDDEN)
     for member in members:
         try:
             user = card.members.get(user__email=member)
         except:
             continue
         if not (user in card.members.all()):
             continue
         card.members.remove(user)
         if user != request.user.profile:
             mail_body = f"{request.user.profile.name} removed you from the card {card.name}."
             mail_subject = f'You were removed from a card'
             send_email_to(member, mail_body,
                           mail_subject)  #email notification
             Activity.objects.create(
                 description=
                 f"{user.name} left card {card.name} in {card.list.name}",
                 user=user,
                 board=card.list.board,
                 list=card.list,
                 card=card)
     return Response({"detail": "successfully removed members from card."})
Ejemplo n.º 5
0
 def patch(self, request, id):  # remove member
     board = get_board(request, id)
     request_user_is_admin = bool(
         request.user.profile in board.admins.all())
     if board.preference.pref_invitation == models.Preference.invitations.members or request_user_is_admin:
         member = request.data.get("member", None)
         try:
             member = board.members.get(id=member)
         except:
             return Response({"detail": "No such member found."},
                             status=status.HTTP_400_BAD_REQUEST)
         member_is_admin = bool(member in board.admins.all())
         if board.members.count() == 1 or (member_is_admin
                                           and board.admins.count() == 1):
             return Response(
                 {
                     "detail":
                     "board must have at least one member and admin"
                 },
                 status=status.HTTP_400_BAD_REQUEST)
         if member_is_admin and not request_user_is_admin:
             return Response(
                 {
                     "detail":
                     "You are not allowed to remove an admin from board."
                 },
                 status=status.HTTP_403_FORBIDDEN)
         board.members.remove(member)
         if member in board.admins.all():
             board.admins.remove(member)
         if not is_allowed_to_watch_or_star(member, board):
             board.starred_by.remove(member)
             board.watched_by.remove(member)
             lists_to_unwatch = member.watching_lists.filter(board=board)
             member.starred_lists.remove(*lists_to_unwatch)
             cards_to_unwatch = member.watching_cards.filter(
                 list__board=board)
             member.starred_lists.remove(*cards_to_unwatch)
         mail_body = f"{request.user.profile.name} removed you from board {board.name}."
         mail_subject = "you were removed from a board"
         send_email_to(member.user.email, mail_body, mail_subject)
         mail_body = f"{member.name} was removed from the board {board.name}.\n You are receiving this email because you are watching the board {board.name}. If you don't want to receive such emails, you can unwatch the board."
         mail_subject = f"{board.name}(Board)"
         send_email_to_object_watchers(board, mail_body, mail_subject)
         #activity creation
         Activity.objects.create(
             description="{} removed {} from {}.".format(
                 request.user.profile.name, member.name, board.name),
             user=request.user.profile,
             board=board)
         return Response({"detail": "succesfully removed from board"},
                         status=status.HTTP_200_OK)
     return Response(status=status.HTTP_403_FORBIDDEN)
Ejemplo n.º 6
0
 def post(self, request, id):
     team = get_team(request, id)
     if 'members' not in request.data:
         return Response(status=status.HTTP_400_BAD_REQUEST)
     members = request.data['members']
     invalid_emails = []
     for member in members:
         try:
             user = UserProfile.objects.get(user__email=member)
             team.members.add(user.id)
             mail_body = f"{request.user.profile.name} added you to team {team.name}. If you don't want to be a part of this team you can leave the team anytime."
             mail_subject = f'You were added to a team'
             send_email_to(member, mail_body,
                           mail_subject)  #email notification
         except:
             invalid_emails.append(member)
             # mail_body = f"Someone wanted to join you to a 'The Flow' team. Flow helps you to organise you project and other works properly to increase you productivity upto 100%. You Create an account on 'The Flow' for free. For more information visit -------------"
     if len(invalid_emails) != 0:
         return Response({
             "detail":
             "User Not found for some emails. Please tell them to join 'The Flow'. You can add them in team after they have joined.",
             "invalid_emails": invalid_emails
         })
     return Response({"detail": "Members added successfully"})