Пример #1
0
    def get_circle_users(self, request):
        roles = [UserRoleType.MEMBER, UserRoleType.ADMIN]
        community = Community.getCommunityFromTeamKey(request.team_key)

        circle_list_message = []
        for circle_value, circle_name in community.circles.items():
            circle_message = CommunityCircleMembersMessage()
            circle_message.circle_name = circle_name
            circle_message.users = []

            for userrole in UserRole.getUsersByCircle(community.key, int(circle_value)):
                user = userrole.user.get()
                if user and (user.account_type == community.team_key):
                    if user.user_email.split("@")[1] == "devnull.usersource.io":
                        break

                    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.role
                    user_message.image_url = user.image_url
                    circle_message.users.append(user_message)

            circle_list_message.append(circle_message)

        return CommunityCircleMembersListMessage(circle_list=circle_list_message, roles=roles)
Пример #2
0
    def get_admin_master_data(self, request):
        communities_message = []
        query = Community.query().filter(Community.team_secret != None)

        if request.team_key:
            query = query.filter(Community.team_key == request.team_key)

        communities = query.fetch()

        for community in communities:
            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.plan = community.plan

            app = community.apps[0].get()
            if app:
                community_message.app_name = app.name
                community_message.app_icon = app.icon_url

            community_message.users = []
            if request.get_user_list:
                for userrole in UserRole.community_user_list(community_key=community.key):
                    user = userrole.user.get()
                    if user and (user.account_type == community.team_key):
                        if user.user_email.split("@")[1] == "devnull.usersource.io":
                            break

                        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.role
                        user_message.image_url = user.image_url
                        if community.circles:
                            user_message.circle = community.circles.get(str(userrole.circle_level))
                        community_message.users.append(user_message)

            communities_message.append(community_message)

        return CommunityAdminMasterListMessage(communities=communities_message)
Пример #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