Esempio n. 1
0
def group_add_member(request, username):
    teamUser = GsuserManager.get_user_by_name(username)
    team_group_id = int(request.POST.get('team_group_id', '0'))
    teamGroup = TeamManager.get_teamGroup_by_id(team_group_id)
    if not teamGroup or teamGroup.team_user_id != teamUser.id:
        return _response_not_manage_rights(request)
    member_username = request.POST.get('member_username', '')
    member_user = GsuserManager.get_user_by_name(member_username)
    if not member_user:
        return json_failed(500, u'没有该用户名')
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(
        teamUser.id, member_user.id)
    if not teamMember:
        return json_failed(
            500,
            u'用户 %s 还没有加入团队帐号 %s' % (member_user.username, teamUser.username))
    groupMember = TeamManager.get_groupMember_by_teamGroupId_memberUserId(
        teamGroup.id, member_user.id)
    if groupMember:
        return json_success(u'用户 %s 已经在该组' % member_user.username)
    groupMember = GroupMember(team_user_id=teamUser.id,
                              group_id=teamGroup.id,
                              member_user_id=member_user.id)
    groupMember.save()
    return json_success(u'成功添加用户 %s 到组 %s' %
                        (member_user.username, teamGroup.name))
Esempio n. 2
0
def add_member(request, username):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    teamMember = None
    username_or_email = request.POST.get('username_or_email', '')
    if '@' in username_or_email:
        user = GsuserManager.get_user_by_email(username_or_email)
        if not user:
            ref_hash = '%032x' % random.getrandbits(128)
            ref_message = u'用户 %s 邀请您注册Gitshell,成为团队 %s 的成员' % (
                request.user.username, username)
            userViaRef = UserViaRef(email=username_or_email,
                                    ref_type=REF_TYPE.VIA_TEAM_MEMBER,
                                    ref_hash=ref_hash,
                                    ref_message=ref_message,
                                    first_refid=teamUser.id,
                                    first_refname=teamUser.username)
            userViaRef.save()
            join_url = 'https://gitshell.com/join/ref/%s/' % ref_hash
            Mailer().send_join_via_team_addmember(request.user, teamUser,
                                                  username_or_email, join_url)
            return json_failed(301,
                               u'邮箱 %s 未注册,已经发送邮件邀请对方注册' % username_or_email)
        teamMember = TeamManager.add_teamMember_by_email(
            teamUser, username_or_email)
    else:
        teamMember = TeamManager.add_teamMember_by_username(
            teamUser, username_or_email)
    if not teamMember:
        return json_failed(404, u'没有相关用户,不能是团队帐号')
    return json_success(u'成功添加用户')
Esempio n. 3
0
def email_add(request):
    is_verify = 0
    email = request.POST.get('email')
    userEmail = GsuserManager.add_useremail(request.user, email, is_verify)
    if not userEmail:
        return json_failed(500, u'绑定邮箱个数最多50个,确定邮箱格式正确和未被绑定')
    return json_success(u'成功添加邮箱 %s' % email)
Esempio n. 4
0
def email_add(request):
    is_verify = 0
    email = request.POST.get('email')
    userEmail = GsuserManager.add_useremail(request.user, email, is_verify)
    if not userEmail:
        return json_failed(500, u'绑定邮箱个数最多50个,确定邮箱格式正确和未被绑定')
    return json_success(u'成功添加邮箱 %s' % email)
Esempio n. 5
0
def remove_member(request, username):
    (manage_teamMember, teamMember) = _get_teamMember_by_manageTeamMemberId(request)
    teamMembers = TeamManager.list_teamMember_by_teamUserId(teamMember.team_user_id)
    if _has_other_admin_teamMember(request, manage_teamMember, teamMembers):
        manage_teamMember.visibly = 1
        manage_teamMember.save()
        return json_success(u'删除用户成功')
    return json_failed(500, u'删除用户失败,一个团队帐号至少需要保留一个管理员')
