示例#1
0
def create_teams():
    team_key = ""
    app_name = ""
    community_name = ""
    admin_user_email = ""
    other_users_email = []

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

    community = Community.getCommunityFromTeamKey(team_key=team_key)
    if not community:
        community_message = CommunityMessage(name=community_name,
                                             team_key=team_key,
                                             team_secret=md5(community_name.lower()))
        community_message.user = UserMessage(user_email=admin_user_email)
        Community.insert(community_message)
        community = Community.getCommunityFromTeamKey(team_key=team_key)

    if community and app:
        if not app.key in community.apps:
            community.apps.append(app.key)
            community.put()

    for user_email in other_users_email:
        user = User.find_user_by_email(email=user_email, team_key=team_key)
        if not user:
            user = User.insert_user(user_email, account_type=team_key, image_url="")
        userrole = UserRole.insert(user, community)
示例#2
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