Beispiel #1
0
def user(request):
    """
    View configuration for the public user page.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    match_dict = request.matchdict
    LOG.debug("Return public user page: %s", match_dict)

    uid = match_dict.get('uid', 0)
    LOG.debug("User being shown: %s", uid)

    if not is_integer(uid):
        raise HTTPNotFound

    current_user = DBDiscussionSession.query(User).get(uid)
    if current_user is None:
        LOG.error("No user found: %s", uid)
        raise HTTPNotFound()

    ui_locales = get_language_from_cookie(request)
    user_dict = get_information_of(current_user, ui_locales)

    db_user_of_request = DBDiscussionSession.query(User).filter_by(nickname=request.authenticated_userid).first()
    can_send_notification = False
    if db_user_of_request:
        can_send_notification = current_user.uid not in [db_user_of_request.uid, 1]

    prep_dict = main_dict(request, user_dict['public_nick'])
    prep_dict.update({
        'user': user_dict,
        'can_send_notification': can_send_notification
    })
    return prep_dict
Beispiel #2
0
def queue_details(request):
    """
    View configuration for the review content.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Queue Details %s / %s", request.matchdict, request.params)
    ui_locales = get_language_from_cookie(request)
    _tn = Translator(ui_locales)

    queue_name = request.validated['queue']
    db_user = request.validated['user']
    application_url = request.application_url

    queue = subclass_by_name(queue_name)
    adapter = QueueAdapter(queue=queue(),
                           db_user=db_user,
                           application_url=application_url,
                           translator=_tn)
    subpage_dict = adapter.get_subpage_of_queue(request.session, queue_name)
    request.session.update(subpage_dict['session'])

    prep_dict = main_dict(request, _tn.get(get_title_by_key(queue_name)))
    prep_dict.update({
        'extras': request.decorated['extras'],
        'subpage': subpage_dict,
        'lock_time': dbas.review.queue.max_lock_time_in_sec
    })
    return prep_dict
Beispiel #3
0
def settings(request):
    """
    View configuration for the personal settings view. Only logged in user can reach this page.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Show settings %s", request.params)

    ui_locales = get_language_from_cookie(request)
    old_pw, new_pw, confirm_pw, message = '', '', '', ''
    success, error = False, False
    db_user: User = request.validated['user']

    if 'form.passwordchange.submitted' in request.params:
        old_pw = escape_string(request.params['passwordold'])
        new_pw = escape_string(request.params['password'])
        confirm_pw = escape_string(request.params['passwordconfirm'])

        message, success = change_password(db_user, old_pw, new_pw, confirm_pw, ui_locales)
        error = not success

    settings_dict = DictionaryHelper(ui_locales).prepare_settings_dict(success, old_pw, new_pw, confirm_pw, error,
                                                                       message, db_user, request.application_url,
                                                                       request.decorated['extras']['use_with_ldap'])

    prep_dict = main_dict(request, Translator(ui_locales).get(_.settings))
    prep_dict.update({
        'settings': settings_dict
    })
    return prep_dict
Beispiel #4
0
def index(request):
    """
    View configuration for the review index.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Review Index: %s / %s", request.matchdict, request.params)
    db_user = request.validated['user']

    _tn = Translator(get_language_from_cookie(request))
    adapter = QueueAdapter(db_user=db_user,
                           main_page=request.application_url,
                           translator=_tn)
    review_dict = adapter.get_review_queues_as_lists()
    count, all_rights = get_reputation_of(db_user)

    prep_dict = main_dict(request, _tn.get(_.review))
    prep_dict.update({
        'review': review_dict,
        'privilege_list': get_privilege_list(_tn),
        'reputation_list': get_reputation_reasons_list(_tn),
        'reputation': {
            'count': count,
            'has_all_rights': all_rights
        }
    })
    return prep_dict
Beispiel #5
0
def batman(request):
    """
    You are not the user D-BAS deserves!

    :param request: current request of the server
    """
    LOG.debug("NANANANANNANANANANANANANANANANA BATMAAAAAAN!")
    return main_dict(request, 'Batman')
Beispiel #6
0
def faq(request):
    """
    View configuration for FAQs.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Return FAQ view.")
    return main_dict(request, 'FAQ')
Beispiel #7
0
def docs(request):
    """
    View configuration for the documentation.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Return docs view.")
    return main_dict(request,
                     Translator(get_language_from_cookie(request)).get(_.docs))
Beispiel #8
0
def experiment(request):
    """
    View configuration for fieldtest.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Return experiment Information view.")
    ui_locales = get_language_from_cookie(request)
    return main_dict(request, Translator(ui_locales).get(_.fieldtest))
Beispiel #9
0
def notifications(request):
    """
    View configuration for the notification view. Only logged in user can reach this page.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Show Notifications")
    _tn = Translator(get_language_from_cookie(request))
    return main_dict(request, _tn.get(_.message))