Esempio n. 6
0
def cancal_admin(request, username):
    (manage_teamMember, teamMember) = _get_teamMember_by_manageTeamMemberId(request)
    teamMembers = TeamManager.list_teamMember_by_teamUserId(teamMember.team_user_id)
    if _has_other_admin_teamMember(request, manage_teamMember, teamMembers):
        manage_teamMember.is_admin = 0
        manage_teamMember.save()
        return json_success(u'解除管理员权限')
    return json_failed(500, u'解除管理员失败,一个团队帐号至少需要保留一个管理员')
Esempio n. 7
0
def unwatch(request, user_name):
    gsuserprofile = GsuserManager.get_userprofile_by_name(user_name)
    if gsuserprofile is None:
        message = u'用户不存在'
        return json_failed(404, message)
    if not RepoManager.unwatch_user(request.userprofile, gsuserprofile):
        message = u'取消关注失败,可能用户未被关注'
        return json_failed(500, message)
    return json_success(u'成功取消关注用户 %s' % user_name)
Esempio n. 8
0
def watch(request, user_name):
    gsuserprofile = GsuserManager.get_userprofile_by_name(user_name)
    if gsuserprofile is None:
        message = u'用户不存在'
        return json_failed(404, message)
    if not RepoManager.watch_user(request.userprofile, gsuserprofile):
        message = u'关注失败,关注数量超过限制或者用户不允许关注'
        return json_failed(500, message)
    return json_success(u'成功关注用户 %s' % user_name)
Esempio n. 9
0
def recommend_delete(request, user_name, recommend_id):
    gsuser = GsuserManager.get_user_by_name(user_name)
    if gsuser is None:
        raise Http404
    recommend = GsuserManager.get_recommend_by_id(recommend_id)
    if recommend.user_id == request.user.id:
        recommend.visibly = 1
        recommend.save()
    return json_success(u'成功删除评论')
Esempio n. 10
0
def watch(request, user_name):
    gsuserprofile = GsuserManager.get_userprofile_by_name(user_name)
    if gsuserprofile is None:
        message = u'用户不存在'
        return json_failed(404, message)
    if not RepoManager.watch_user(request.userprofile, gsuserprofile):
        message = u'关注失败,关注数量超过限制或者用户不允许关注'
        return json_failed(500, message)
    return json_success(u'成功关注用户 %s' % user_name)
Esempio n. 11
0
def unwatch(request, user_name):
    gsuserprofile = GsuserManager.get_userprofile_by_name(user_name)
    if gsuserprofile is None:
        message = u'用户不存在'
        return json_failed(404, message)
    if not RepoManager.unwatch_user(request.userprofile, gsuserprofile):
        message = u'取消关注失败,可能用户未被关注'
        return json_failed(500, message)
    return json_success(u'成功取消关注用户 %s' % user_name)
Esempio n. 12
0
def member_leave(request, username):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(teamUser.id, request.user.id)
    teamMembers = TeamManager.list_teamMember_by_teamUserId(teamMember.team_user_id)
    if _has_other_admin_teamMember(request, teamMember, teamMembers):
        teamMember.visibly = 1
        teamMember.save()
        return json_success(u'用户退出成功')
    return json_failed(500, u'用户退出失败,一个团队帐号至少需要保留一个管理员')
Esempio n. 13
0
def recommend_delete(request, user_name, recommend_id):
    gsuser = GsuserManager.get_user_by_name(user_name)
    if gsuser is None:
        raise Http404
    recommend = GsuserManager.get_recommend_by_id(recommend_id)
    if recommend.user_id == request.user.id:
        recommend.visibly = 1
        recommend.save()
    return json_success(u'成功删除评论')
Esempio n. 14
0
def notif_email(request):
    user = request.user
    notifSetting = FeedManager.get_notifsetting_by_userId(user.id)
    email = request.POST.get('email', user.email)
    if email_re.match(email):
        useremail = GsuserManager.get_useremail_by_userId_email(user.id, email)
        if useremail and useremail.is_verify == 1:
            notifSetting.email = email
            notifSetting.save()
    return json_success(u'成功修改邮箱 %s' % email)
