def getAppAndCommunity(message, user): if message.team_key: community = Community.getCommunityFromTeamKey(team_key=message.team_key) appinfo = getAppInfo(community.key.id()) elif message.app_name: appinfo = AppInfo.get(name=message.app_name, platform=message.platform_type) community = None if appinfo is None: appInfoMessage = AppInfoMessage(name=message.app_name, version=message.app_version, platform=message.platform_type) appinfo = AppInfo.insert(appInfoMessage) else: app_community = getCommunityForApp(id=appinfo.key.id()) if app_community and isMember(app_community, user): community = app_community elif message.community_name: community_id = Community.getCommunity(community_name=message.community_name).id community = Community.get_by_id(community_id) appinfo = getAppInfo(community_id) else: raise endpoints.BadRequestException("Please specify a community or app") return appinfo, community
def getCommunityForApp(id=None, app_name=None): if id: app = AppInfo.get_by_id(id) elif app_name: app = AppInfo.get(name=app_name) app_community = None if app: communities = Community.query().fetch() for community in communities: if app.key in community.apps: app_community = community break return app_community
def anno_list(self, request): """ Exposes an API endpoint to retrieve a list of anno. """ user = auth_user(self.request_state.headers) limit = 10 if request.limit is not None: limit = request.limit is_plugin = request.is_plugin or False curs = None if request.cursor is not None: try: curs = Cursor(urlsafe=request.cursor) except BadValueError: raise endpoints.BadRequestException('Invalid cursor %s.' % request.cursor) select_projection = None if request.select is not None: select_projection = request.select.split(',') if request.query_type == AnnoQueryType.CREATED: return Anno.query_by_app_by_created(request.app, limit, select_projection, curs, user) elif request.query_type == AnnoQueryType.VOTE_COUNT: return Anno.query_by_vote_count(request.app, user) elif request.query_type == AnnoQueryType.FLAG_COUNT: return Anno.query_by_flag_count(request.app, user) elif request.query_type == AnnoQueryType.ACTIVITY_COUNT: return Anno.query_by_activity_count(request.app, user) elif request.query_type == AnnoQueryType.LAST_ACTIVITY: return Anno.query_by_last_activity(request.app, user) elif request.query_type == AnnoQueryType.COUNTRY: return Anno.query_by_country(request.app, user) elif request.query_type == AnnoQueryType.COMMUNITY: community = Community.get_by_id(request.community) return Anno.query_by_community(community, limit, select_projection, curs, user) elif request.query_type == AnnoQueryType.APP: app = AppInfo.get(request.app) return Anno.query_by_app(app, limit, select_projection, curs, user) else: return Anno.query_by_page(limit, select_projection, curs, user, is_plugin)