Revision edc51a21

b/astakosclient/astakosclient/__init__.py
804 804

  
805 805
    # ----------------------------
806 806
    # do a GET to ``API_PROJECTS``
807
    def get_projects(self, name=None, state=None, owner=None):
807
    def get_projects(self, name=None, state=None, owner=None, mode=None):
808 808
        """Retrieve all accessible projects
809 809

  
810 810
        Arguments:
811 811
        name  -- filter by name (optional)
812 812
        state -- filter by state (optional)
813 813
        owner -- filter by owner (optional)
814
        mode  -- if value is 'member', return only active projects in which
815
                 the request user is an active member
814 816

  
815 817
        In case of success, return a list of project descriptions.
816 818
        """
......
821 823
            filters["state"] = state
822 824
        if owner is not None:
823 825
            filters["owner"] = owner
826
        if mode is not None:
827
            filters["mode"] = mode
824 828
        req_headers = {'content-type': 'application/json'}
825 829
        req_body = (parse_request({"filter": filters}, self.logger)
826 830
                    if filters else None)
b/astakosclient/docs/index.rst
189 189
        rejected and which failed to resolved. Otherwise raise an
190 190
        AstakosClientException exception.
191 191

  
192
    **get_projects(**\ name=None, state=None, owner=None\ **)**
192
    **get_projects(**\ name=None, state=None, owner=None, mode=None\ **)**
193 193
        Retrieve all accessible projects
194 194

  
195 195
    **get_project(**\ project_id\ **)**
b/snf-astakos-app/astakos/api/projects.py
281 281
    user = request.user
282 282
    input_data = read_json_body(request, default={})
283 283
    filters = input_data.get("filter", {})
284
    mode = input_data.get("mode", "default")
284 285
    query = make_project_query(filters)
285
    projects = _get_projects(query, request_user=user)
286
    projects = _get_projects(query, mode=mode, request_user=user)
286 287
    data = get_projects_details(projects, request_user=user)
287 288
    return json_response(data)
288 289

  
289 290

  
290
def _get_projects(query, request_user=None):
291
def _get_projects(query, mode="default", request_user=None):
291 292
    projects = Project.objects.filter(query)
292 293

  
293
    if not request_user.is_project_admin():
294
        membs = request_user.projectmembership_set.any_accepted()
294
    if mode == "member":
295
        membs = request_user.projectmembership_set.\
296
            actually_accepted_and_active()
295 297
        memb_projects = membs.values_list("project", flat=True)
296 298
        is_memb = Q(id__in=memb_projects)
297
        owned = Q(owner=request_user)
298
        active = (Q(state=Project.NORMAL) &
299
                  Q(private=False))
300
        projects = projects.filter(is_memb | owned | active)
299
        projects = projects.filter(is_memb)
300
    elif mode == "default":
301
        if not request_user.is_project_admin():
302
            membs = request_user.projectmembership_set.any_accepted()
303
            memb_projects = membs.values_list("project", flat=True)
304
            is_memb = Q(id__in=memb_projects)
305
            owned = Q(owner=request_user)
306
            active = (Q(state=Project.NORMAL) &
307
                      Q(private=False))
308
            projects = projects.filter(is_memb | owned | active)
309
    else:
310
        raise faults.BadRequest("Unrecognized mode '%s'." % mode)
301 311
    return projects.select_related("last_application")
302 312

  
303 313

  
b/snf-astakos-app/astakos/im/models.py
1892 1892
            q &= Q(project__in=projects)
1893 1893
        return self.filter(q)
1894 1894

  
1895
    def actually_accepted_and_active(self):
1896
        q = self.model.Q_ACTUALLY_ACCEPTED
1897
        q &= Q(project__state=Project.NORMAL)
1898
        return self.filter(q)
1899

  
1895 1900
    def initialized(self, projects=None):
1896 1901
        q = Q(initialized=True)
1897 1902
        if projects is not None:

Also available in: Unified diff