Example #1
0
 def _share(self, foias, user, post):
     """Share the requests with the selected users"""
     foias = [f for f in foias if f.has_perm(user, 'change')]
     form = FOIAAccessForm(post)
     if form.is_valid():
         access = form.cleaned_data['access']
         users = form.cleaned_data['users']
         if access == 'edit':
             for foia in foias:
                 foia.read_collaborators.remove(*users)
                 foia.edit_collaborators.add(*users)
         elif access == 'view':
             for foia in foias:
                 foia.edit_collaborators.remove(*users)
                 foia.read_collaborators.add(*users)
         return 'Requests shared'
Example #2
0
 def _share(self, foias, user, post):
     """Share the requests with the selected users"""
     foias = [f for f in foias if f.has_perm(user, "change")]
     form = FOIAAccessForm(post)
     if form.is_valid():
         access = form.cleaned_data["access"]
         users = form.cleaned_data["users"]
         if access == "edit":
             for foia in foias:
                 foia.read_collaborators.remove(*users)
                 foia.edit_collaborators.add(*users)
         elif access == "view":
             for foia in foias:
                 foia.edit_collaborators.remove(*users)
                 foia.read_collaborators.add(*users)
         return "Requests shared"
     else:
         return None
Example #3
0
 def _grant_access(self, request, foia):
     """Grant editor access to the specified users."""
     form = FOIAAccessForm(request.POST)
     has_perm = foia.has_perm(request.user, 'change')
     if not has_perm or not form.is_valid():
         return redirect(foia)
     access = form.cleaned_data['access']
     users = form.cleaned_data['users']
     if access == 'edit' and users:
         for user in users:
             foia.add_editor(user)
     if access == 'view' and users:
         for user in users:
             foia.add_viewer(user)
     if len(users) > 1:
         success_msg = '%d people can now %s this request.' % (len(users), access)
     else:
         success_msg = '%s can now %s this request.' % (users[0].first_name, access)
     messages.success(request, success_msg)
     return redirect(foia)
Example #4
0
def grant_access(request, foia):
    """Grant editor access to the specified users."""
    form = FOIAAccessForm(request.POST)
    has_perm = foia.has_perm(request.user, "change")
    if not has_perm or not form.is_valid():
        return _get_redirect(request, foia)
    access = form.cleaned_data["access"]
    users = form.cleaned_data["users"]
    if access == "edit" and users:
        for user in users:
            foia.add_editor(user)
    if access == "view" and users:
        for user in users:
            foia.add_viewer(user)
    if len(users) > 1:
        success_msg = "%d people can now %s this request." % (len(users), access)
    else:
        success_msg = "%s can now %s this request." % (
            users[0].profile.full_name,
            access,
        )
    messages.success(request, success_msg)
    return _get_redirect(request, foia)