Commit 8312c9ee authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

astakos: Introduce private projects

A private project can only be accessed by its owner and its members.
No user can join the project; but the owner can enroll members.
parent 194d5eb8
......@@ -293,7 +293,8 @@ def _get_projects(query, request_user=None):
is_memb = Q(id__in=memb_projects)
owned = (Q(application__owner=request_user) |
Q(application__applicant=request_user))
active = Project.o_state_q(Project.O_ACTIVE)
active = (Project.o_state_q(Project.O_ACTIVE) &
Q(application__private=False))
projects = projects.filter(is_memb | owned | active)
return projects.select_related(
"application", "application__owner", "application__applicant")
......@@ -365,6 +366,13 @@ def _get_maybe_string(d, key):
return value
def _get_maybe_boolean(d, key):
value = d.get(key)
if value is not None and not isinstance(value, bool):
raise faults.BadRequest("%s must be boolean" % key)
return value
DOMAIN_VALUE_REGEX = re.compile(
r'^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$',
re.IGNORECASE)
......@@ -414,6 +422,7 @@ def submit_application(app_data, user, project_id=None):
if not isinstance(max_members, (int, long)) or max_members < 0:
raise faults.BadRequest("Invalid max_members")
private = bool(_get_maybe_boolean(app_data, "private"))
homepage = _get_maybe_string(app_data, "homepage")
description = _get_maybe_string(app_data, "description")
comments = _get_maybe_string(app_data, "comments")
......@@ -432,6 +441,7 @@ def submit_application(app_data, user, project_id=None):
member_join_policy=join_policy,
member_leave_policy=leave_policy,
limit_on_members_number=max_members,
private=private,
comments=comments,
resources=resources,
request_user=user)
......
......@@ -343,7 +343,7 @@ ALLOWED_CHECKS = [
(lambda u, a: not u or u.is_project_admin()),
(lambda u, a: a.owner == u),
(lambda u, a: a.applicant == u),
(lambda u, a: a.chain.overall_state() == Project.O_ACTIVE
(lambda u, a: a.chain.overall_state() == Project.O_ACTIVE and not a.private
or bool(a.chain.projectmembership_set.any_accepted().filter(person=u))),
]
......@@ -672,6 +672,7 @@ def submit_application(owner=None,
member_join_policy=None,
member_leave_policy=None,
limit_on_members_number=None,
private=False,
comments=None,
resources=None,
request_user=None):
......@@ -700,6 +701,7 @@ def submit_application(owner=None,
member_join_policy=member_join_policy,
member_leave_policy=member_leave_policy,
limit_on_members_number=limit_on_members_number,
private=private,
comments=comments)
if project is None:
......
......@@ -1328,6 +1328,7 @@ class ProjectApplication(models.Model):
waive_reason = models.TextField(null=True, blank=True)
waive_actor = models.ForeignKey(AstakosUser, null=True,
related_name='waived_apps')
private = models.BooleanField(default=False)
objects = ProjectApplicationManager()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment