コード例 #1
0
    def get_search_results(id, page):
        page = int(page)
        requester = get_requesting_user()
        if requester is None:
            response = base_routes.make_not_authorized_response()
        elif not is_integer(id):
            response = base_routes.make_bad_request_response()
        else:
            search = store.session.query(Search).filter_by(id=id).first()
            if search is None:
                response = base_routes.make_not_found_response()
            else:
                if search.has_admin_rights(requester):
                    matching_searches = search_utils.find_matching_searches(
                        search, page)

                    serialized = [
                        search.serialize(
                            requester,
                            exclude=[],
                        ) for search in matching_searches
                    ]
                    response_data = {'data': serialized}
                    response = jsonify(response_data)
                else:
                    response = base_routes.make_forbidden_response()
        return response
コード例 #2
0
    def get_search_results(id, page):
        page = int(page)
        requester = get_requesting_user()
        if requester is None:
            response = base_routes.make_not_authorized_response()
        elif not is_integer(id):
            response = base_routes.make_bad_request_response()
        else:
            search = store.session.query(Search).filter_by(id=id).first()
            if search is None:
                response = base_routes.make_not_found_response()
            else:
                if search.has_admin_rights(requester):
                    matching_searches = search_utils.find_matching_searches(search, page)

                    serialized = [
                        search.serialize(
                            requester,
                            exclude=[],
                        ) for search in matching_searches
                    ]
                    response_data = {'data': serialized}
                    response = jsonify(response_data)
                else:
                    response = base_routes.make_forbidden_response()
        return response
コード例 #3
0
 def statistics():
     requester = get_requesting_user()
     if requester is None:
         response = base_routes.make_not_authorized_response()
     elif not requester.is_administrator:
         response = base_routes.make_forbidden_response()
     else:
         yesterday = Statistic.date_yesterday()
         response_data = {'data': {}}
         for days_ago in range(30):
             date = yesterday - datetime.timedelta(days=days_ago)
             stats = Statistic.get_statistics(date)
             response_data['data'][time_format.to_iso8601(date)] = stats
         response = jsonify(response_data)
     return response
コード例 #4
0
 def statistics():
     requester = get_requesting_user()
     if requester is None:
         response = base_routes.make_not_authorized_response()
     elif not requester.is_administrator:
         response = base_routes.make_forbidden_response()
     else:
         yesterday = Statistic.date_yesterday()
         response_data = {'data': {}}
         for days_ago in range(30):
             date = yesterday - datetime.timedelta(days=days_ago)
             stats = Statistic.get_statistics(date)
             response_data['data'][time_format.to_iso8601(date)] = stats
         response = jsonify(response_data)
     return response
コード例 #5
0
 def userbyemail(email):
     requester = get_requesting_user()
     if requester is None:
         response = base_routes.make_not_authorized_response()
     elif requester.email != email:
         response = base_routes.make_forbidden_response()
     else:
         users = store.session.query(User).filter(User.email == email, User.active == True).all()
         if len(users) > 1:
             logger.error('More than one active user with the same email - {}'.format(email))
             user = users[0]
         elif len(users) == 0:
             user = None
         else:
             user = users[0]
         if user is None:
             response = base_routes.make_not_found_response()
         else:
             response = base_routes.make_single_response(requester, user)
     return response
コード例 #6
0
 def userbyemail(email):
     requester = get_requesting_user()
     if requester is None:
         response = base_routes.make_not_authorized_response()
     elif requester.email != email:
         response = base_routes.make_forbidden_response()
     else:
         users = store.session.query(User).filter(
             User.email == email, User.active == True).all()
         if len(users) > 1:
             logger.error(
                 'More than one active user with the same email - {}'.
                 format(email))
             user = users[0]
         elif len(users) == 0:
             user = None
         else:
             user = users[0]
         if user is None:
             response = base_routes.make_not_found_response()
         else:
             response = base_routes.make_single_response(requester, user)
     return response