Skip to content

Commit

Permalink
collaborators only from network, closes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
muremwa committed May 1, 2023
1 parent a543d4e commit dc13721
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions notes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,12 @@ def add_collaborator(request, **kwargs):
if request.user != note.user:
raise PermissionDenied("You are not authorised to add a collaborator")
else:
note.collaborators.add(add_this)
notes_signal.send(add_collaborator, note=note, user=add_this.user)
return redirect(reverse("notes:edit-collaborators", args=[str(kwargs['note_id'])]))
if Connection.objects.exist(request.user, add_this.user, status=True):
note.collaborators.add(add_this)
notes_signal.send(add_collaborator, note=note, user=add_this.user)
else:
raise PermissionDenied(f"@{add_this.user.username} cannot be a collaborator, they are not in your network")
return redirect(reverse("notes:edit-collaborators", args=[str(kwargs['note_id'])]))


# remove collaboration
Expand Down Expand Up @@ -521,11 +524,7 @@ def undo_collaborative(request, note_id):
if note.user != request.user:
raise Http404
else:
collaborators = note.collaborators.all()
# remove all collaborators first
for collaborator in collaborators:
note.collaborators.remove(collaborator)
# make collaborative false
note.collaborators.clear()
note.collaborative = False
note.save()

Expand Down

0 comments on commit dc13721

Please # to comment.