Beispiel #10
0
def privacy(request):
    """
    View configuration for the privacy.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Return privacy policy view.")
    return main_dict(
        request,
        Translator(get_language_from_cookie(request)).get(_.privacy_policy))
Beispiel #11
0
def discussion_overview(request):
    """

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value whether the user is logged in
    """
    LOG.debug("Return a discussion overview dictionary")
    ui_locales = get_language_from_cookie(request)
    issue_dict = get_issues_overview_for(request.validated['user'],
                                         request.application_url)

    prep_dict = main_dict(request, Translator(ui_locales).get(_.myDiscussions))
    modifiy_issue_main_url(issue_dict)
    prep_dict.update({'issues': issue_dict})
    return prep_dict
Beispiel #12
0
def reputation(request):
    """
    View configuration for the review reputation_borders.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Reputation Borders view. %s / %s", request.matchdict,
              request.params)
    ui_locales = get_language_from_cookie(request)
    _tn = Translator(ui_locales)

    reputation_dict = get_history_of(request.validated['user'], _tn)
    prep_dict = main_dict(request, _tn.get(_.reputation))
    prep_dict.update({'reputation': reputation_dict})
    return prep_dict
Beispiel #13
0
def start(request):
    """
    View configuration for the initial discussion overview.

    :param request: request of the web server
    :return: dictionary
    """
    LOG.debug("Return configuration for initial discussion overview")
    ui_locales = get_language_from_cookie(request)
    issue_dict = issue_handler.get_issues_overview_on_start(
        request.validated['user'])
    prep_dict = main_dict(request,
                          Translator(ui_locales).get(_.discussionStart))

    prep_dict.update(issue_dict)
    return prep_dict
Beispiel #14
0
def ongoing(request):
    """
    View configuration for the current reviews.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Current reviews view. %s / %s", request.matchdict,
              request.params)
    ui_locales = get_language_from_cookie(request)
    _tn = Translator(ui_locales)

    specific_history = get_ongoing_reviews(request.application_url,
                                           request.validated['user'], _tn)
    prep_dict = main_dict(request, _tn.get(_.review_ongoing))
    prep_dict.update({'history': specific_history})
    return prep_dict
Beispiel #15
0
def imprint(request):
    """
    View configuration for the imprint.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Return imprint view.")
    # add version of pyramid
    request.decorated['extras'].update(
        {'pyramid_version': pkg_resources.get_distribution('pyramid').version})

    prep_dict = main_dict(
        request,
        Translator(get_language_from_cookie(request)).get(_.imprint))
    prep_dict.update({'imprint': get_changelog(5)})
    return prep_dict
Beispiel #16
0
def notfound(request):
    """
    View configuration for the 404 page.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    if request.path.startswith('/api'):
        return HTTPNotFound({'path': request.path, 'message': 'Not Found'})

    # check cornice routes
    cornice_services = ['/admin', '/docs']
    for service in cornice_services:
        if request.path.startswith(service):
            LOG.debug("Redirect to %s/", service)
            return HTTPFound(location=service + '/')

    LOG.debug(
        "Configuration for 404 page in %s-request. Path: %s, view name: %s, matchdict: %s, params: %s",
        request.method, request.path, request.view_name, request.matchdict,
        request.params)

    # clear url
    path = request.path
    if path.startswith('/404/'):
        path = path[4:]

    # prepare return dict
    param_error = 'param_error' in request.params and request.params[
        'param_error'] == 'true'
    revoked_content = 'revoked_content' in request.params and request.params[
        'revoked_content'] == 'true'

    request.response.status = 404

    prep_dict = main_dict(request, '404 Error')
    prep_dict.update({
        'page_notfound_viewname': path,
        'param_error': param_error,
        'revoked_content': revoked_content,
        'discussion': {
            'broke_limit': False
        }
    })
    return prep_dict
Beispiel #17
0
def index(request):
    """
    View configuration for the overview page

    :param request: current request of the server
    :return: HTTP 200 with several information
    """
    LOG.debug("Return index page. %s", request.matchdict)

    set_language_for_visit(request)
    session_expired = 'session_expired' in request.params and request.params[
        'session_expired'] == 'true'

    prep_dict = main_dict(request, name + ' ' + full_version)
    prep_dict.update({
        'session_expired': session_expired,
    })
    return prep_dict
Beispiel #18
0
def news(request):
    """
    View configuration for the news.

    :param request: current request of the server
    :return: dictionary with title and project name as well as a value, weather the user is logged in
    """
    LOG.debug("Return news view.")

    ui_locales = get_language_from_cookie(request)
    db_user = request.validated['user']
    is_author = db_user.is_admin() or db_user.is_author()

    prep_dict = main_dict(request, 'News')
    prep_dict.update({
        'is_author': is_author,
        'news': news_handler.get_news(ui_locales)
    })
    return prep_dict