Esempio n. 15
0
def notif_fqcy(request):
    user = request.user
    notifSetting = FeedManager.get_notifsetting_by_userId(user.id)
    fqcy_str = request.POST.get('fqcy', '0')
    if re.match('^-?\d+$', fqcy_str):
        fqcy = int(fqcy_str)
        if fqcy in NOTIF_FQCY.VALUES:
            notifSetting.notif_fqcy = fqcy
            notifSetting.save()
    return json_success(u'成功修改频率 %s' % fqcy_str)
Esempio n. 16
0
def notif_email(request):
    user = request.user
    notifSetting = FeedManager.get_notifsetting_by_userId(user.id);
    email = request.POST.get('email', user.email)
    if email_re.match(email):
        useremail = GsuserManager.get_useremail_by_userId_email(user.id, email)
        if useremail and useremail.is_verify == 1:
            notifSetting.email = email
            notifSetting.save()
    return json_success(u'成功修改邮箱 %s' % email)
Esempio n. 17
0
def remove_member(request, username):
    (manage_teamMember,
     teamMember) = _get_teamMember_by_manageTeamMemberId(request)
    teamMembers = TeamManager.list_teamMember_by_teamUserId(
        teamMember.team_user_id)
    if _has_other_admin_teamMember(request, manage_teamMember, teamMembers):
        manage_teamMember.visibly = 1
        manage_teamMember.save()
        return json_success(u'删除用户成功')
    return json_failed(500, u'删除用户失败,一个团队帐号至少需要保留一个管理员')
Esempio n. 18
0
def permission_grant(request, username):
    teamUser = GsuserManager.get_user_by_name(username)
    grant_type = request.POST.get('grant_type', 'global')
    permission = int(request.POST.get('permission', '0'))
    if grant_type == 'global':
        TeamManager.grant_team_global_permission(teamUser.id, permission)
    elif grant_type == 'user':
        user_id = int(request.POST.get('user_id', '0'))
        TeamManager.grant_team_user_permission(teamUser.id, user_id, permission)
    return json_success(u'赋予权限成功')
Esempio n. 19
0
def group_add_member(request, username):
    teamUser = GsuserManager.get_user_by_name(username)
    team_group_id = int(request.POST.get('team_group_id', '0'))
    teamGroup = TeamManager.get_teamGroup_by_id(team_group_id)
    if not teamGroup or teamGroup.team_user_id != teamUser.id:
        return _response_not_manage_rights(request)
    member_username = request.POST.get('member_username', '')
    member_user = GsuserManager.get_user_by_name(member_username)
    if not member_user:
        return json_failed(500, u'没有该用户名')
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(teamUser.id, member_user.id)
    if not teamMember:
        return json_failed(500, u'用户 %s 还没有加入团队帐号 %s' % (member_user.username, teamUser.username))
    groupMember = TeamManager.get_groupMember_by_teamGroupId_memberUserId(teamGroup.id, member_user.id)
    if groupMember:
        return json_success(u'用户 %s 已经在该组' % member_user.username)
    groupMember = GroupMember(team_user_id=teamUser.id, group_id=teamGroup.id, member_user_id=member_user.id)
    groupMember.save()
    return json_success(u'成功添加用户 %s 到组 %s' % (member_user.username, teamGroup.name))
Esempio n. 20
0
def cancal_admin(request, username):
    (manage_teamMember,
     teamMember) = _get_teamMember_by_manageTeamMemberId(request)
    teamMembers = TeamManager.list_teamMember_by_teamUserId(
        teamMember.team_user_id)
    if _has_other_admin_teamMember(request, manage_teamMember, teamMembers):
        manage_teamMember.is_admin = 0
        manage_teamMember.save()
        return json_success(u'解除管理员权限')
    return json_failed(500, u'解除管理员失败,一个团队帐号至少需要保留一个管理员')
