Skip to content

Commit

Permalink
Merge pull request #30 from opengisch/format
Browse files Browse the repository at this point in the history
Fix collaborators and exports
  • Loading branch information
suricactus authored May 25, 2021
2 parents 44cc81e + bd54a94 commit a4f0d19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
12 changes: 5 additions & 7 deletions docker-app/qfieldcloud/core/invitations_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def invite_user_by_email(
except IntegrityError:
return (
False,
_("%(email)s has already been invited to create a QFieldCloud account.")
% {"email": email},
_("{} has already been invited to create a QFieldCloud account.").format(
email
),
)

# TODO see if we can "pre-attach" this future user to this project, probably to be done
Expand All @@ -67,10 +68,7 @@ def invite_user_by_email(
invite.send_invitation(request)
return (
True,
_("%(email)s has been invited to create a QFieldCloud account.")
% {"email": email},
_("{} has been invited to create a QFieldCloud account.").format(email),
)

return True, _("%(email)s has been added to the QFieldCloud waiting list.") % {
"email": email
}
return True, _("{} has been added to the QFieldCloud waiting list.").format(email)
14 changes: 14 additions & 0 deletions docker-app/qfieldcloud/core/permissions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
OrganizationMember,
Project,
ProjectCollaborator,
ProjectQueryset,
)
from qfieldcloud.core.models import User as QfcUser

Expand All @@ -24,6 +25,14 @@ def user_has_project_roles(
return _project_for_owner(user, project).filter(user_role__in=roles).exists()


def user_has_project_role_origins(
user: QfcUser, project: Project, origins: List[ProjectQueryset.RoleOrigins]
):
return (
_project_for_owner(user, project).filter(user_role_origin__in=origins).exists()
)


def user_has_organization_roles(
user: QfcUser, organization: Organization, roles: List[OrganizationMember.Roles]
):
Expand Down Expand Up @@ -363,6 +372,11 @@ def can_delete_members(user: QfcUser, organization: Organization) -> bool:


def can_become_collaborator(user: QfcUser, project: Project) -> bool:
if user_has_project_role_origins(
user, project, [ProjectQueryset.RoleOrigins.PUBLIC]
):
return True

return not user_has_project_roles(
user,
project,
Expand Down
2 changes: 1 addition & 1 deletion docker-qgis/libqfieldsync

0 comments on commit a4f0d19

Please sign in to comment.