Ejemplo n.º 1
0
    def community_users(self, request):
        user = auth_user(self.request_state.headers)
        community_userroles = []

        if user:
            community = Community.getCommunityFromTeamKey(request.account_type)
            if community and (UserRole.getCircleLevel(user, community) > 0):
                community_userroles = UserRole.query().filter(ndb.AND(UserRole.community == community.key,
                                                                      UserRole.circle_level > 0)
                                                              ).fetch(projection=[UserRole.user])

        users = []
        for community_userrole in community_userroles:
            current_user = community_userrole.user.get()
            users.append(UserMessage(id=current_user.key.id(),
                                     user_email=current_user.user_email,
                                     display_name=current_user.display_name,
                                     image_url=current_user.image_url))

        # removing auth_user
        [ users.remove(user_info) for user_info in users if user_info.user_email == user.user_email ]

        # sorting users alphabetically
        users = sorted(users, key=lambda user_info: user_info.display_name.lower())

        return UserListMessage(user_list=users)
Ejemplo n.º 2
0
    def insert_anno(cls, message, user):
        """
        create a new anno model from request message.
        """
        itemCount = 0
        appinfo, community = getAppAndCommunity(message, user)

        circle_level = 0
        if community:
            itemCount = cls.countItemsForTeam(community.key)
            circle_level = UserRole.getCircleLevel(user, community)
            if message.circle_level and (message.circle_level <= circle_level):
                circle_level = message.circle_level

        entity = cls(anno_text=message.anno_text, anno_type=message.anno_type,
                     level=message.level, device_model=message.device_model,
                     os_name=message.os_name, os_version=message.os_version,
                     creator=user.key, draw_elements=message.draw_elements,
                     image=message.image, screenshot_is_anonymized=message.screenshot_is_anonymized,
                     geo_position=message.geo_position, flag_count=0, vote_count=0,
                     followup_count=0, latitude=message.latitude, longitude=message.longitude,
                     screen_info=message.screen_info)

        # set appinfo and community
        entity.app = appinfo.key
        entity.community = community.key if community else None
        entity.circle_level = circle_level

        # set created time if provided in the message.
        if message.created is not None:
            entity.created = message.created

        # use google map api to retrieve country information and save into datastore.
        if message.latitude is not None and message.longitude is not None:
            entity.country = get_country_by_coordinate(message.latitude, message.longitude)

        # set last update time & activity
        entity.last_update_time = datetime.datetime.now()
        entity.last_activity = 'UserSource'
        entity.last_update_type = 'create'
        anno_key = entity.put()

        entity.anno_id = anno_key.id()
        entity.put()

        # update user anno state
        from model.userannostate import UserAnnoState
        UserAnnoState.insert(user=user, anno=entity, type=AnnoActionType.CREATED)

        if community:
            itemCount = cls.query_count_by_community(community_key=community.key)
            if itemCount == 0:
                send_first_anno_email(community.name, user.display_name)

        return entity
Ejemplo n.º 3
0
    def create_sdk_team(cls, message, pricing_plan=False, stripe_token=None):
        team_key = message.team_key
        app_name = message.app.name
        community_name = message.community_name or app_name
        plan = message.plan or PlanType.BASIC

        app = AppInfo.query().filter(AppInfo.lc_name == app_name.lower()).get()
        if not app:
            appinfo_message = AppInfoMessage()
            appinfo_message.name = app_name
            appinfo_message.icon_url = message.app.icon_url
            appinfo_message.version = message.app.version
            app = AppInfo.insert(appinfo_message)

        from helper.utils import md5
        community_message = CommunityMessage(name=community_name,
                                             team_key=team_key,
                                             team_secret=md5(community_name.lower()),
                                             plan=plan)
        community_message.user = UserMessage(user_email=message.admin_user.user_email,
                                             display_name=message.admin_user.display_name,
                                             password=message.admin_user.password)
        community, user = cls.insert(community_message, getCommunity=True)

        communities_message = []
        if community and app:
            if not app.key in community.apps:
                community.apps.append(app.key)
                community.put()

            # response message
            community_message = CommunityAdminMasterMessage()
            community_message.community_name = community.name
            community_message.team_key = community.team_key
            community_message.team_secret = community.team_secret
            # community_message.team_hash = community.team_hash
            community_message.app_name = app.name
            community_message.app_icon = app.icon_url

            community_message.users = []
            from model.userrole import UserRole

            user_message = UserAdminMasterMessage()
            user_message.display_name = user.display_name
            user_message.user_email = user.user_email
            user_message.password_present = True if user.password else False
            user_message.role = UserRole.getRole(user, community)
            user_message.image_url = user.image_url

            if community.circles:
                user_message.circle = community.circles.get(str(UserRole.getCircleLevel(user, community)))

            community_message.users.append(user_message)
            communities_message.append(community_message)
            registration_successful = True

            if pricing_plan:
                if stripe_token:
                    payment_success = StripePayment.create_charge(stripe_token, community.key, plan)
                    if not payment_success:
                        registration_successful = False
                else:
                    registration_successful = False

            if registration_successful:
                from helper.utils import send_created_team_email
                from helper.utils import send_access_team_email
                send_created_team_email(community.name, user.display_name)
                send_access_team_email(user.user_email, community.team_hash,
                                       community.name, community.team_key,
                                       community.team_secret)
            else:
                community.key.delete()
                communities_message = []

        return communities_message