Пример #1
0
def discussion_list_view(request):
    request.session.pop('discussion')
    user_id = authenticated_userid(request) or Everyone
    user = None
    if user_id != Everyone:
        user = User.get(user_id)
    roles = get_roles(user_id)
    context = get_default_context(request)
    context['discussions'] = []
    # Show even anonymous users every discussion one has access to if
    # authenticated, so they can login and read them
    discussions = discussions_with_access(Authenticated if user_id ==
                                          Everyone else user_id)
    for discussion in discussions:
        discussionFrontendUrls = FrontendUrls(discussion)
        discussion_context = {
            'topic': discussion.topic,
            'slug': discussion.slug,
            'url': discussionFrontendUrls.get_discussion_url()
        }
        if user_has_permission(discussion.id, user_id, P_ADMIN_DISC):
            discussion_context[
                'admin_url'] = discussionFrontendUrls.get_discussion_edition_url(
                )
            discussion_context['permissions_url'] = request.route_url(
                'discussion_permissions', discussion_id=discussion.id)
        context['discussions'].append(discussion_context)
    if R_SYSADMIN in roles:
        context['discussions_admin_url'] = request.route_url(
            'discussion_admin')
        context['permissions_admin_url'] = request.route_url(
            'general_permissions')
    context['user'] = user
    return context
Пример #2
0
def discussion_list_view(request):
    user_id = authenticated_userid(request) or Everyone
    user = None
    if user_id != Everyone:
        user = User.get(user_id)
    roles = get_roles(user_id)
    context = get_default_context(request)
    context['discussions'] = []
    #Show even anonymous users every discussion one has access to if 
    #authenticated, so they can login and read them
    discussions = discussions_with_access(Authenticated if user_id == Everyone else user_id)
    for discussion in discussions:
        discussionFrontendUrls = FrontendUrls(discussion)
        discussion_context = {
            'topic': discussion.topic,
            'slug': discussion.slug,
            'url': discussionFrontendUrls.get_discussion_url()
        }
        if user_has_permission(discussion.id, user_id, P_ADMIN_DISC):
            discussion_context['admin_url'] = discussionFrontendUrls.get_discussion_edition_url()
            discussion_context['permissions_url'] = request.route_url(
                'discussion_permissions', discussion_id=discussion.id)
        context['discussions'].append(discussion_context)
    if R_SYSADMIN in roles:
        context['discussions_admin_url'] = request.route_url('discussion_admin')
        context['permissions_admin_url'] = request.route_url('general_permissions')
    context['user'] = user
    return context
Пример #3
0
def etalab_get_discussions(request):
    # According to the Etalab API specification, an Instance object must have the following fields:
    # - url: we send discussion.get_url(). Note: a discussion may have 2 URLs (HTTP and HTTPS). For this, see discussion.get_discussion_urls()
    # - name: we use discussion.topic
    # - adminEmail: email of the discussion creator, who made the API request to create a discusison (so in our case the field will not show if the discussion has been created by another mean)
    # - adminName: name of this guy, also provided in the discussion creation request (so in our case the field will not show if the discussion has been created by another mean)
    # - createdAt: creation date
    # We also send the following optional fields:
    # - id: this field is not in specification's optional nor mandatory fields
    # - status: "running"
    # - metadata: metadata.creation_date => will probably be renamed, see above
    view = "etalab"
    user_id = request.authenticated_userid or Everyone
    permissions = get_permissions(user_id, None)
    if P_READ not in permissions:
        raise HTTPUnauthorized()
    discussions = discussions_with_access(user_id)
    return {"items": [discussion.generic_json(view, user_id, permissions)
                      for discussion in discussions]}
Пример #4
0
def etalab_get_discussions(request):
    # According to the Etalab API specification, an Instance object must have the following fields:
    # - url: we send discussion.get_url(). Note: a discussion may have 2 URLs (HTTP and HTTPS). For this, see discussion.get_discussion_urls()
    # - name: we use discussion.topic
    # - adminEmail: email of the discussion creator, who made the API request to create a discusison (so in our case the field will not show if the discussion has been created by another mean)
    # - adminName: name of this guy, also provided in the discussion creation request (so in our case the field will not show if the discussion has been created by another mean)
    # - createdAt: creation date
    # We also send the following optional fields:
    # - id: this field is not in specification's optional nor mandatory fields
    # - status: "running"
    # - metadata: metadata.creation_date => will probably be renamed, see above
    view = "etalab"
    user_id = request.authenticated_userid or Everyone
    permissions = get_permissions(user_id, None)
    if P_READ not in permissions:
        raise HTTPUnauthorized()
    discussions = discussions_with_access(user_id)
    return {
        "items": [
            discussion.generic_json(view, user_id, permissions)
            for discussion in discussions
        ]
    }