Esempio n. 21
0
def notif_fqcy(request):
    user = request.user
    notifSetting = FeedManager.get_notifsetting_by_userId(user.id);
    fqcy_str = request.POST.get('fqcy', '0')
    if re.match('^-?\d+$', fqcy_str):
        fqcy = int(fqcy_str)
        if fqcy in NOTIF_FQCY.VALUES:
            notifSetting.notif_fqcy = fqcy
            notifSetting.save()
    return json_success(u'成功修改频率 %s' % fqcy_str)
Esempio n. 22
0
def member_leave(request, username):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(
        teamUser.id, request.user.id)
    teamMembers = TeamManager.list_teamMember_by_teamUserId(
        teamMember.team_user_id)
    if _has_other_admin_teamMember(request, teamMember, teamMembers):
        teamMember.visibly = 1
        teamMember.save()
        return json_success(u'用户退出成功')
    return json_failed(500, u'用户退出失败,一个团队帐号至少需要保留一个管理员')
Esempio n. 23
0
def group_add(request, username):
    teamUser = GsuserManager.get_user_by_name(username)
    group_name = request.POST.get('group_name', '')
    if not re.match('^[ 0-9a-zA-Z_-]+$', group_name):
        return json_failed(403, u'组名不符合规范,只允许[ 0-9a-zA-Z_-]之内的字符')
    teamGroup = TeamManager.get_teamGroup_by_teamUserId_name(teamUser.id, group_name)
    if teamGroup:
        return json_failed(500, u'组名已经存在')
    teamGroup = TeamGroup(team_user_id = teamUser.id, name = group_name, desc = '')
    teamGroup.save()
    return json_success(u'成功创建组 %s' % group_name)
Esempio n. 24
0
def permission_grant(request, username):
    teamUser = GsuserManager.get_user_by_name(username)
    grant_type = request.POST.get('grant_type', 'global')
    permission = int(request.POST.get('permission', '0'))
    if grant_type == 'global':
        TeamManager.grant_team_global_permission(teamUser.id, permission)
    elif grant_type == 'user':
        user_id = int(request.POST.get('user_id', '0'))
        TeamManager.grant_team_user_permission(teamUser.id, user_id,
                                               permission)
    return json_success(u'赋予权限成功')
Esempio n. 25
0
def group_add(request, username):
    teamUser = GsuserManager.get_user_by_name(username)
    group_name = request.POST.get('group_name', '')
    if not re.match('^[ 0-9a-zA-Z_-]+$', group_name):
        return json_failed(403, u'组名不符合规范,只允许[ 0-9a-zA-Z_-]之内的字符')
    teamGroup = TeamManager.get_teamGroup_by_teamUserId_name(
        teamUser.id, group_name)
    if teamGroup:
        return json_failed(500, u'组名已经存在')
    teamGroup = TeamGroup(team_user_id=teamUser.id, name=group_name, desc='')
    teamGroup.save()
    return json_success(u'成功创建组 %s' % group_name)
Esempio n. 26
0
def group_remove_member(request, username):
    teamUser = GsuserManager.get_user_by_name(username)
    team_group_id = int(request.POST.get('team_group_id', '0'))
    teamGroup = TeamManager.get_teamGroup_by_id(team_group_id)
    if not teamGroup or teamGroup.team_user_id != teamUser.id:
        return _response_not_manage_rights(request)
    member_user_id = int(request.POST.get('member_user_id', '0'))
    groupMember = TeamManager.get_groupMember_by_teamGroupId_memberUserId(teamGroup.id, member_user_id)
    if groupMember:
        groupMember.visibly = 1
        groupMember.save()
    return json_success(u'从 %s 组移除用户' % (teamGroup.name))
Esempio n. 27
0
def email_primary(request, eid):
    usermail = GsuserManager.get_useremail_by_id(eid)
    if not usermail or usermail.user_id != request.user.id:
        return json_failed(500, u'设置失败,没有权限')
    useremails = GsuserManager.list_useremail_by_userId(request.user.id)
    for x in useremails:
        if usermail.id != x.id and x.is_primary == 1:
            x.is_primary = 0
            x.save()
    usermail.is_primary = 1
    usermail.save()
    return json_success(u'成功设置默认邮箱 %s' % usermail.email)
