예제 #1
0
파일: main.py 프로젝트: psimakov/pyaedj
  def action(unused_user, roles):
    members = dao.Members()
    is_admin = ROLE_ADMIN in roles
    results = []

    # add registered members
    for member in members.query_members():
      if len(results) > MAX_MEMBERS_IN_LIST:
        break

      settings = json.loads(member.data)
      profile = settings.get('profile', None)
      registration = settings.get('registration', None)

      # check rights
      is_public = profile and (
          profile.get('visibility') == PROFILE_VISIBILITY_PUBLIC)
      if not(is_public or is_admin):
        continue

      # add projection to output
      results.append({
          'slug': member.slug,
          'profile': profile,
          'registration': registration,
      })

    return results
예제 #2
0
파일: main.py 프로젝트: psimakov/pyaedj
  def action(user, unused_roles):
    members = dao.Members()

    # load member current settings
    member_uid = get_uid_for(user)
    member = members.get_or_create_member(member_uid)
    version = ETag.from_request(ETag.ETAG_NAME_SETTINGS)
    if not version:
      version = member.version

    # update registration portion of settings
    settings = json.loads(member.data)
    settings['registered'] = True
    settings['registration'] = {
        'displayName': user['displayName'],
        'photoURL': user['photoURL'],
        'email': user['email'],
        'created_on': dao.datetime_to_str(dao.timezone_aware_now()),
    }

    # save to storage
    try:
      members.update(member_uid, json.dumps(settings), version=version)
    except dao.ETagError as error:
      flask.abort(format_api_response(400, error.to_json_serializable()))
예제 #3
0
파일: main.py 프로젝트: NeoTim/pyaedj
def with_user(method):
    """Executed method with current user."""
    user = get_user_for_request(flask.request)
    if not user:
        return flask.Response('Unauthorized.', 401)
    roles, status = get_roles_for(user)

    result = None
    if method:
        if not roles:
            return flask.Response('Access denied.', 403)
        try:
            result = method(user, roles)
        except HTTPException:  # these are flask.abort; ok
            raise
        except dao.BusinessRuleError:  # these are our dao.* exceptions; ok
            raise
        except Exception:  # pylint: disable=broad-except
            logging.error('Exception:\n%s', traceback.format_exc())
            flask.abort(
                format_api_response(
                    500,
                    dao.BusinessRuleError(
                        'Internal server error. Please try again later.').
                    to_json_serializable()))

    member = dao.Members().get_or_create_member(get_uid_for(user))

    user['roles'] = roles
    user['settings'] = json.loads(member.data)
    user['slug'] = member.slug
    user['status'] = status
    user[ETag.ETAG_NAME_SETTINGS] = member.version

    response = {
        'app': {
            'schema': APP_SCHEMA,
        },
        'user': user,
        'server': get_server_info(),
    }

    if result or result == []:  # pylint: disable=g-explicit-bool-comparison
        response['result'] = result

    return format_api_response(200, response)
예제 #4
0
파일: main.py 프로젝트: psimakov/pyaedj
  def action(user, unused_roles):
    members = dao.Members()

    # load member current settings
    member_uid = get_uid_for(user)
    member = members.get_or_create_member(member_uid)
    version = ETag.from_request(ETag.ETAG_NAME_SETTINGS)
    if not version:
      version = member.version

    # update profile portion of settings
    settings = json.loads(member.data)
    settings['profile'] = profile

    # save to storage
    try:
      members.update(member_uid, json.dumps(settings), version=version)
    except dao.ETagError as error:
      flask.abort(format_api_response(400, error.to_json_serializable()))
예제 #5
0
파일: dao_test.py 프로젝트: psimakov/pyaedj
 def setUp(self):
     super(PostsAndVotesBaseTestSuite, self).setUp()
     self.members = dao.Members()
     self.posts = dao.Posts()
     self.votes = dao.Votes()
예제 #6
0
파일: dao_test.py 프로젝트: psimakov/pyaedj
 def test_get_or_create_member(self):
     members = dao.Members()
     self.assertEqual(0, len(list(members.query_members())))
     members.get_or_create_member('member-1')
     self.assertEqual(1, len(list(members.query_members())))