Esempio n. 28
0
def email_primary(request, eid):
    usermail = GsuserManager.get_useremail_by_id(eid)
    if not usermail or usermail.user_id != request.user.id:
        return json_failed(500, u'设置失败,没有权限')
    useremails = GsuserManager.list_useremail_by_userId(request.user.id)
    for x in useremails:
        if usermail.id != x.id and x.is_primary == 1:
            x.is_primary = 0
            x.save()
    usermail.is_primary = 1
    usermail.save()
    return json_success(u'成功设置默认邮箱 %s' % usermail.email)
Esempio n. 29
0
def group_remove(request, username):
    teamUser = GsuserManager.get_user_by_name(username)
    team_group_id = int(request.POST.get('team_group_id', '0'))
    teamGroup = TeamManager.get_teamGroup_by_id(team_group_id)
    if not teamGroup or teamGroup.team_user_id != teamUser.id:
        return _response_not_manage_rights(request)
    groupMembers = TeamManager.list_groupMember_by_teamGroupId(teamGroup.id)
    for groupMember in groupMembers:
        groupMember.visibly = 1
        groupMember.save()
    teamGroup.visibly = 1
    teamGroup.save()
    return json_success(u'成功删除组 %s' % teamGroup.name)
Esempio n. 30
0
def group_remove(request, username):
    teamUser = GsuserManager.get_user_by_name(username)
    team_group_id = int(request.POST.get('team_group_id', '0'))
    teamGroup = TeamManager.get_teamGroup_by_id(team_group_id)
    if not teamGroup or teamGroup.team_user_id != teamUser.id:
        return _response_not_manage_rights(request)
    groupMembers = TeamManager.list_groupMember_by_teamGroupId(teamGroup.id)
    for groupMember in groupMembers:
        groupMember.visibly = 1
        groupMember.save()
    teamGroup.visibly = 1
    teamGroup.save()
    return json_success(u'成功删除组 %s' % teamGroup.name)
Esempio n. 31
0
def group_remove_member(request, username):
    teamUser = GsuserManager.get_user_by_name(username)
    team_group_id = int(request.POST.get('team_group_id', '0'))
    teamGroup = TeamManager.get_teamGroup_by_id(team_group_id)
    if not teamGroup or teamGroup.team_user_id != teamUser.id:
        return _response_not_manage_rights(request)
    member_user_id = int(request.POST.get('member_user_id', '0'))
    groupMember = TeamManager.get_groupMember_by_teamGroupId_memberUserId(
        teamGroup.id, member_user_id)
    if groupMember:
        groupMember.visibly = 1
        groupMember.save()
    return json_success(u'从 %s 组移除用户' % (teamGroup.name))
Esempio n. 32
0
def destroy_confirm(request, username):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(teamUser.id, request.user.id)
    teamRepos = RepoManager.list_repo_by_userId(teamUser.id, 0, 1000)
    for teamRepo in teamRepos:
        RepoManager.delete_repo(teamUser, teamUserprofile, teamRepo)
    teamMembers = TeamManager.list_teamMember_by_teamUserId(teamUser.id)
    for teamMember in teamMembers:
        teamMember.visibly = 1
        teamMember.save()
    teamUser.delete()
    teamUserprofile.visibly = 1
    teamUserprofile.save()
    return json_success(u'已经删除了团队帐号')
Esempio n. 33
0
def destroy_confirm(request, username):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(
        teamUser.id, request.user.id)
    teamRepos = RepoManager.list_repo_by_userId(teamUser.id, 0, 1000)
    for teamRepo in teamRepos:
        RepoManager.delete_repo(teamUser, teamUserprofile, teamRepo)
    teamMembers = TeamManager.list_teamMember_by_teamUserId(teamUser.id)
    for teamMember in teamMembers:
        teamMember.visibly = 1
        teamMember.save()
    teamUser.delete()
    teamUserprofile.visibly = 1
    teamUserprofile.save()
    return json_success(u'已经删除了团队帐号')
Esempio n. 34
0
def notif_types(request):
    user = request.user
    notifSetting = FeedManager.get_notifsetting_by_userId(user.id);
    types_str = request.POST.get('types', 'all')
    types = []
    if types_str == 'all':
        notifSetting.notif_types = 'all'
    else:
        for type_str in types_str.split(','):
            if not re.match('^\d+$', type_str):
                continue
            type_ = int(type_str)
            if type_ in NOTIF_TYPE.VALUES:
                types.append(type_str);
        notifSetting.notif_types = ','.join(types)
    notifSetting.save()
    return json_success(u'成功修改通知 %s' % types_str)
Esempio n. 35
0
def notif_types(request):
    user = request.user
    notifSetting = FeedManager.get_notifsetting_by_userId(user.id)
    types_str = request.POST.get('types', 'all')
    types = []
    if types_str == 'all':
        notifSetting.notif_types = 'all'
    else:
        for type_str in types_str.split(','):
            if not re.match('^\d+$', type_str):
                continue
            type_ = int(type_str)
            if type_ in NOTIF_TYPE.VALUES:
                types.append(type_str)
        notifSetting.notif_types = ','.join(types)
    notifSetting.save()
    return json_success(u'成功修改通知 %s' % types_str)
Esempio n. 36
0
def add_member(request, username):
    (teamUser, teamUserprofile) = _get_team_user_userprofile(request, username)
    teamMember = None
    username_or_email = request.POST.get('username_or_email', '')
    if '@' in username_or_email:
        user = GsuserManager.get_user_by_email(username_or_email)
        if not user:
            ref_hash = '%032x' % random.getrandbits(128)
            ref_message = u'用户 %s 邀请您注册Gitshell,成为团队 %s 的成员' % (request.user.username, username)
            userViaRef = UserViaRef(email=username_or_email, ref_type=REF_TYPE.VIA_TEAM_MEMBER, ref_hash=ref_hash, ref_message=ref_message, first_refid = teamUser.id, first_refname = teamUser.username)
            userViaRef.save()
            join_url = 'https://gitshell.com/join/ref/%s/' % ref_hash
            Mailer().send_join_via_team_addmember(request.user, teamUser, username_or_email, join_url)
            return json_failed(301, u'邮箱 %s 未注册,已经发送邮件邀请对方注册' % username_or_email)
        teamMember = TeamManager.add_teamMember_by_email(teamUser, username_or_email)
    else:
        teamMember = TeamManager.add_teamMember_by_username(teamUser, username_or_email)
    if not teamMember:
        return json_failed(404, u'没有相关用户,不能是团队帐号')
    return json_success(u'成功添加用户')
Esempio n. 37
0
def grant_admin(request, username):
    (manage_teamMember, teamMember) = _get_teamMember_by_manageTeamMemberId(request)
    manage_teamMember.is_admin = 1
    manage_teamMember.save()
    return json_success(u'赋予管理员权限')
Esempio n. 38
0
def email_remove(request, eid):
    usermail = GsuserManager.get_useremail_by_id(eid)
    if usermail and usermail.user_id == request.user.id:
        usermail.visibly = 1
        usermail.save()
    return json_success(u'成功删除邮箱 %s' % usermail.email)
Esempio n. 39
0
def email_remove(request, eid):
    usermail = GsuserManager.get_useremail_by_id(eid)
    if usermail and usermail.user_id == request.user.id:
        usermail.visibly = 1
        usermail.save()
    return json_success(u'成功删除邮箱 %s' % usermail.email)
Esempio n. 40
0
def grant_admin(request, username):
    (manage_teamMember,
     teamMember) = _get_teamMember_by_manageTeamMemberId(request)
    manage_teamMember.is_admin = 1
    manage_teamMember.save()
    return json_success(u'赋予管理员权限')