示例#1
0
文件: views.py 项目: ZheYuan/gitshell
def watch_user(request, user_name):
    title = u'%s / 关注的用户' % user_name
    gsuser = GsuserManager.get_user_by_name(user_name)
    if gsuser is None:
        raise Http404
    gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id)

    feedAction = FeedAction()
    raw_watch_users = feedAction.get_watch_users(gsuser.id, 0, 100)
    watch_user_ids = [int(x[0]) for x in raw_watch_users]
    watch_users_map = GsuserManager.map_users(watch_user_ids)
    watch_users = [watch_users_map[x] for x in watch_user_ids if x in watch_users_map]

    raw_bewatch_users = feedAction.get_bewatch_users(gsuser.id, 0, 100)
    bewatch_user_ids = [int(x[0]) for x in raw_bewatch_users]
    bewatch_users_map = GsuserManager.map_users(bewatch_user_ids)
    bewatch_users = [bewatch_users_map[x] for x in bewatch_user_ids if x in bewatch_users_map]
    # fixed on detect
    need_fix = False
    if len(watch_users) != gsuserprofile.watch:
        gsuserprofile.watch = len(watch_users)
        need_fix = True
    if len(bewatch_users) < 100 and len(bewatch_users) != gsuserprofile.be_watched:
        gsuserprofile.be_watched = len(bewatch_users) 
        need_fix = True
    if need_fix:
        gsuserprofile.save()

    response_dictionary = {'mainnav': 'user', 'title': title, 'watch_users': watch_users, 'bewatch_users': bewatch_users}
    response_dictionary.update(get_common_user_dict(request, gsuser, gsuserprofile))
    return render_to_response('user/watch_user.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
示例#2
0
文件: views.py 项目: ZheYuan/gitshell
def github_authenticate(thirdpartyUser):
    tp_id, tp_username, tp_email, github_user_info = thirdpartyUser.tp_id, thirdpartyUser.tp_username, thirdpartyUser.tp_email, thirdpartyUser.github_user_info
    thirdpartyUser_find = GsuserManager.get_thirdpartyUser_by_type_tpId(ThirdpartyUser.GITHUB, tp_id)
    if thirdpartyUser_find is not None:
        if thirdpartyUser_find.access_token != thirdpartyUser.access_token:
            thirdpartyUser_find.access_token = thirdpartyUser.access_token
            thirdpartyUser_find.save()
        user_id = thirdpartyUser_find.id
        user = GsuserManager.get_user_by_id(user_id)
        return user
    username = __get_uniq_username(tp_username)
    email = __get_uniq_email(tp_email)
    password = __get_random_password()
    if username is None or email is None or password is None:
        return None
    create_user = None
    try:
        create_user = User.objects.create_user(username, email, password)
        if create_user is not None and create_user.is_active:
            userprofile = Userprofile(username = create_user.username, email = create_user.email, imgurl = hashlib.md5(create_user.email.lower()).hexdigest())
            _fill_github_user_info(userprofile, github_user_info)
            userprofile.id = create_user.id
            userprofile.save()
            if username == tp_username and email == tp_email:
                thirdpartyUser.init = 1
            thirdpartyUser.user_type = ThirdpartyUser.GITHUB
            thirdpartyUser.id = create_user.id
            thirdpartyUser.save()
    except IntegrityError, e:
        logger.exception(e)
示例#3
0
def group(request, username, group_id):
    teamUser = GsuserManager.get_user_by_name(username)
    teamUserprofile = GsuserManager.get_userprofile_by_id(teamUser.id)
    teamGroup = TeamManager.get_teamGroup_by_id(group_id)
    if not teamGroup or teamGroup.team_user_id != teamUser.id:
        raise Http404
    groupMembers = TeamManager.list_groupMember_by_teamGroupId(teamGroup.id)
    userIdInGroupSet = Set([x.member_user_id for x in groupMembers])
    teamMembers = TeamManager.list_teamMember_by_teamUserId(teamUser.id)
    teamMembersNotInGroup = [
        x for x in teamMembers if x.user_id not in userIdInGroupSet
    ]
    current = 'settings'
    sub_nav = 'groups'
    title = u'%s / 设置 / 组管理 / %s' % (teamUser.username, teamGroup.name)
    response_dictionary = {
        'current': current,
        'sub_nav': sub_nav,
        'title': title,
        'teamGroup': teamGroup,
        'groupMembers': groupMembers,
        'teamMembersNotInGroup': teamMembersNotInGroup
    }
    response_dictionary.update(
        _get_common_team_dict(request, teamUser, teamUserprofile))
    return render_to_response('team/group.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
示例#4
0
 def fillwith(self):
     self.short_refname = self.refname
     if self.refname and '/' in self.refname:
         self.short_refname = self.refname[self.refname.rfind('/')+1:]
     self.repo = RepoManager.get_repo_by_id(self.repo_id)
     self.committer_userprofile = GsuserManager.get_userprofile_by_name(self.committer)
     self.author_userprofile = GsuserManager.get_userprofile_by_name(self.author)
示例#5
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))
示例#6
0
def watch_repo(request, user_name):
    title = u'%s / 关注的仓库' % user_name
    gsuser = GsuserManager.get_user_by_name(user_name)
    if gsuser is None:
        raise Http404
    gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id)

    feedAction = FeedAction()
    raw_watch_repos = feedAction.get_watch_repos(gsuser.id, 0, 100)
    watch_repo_ids = [int(x[0]) for x in raw_watch_repos]
    watch_repos_map = RepoManager.merge_repo_map_ignore_visibly(watch_repo_ids)
    watch_repos = [
        watch_repos_map[x] for x in watch_repo_ids if x in watch_repos_map
    ]

    response_dictionary = {
        'mainnav': 'user',
        'title': title,
        'watch_repos': watch_repos
    }
    # fixed on detect
    if len(watch_repos) != gsuserprofile.watchrepo:
        gsuserprofile.watchrepo = len(watch_repos)
        gsuserprofile.save()

    response_dictionary.update(
        get_common_user_dict(request, gsuser, gsuserprofile))
    return render_to_response('user/watch_repo.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
示例#7
0
def get_common_user_dict(request, gsuser, gsuserprofile):
    feedAction = FeedAction()
    raw_watch_users = feedAction.get_watch_users(gsuser.id, 0, 10)
    raw_bewatch_users = feedAction.get_bewatch_users(gsuser.id, 0, 10)
    watch_user_ids = [int(x[0]) for x in raw_watch_users]
    bewatch_user_ids = [int(x[0]) for x in raw_bewatch_users]
    watch_users_map = GsuserManager.map_users(watch_user_ids)
    bewatch_users_map = GsuserManager.map_users(bewatch_user_ids)
    watch_users = [
        watch_users_map[x] for x in watch_user_ids if x in watch_users_map
    ]
    bewatch_users = [
        bewatch_users_map[x] for x in bewatch_user_ids
        if x in bewatch_users_map
    ]
    raw_recommends = GsuserManager.list_recommend_by_userid(gsuser.id, 0, 20)
    recommends = __conver_to_recommends_vo(raw_recommends)

    is_watched_user = False
    if request.user.is_authenticated():
        is_watched_user = RepoManager.is_watched_user(request.user.id,
                                                      gsuser.id)
    return {
        'gsuser': gsuser,
        'gsuserprofile': gsuserprofile,
        'watch_users': watch_users,
        'bewatch_users': bewatch_users,
        'recommends': recommends,
        'is_watched_user': is_watched_user,
        'show_common': True
    }
示例#8
0
def github_authenticate(thirdpartyUser):
    tp_id, tp_username, tp_email, github_user_info = thirdpartyUser.tp_id, thirdpartyUser.tp_username, thirdpartyUser.tp_email, thirdpartyUser.github_user_info
    thirdpartyUser_find = GsuserManager.get_thirdpartyUser_by_type_tpId(
        ThirdpartyUser.GITHUB, tp_id)
    if thirdpartyUser_find is not None:
        if thirdpartyUser_find.access_token != thirdpartyUser.access_token:
            thirdpartyUser_find.access_token = thirdpartyUser.access_token
            thirdpartyUser_find.save()
        user_id = thirdpartyUser_find.id
        user = GsuserManager.get_user_by_id(user_id)
        return user
    username = __get_uniq_username(tp_username)
    email = __get_uniq_email(tp_email)
    password = __get_random_password()
    if username is None or email is None or password is None:
        return None
    create_user = None
    try:
        create_user = User.objects.create_user(username, email, password)
        if create_user is not None and create_user.is_active:
            userprofile = Userprofile(
                username=create_user.username,
                email=create_user.email,
                imgurl=hashlib.md5(create_user.email.lower()).hexdigest())
            _fill_github_user_info(userprofile, github_user_info)
            userprofile.id = create_user.id
            userprofile.save()
            if username == tp_username and email == tp_email:
                thirdpartyUser.init = 1
            thirdpartyUser.user_type = ThirdpartyUser.GITHUB
            thirdpartyUser.id = create_user.id
            thirdpartyUser.save()
    except IntegrityError, e:
        logger.exception(e)
示例#9
0
    def notif_at(self, notif_type, from_user_id, relative_id, message):
        at_name_list = FeedUtils.list_atname(message)
        user_unread_message_dict = {}

        for at_name in at_name_list:
            at_user = GsuserManager.get_user_by_name(at_name)
            if at_user is not None:
                to_user_id = at_user.id
                notifMessage = None
                # disable duplicate notify
                exists_notifMessage = self.get_notifmessage_by_userId_notifType_relativeId(to_user_id, notif_type, relative_id)
                if exists_notifMessage is not None:
                    continue
                if notif_type == NOTIF_TYPE.AT_COMMIT:
                    notifMessage = NotifMessage.create_at_commit(from_user_id, to_user_id, relative_id)
                elif notif_type == NOTIF_TYPE.AT_MERGE:
                    notifMessage = NotifMessage.create_at_merge(from_user_id, to_user_id, relative_id)
                elif notif_type == NOTIF_TYPE.AT_ISSUE:
                    notifMessage = NotifMessage.create_at_issue(from_user_id, to_user_id, relative_id)
                elif notif_type == NOTIF_TYPE.AT_ISSUE_COMMENT:
                    notifMessage = NotifMessage.create_at_issue_comment(from_user_id, to_user_id, relative_id)
                if notifMessage is None:
                    continue
                self.message_save_and_notif(notifMessage)
                if to_user_id not in user_unread_message_dict:
                    user_unread_message_dict[to_user_id] = 0
                user_unread_message_dict[to_user_id] = user_unread_message_dict[to_user_id] + 1

        for to_user_id, unread_message in user_unread_message_dict.items():
            at_userprofile = GsuserManager.get_userprofile_by_id(to_user_id)
            at_userprofile.unread_message = at_userprofile.unread_message + unread_message
            at_userprofile.save()
示例#10
0
 def notif_pull_request_status(self, pullRequest, pullStatus):
     notif_type = NOTIF_TYPE.MERGE_CREATE_PULL_REQUEST
     message = ''
     if pullStatus == PULL_STATUS.NEW:
         message = u'新建了'
         merge_user_profile = GsuserManager.get_userprofile_by_id(pullRequest.merge_user_id)
         if merge_user_profile is not None:
             notifMessage = NotifMessage.create(NOTIF_CATE.MERGE, NOTIF_TYPE.MERGE_CREATE_PULL_REQUEST, pullRequest.pull_user_id, pullRequest.merge_user_id, pullRequest.id)
             notifMessage.message = message
             self.message_save_and_notif(notifMessage)
         merge_user_profile.unread_message = merge_user_profile.unread_message + 1
         merge_user_profile.save()
         return
     if pullStatus == PULL_STATUS.MERGED_FAILED:
         notif_type = NOTIF_TYPE.MERGE_MERGED_FAILED_PULL_REQUEST
         message = u'合并失败'
     elif pullStatus == PULL_STATUS.MERGED:
         notif_type = NOTIF_TYPE.MERGE_MERGED_PULL_REQUEST
         message = u'合并了'
     elif pullStatus == PULL_STATUS.REJECTED:
         notif_type = NOTIF_TYPE.MERGE_REJECTED_PULL_REQUEST
         message = u'拒绝了'
     elif pullStatus == PULL_STATUS.CLOSE:
         notif_type = NOTIF_TYPE.MERGE_CLOSE_PULL_REQUEST
         message = u'关闭了'
     pull_user_profile = GsuserManager.get_userprofile_by_id(pullRequest.pull_user_id)
     if pull_user_profile is not None:
         notifMessage = NotifMessage.create(NOTIF_CATE.MERGE, notif_type, pullRequest.merge_user_id, pullRequest.pull_user_id, pullRequest.id)
         notifMessage.message = message
         self.message_save_and_notif(notifMessage)
     pull_user_profile.unread_message = pull_user_profile.unread_message + 1
     pull_user_profile.save()
示例#11
0
 def list_teamMember_by_teamUserId(self, team_user_id):
     userprofile = GsuserManager.get_userprofile_by_id(team_user_id)
     if userprofile.is_team_account == 0:
         return []
     teamMembers = query(TeamMember, team_user_id, 'teammember_l_teamUserId', [team_user_id])
     for x in teamMembers:
         x.user = GsuserManager.get_userprofile_by_id(x.user_id)
         x.team_user = userprofile
     return teamMembers
示例#12
0
 def list_teamMember_by_userId(self, user_id):
     userprofile = GsuserManager.get_userprofile_by_id(user_id)
     if userprofile.has_joined_team == 0:
         return []
     teamMembers = query(TeamMember, None, 'teammember_l_userId', [user_id])
     for x in teamMembers:
         x.user = GsuserManager.get_userprofile_by_id(x.user_id)
         x.team_user = GsuserManager.get_userprofile_by_id(x.team_user_id)
     return teamMembers
示例#13
0
 def fillwith(self):
     self.short_refname = self.refname
     if self.refname and '/' in self.refname:
         self.short_refname = self.refname[self.refname.rfind('/') + 1:]
     self.repo = RepoManager.get_repo_by_id(self.repo_id)
     self.committer_userprofile = GsuserManager.get_userprofile_by_name(
         self.committer)
     self.author_userprofile = GsuserManager.get_userprofile_by_name(
         self.author)
示例#14
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'成功删除评论')
示例#15
0
文件: views.py 项目: ZheYuan/gitshell
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'成功删除评论')
示例#16
0
 def fillwith(self):
     self.repo = RepoManager.get_repo_by_id(self.repo_id)
     self.creator_userprofile = GsuserManager.get_userprofile_by_id(self.creator_user_id)
     self.assigned_userprofile = GsuserManager.get_userprofile_by_id(self.assigned)
     if self.tracker in ISSUE_ATTRS['REV_TRACKERS']:
         self.tracker_v = ISSUE_ATTRS['REV_TRACKERS'][self.tracker]
     if self.status in ISSUE_ATTRS['REV_STATUSES']:
         self.status_v = ISSUE_ATTRS['REV_STATUSES'][self.status]
     if self.priority in ISSUE_ATTRS['REV_PRIORITIES']:
         self.priority_v = ISSUE_ATTRS['REV_PRIORITIES'][self.priority]
示例#17
0
文件: views.py 项目: ZheYuan/gitshell
def groups(request, username):
    teamUser = GsuserManager.get_user_by_name(username)
    teamUserprofile = GsuserManager.get_userprofile_by_id(teamUser.id)
    teamGroups = TeamManager.list_teamGroup_by_teamUserId(teamUser.id)
    current = 'settings'; sub_nav = 'groups'; title = u'%s / 设置 / 组管理' % (teamUser.username)
    response_dictionary = {'current': current, 'sub_nav': sub_nav, 'title': title, 'teamGroups': teamGroups}
    response_dictionary.update(_get_common_team_dict(request, teamUser, teamUserprofile))
    return render_to_response('team/groups.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
示例#18
0
def __get_uniq_username(tp_username):
    if tp_username is not None and not tp_username.startswith('-'):
        user = GsuserManager.get_user_by_name(tp_username)
        if user is None:
            return tp_username
    for i in range(0, 1000):
        random_username = '******' % random.getrandbits(64)
        user = GsuserManager.get_user_by_name(random_username)
        if user is None:
            return random_username
    return None
示例#19
0
文件: views.py 项目: ZheYuan/gitshell
def _get_team_user_userprofile(request, username):
    current_user = GsuserManager.get_user_by_name(username)
    if not current_user:
        return (request.user, request.userprofile)
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(current_user.id, request.user.id)
    if not teamMember:
        return (request.user, request.userprofile)
    current_userprofile = GsuserManager.get_userprofile_by_id(current_user.id)
    if current_userprofile:
        return (current_user, current_userprofile)
    return (request.user, request.userprofile)
示例#20
0
文件: views.py 项目: ZheYuan/gitshell
def stats(request, user_name):
    user = GsuserManager.get_user_by_name(user_name)
    if user is None:
        raise Http404
    stats_dict = get_stats_dict(request, user)
    gsuserprofile = GsuserManager.get_userprofile_by_id(user.id)
    response_dictionary = {'title': u'%s / 最近统计' % (user.username), 'gsuserprofile': gsuserprofile}
    response_dictionary.update(stats_dict)
    return render_to_response('user/stats.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
示例#21
0
文件: views.py 项目: ZheYuan/gitshell
def __get_uniq_username(tp_username):
    if tp_username is not None and not tp_username.startswith('-'):
        user = GsuserManager.get_user_by_name(tp_username)
        if user is None:
            return tp_username
    for i in range(0, 1000):
        random_username = '******' % random.getrandbits(64)
        user = GsuserManager.get_user_by_name(random_username)
        if user is None:
            return random_username
    return None
示例#22
0
文件: views.py 项目: ZheYuan/gitshell
def __get_uniq_email(tp_email):
    if tp_email is not None:
        user = GsuserManager.get_user_by_email(tp_email)
        if user is None:
            return tp_email
    for i in range(0, 1000):
        random_email = ('%8x' % random.getrandbits(64)) + '@example.com'
        user = GsuserManager.get_user_by_email(random_email)
        if user is None:
            return random_email
    return None
示例#23
0
def __get_uniq_email(tp_email):
    if tp_email is not None:
        user = GsuserManager.get_user_by_email(tp_email)
        if user is None:
            return tp_email
    for i in range(0, 1000):
        random_email = ('%8x' % random.getrandbits(64)) + '@example.com'
        user = GsuserManager.get_user_by_email(random_email)
        if user is None:
            return random_email
    return None
示例#24
0
def get_attrs(username, reponame):
    user = GsuserManager.get_user_by_name(username)
    if not user:
        return_all_none()
    userprofile = GsuserManager.get_userprofile_by_id(user.id)
    if not userprofile:
        return_all_none()
    repo = RepoManager.get_repo_by_userId_name(user.id, reponame)
    if not repo:
        return_all_none()
    abs_repo_path = repo.get_abs_repopath()
    return (user, userprofile, repo, abs_repo_path)
示例#25
0
文件: views.py 项目: ZheYuan/gitshell
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)
示例#26
0
文件: views.py 项目: ZheYuan/gitshell
def star_repo(request, user_name):
    title = u'%s / 标星的仓库' % user_name
    gsuser = GsuserManager.get_user_by_name(user_name)
    if gsuser is None:
        raise Http404
    gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id)
    star_repos = RepoManager.list_star_repo(gsuser.id, 0, 500)
    response_dictionary = {'mainnav': 'user', 'title': title, 'star_repos': star_repos}
    response_dictionary.update(get_common_user_dict(request, gsuser, gsuserprofile))
    return render_to_response('user/star_repo.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
示例#27
0
文件: views.py 项目: drew-sj/gitshell
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)
示例#28
0
def get_attrs(username, reponame):
    user = GsuserManager.get_user_by_name(username)
    if not user:
        return_all_none()
    userprofile = GsuserManager.get_userprofile_by_id(user.id)
    if not userprofile:
        return_all_none()
    repo = RepoManager.get_repo_by_userId_name(user.id, reponame)
    if not repo:
        return_all_none()
    abs_repo_path = repo.get_abs_repopath()
    return (user, userprofile, repo, abs_repo_path)
示例#29
0
def _get_team_user_userprofile(request, username):
    current_user = GsuserManager.get_user_by_name(username)
    if not current_user:
        return (request.user, request.userprofile)
    teamMember = TeamManager.get_teamMember_by_teamUserId_userId(
        current_user.id, request.user.id)
    if not teamMember:
        return (request.user, request.userprofile)
    current_userprofile = GsuserManager.get_userprofile_by_id(current_user.id)
    if current_userprofile:
        return (current_user, current_userprofile)
    return (request.user, request.userprofile)
示例#30
0
def get_user_repo_attr(username, reponame):
    nones = (None, None, None, None)
    user = GsuserManager.get_user_by_name(username) 
    if not user:
        return nones
    userprofile = GsuserManager.get_userprofile_by_id(user.id)
    if not userprofile:
        return nones
    repo = RepoManager.get_repo_by_userId_name(user.id, reponame)
    if not repo:
        return nones
    abs_repopath = repo.get_abs_repopath()
    return (user, userprofile, repo, abs_repopath)
示例#31
0
 def _set_real_committer_name(self, item):
     if 'committer_name' not in item or 'committer_email' not in item:
         return
     committer_name = item['committer_name']
     committer_email = item['committer_email']
     item['real_committer_name'] = ''
     user = GsuserManager.get_user_by_email(committer_email)
     if user:
         item['real_committer_name'] = user.username
         return
     user = GsuserManager.get_user_by_name(committer_name)
     if user:
         item['real_committer_name'] = user.username
示例#32
0
 def _set_real_author_name(self, item):
     if 'author_name' not in item or 'author_email' not in item:
         return
     author_name = item['author_name']
     author_email = item['author_email']
     item['real_author_name'] = ''
     user = GsuserManager.get_user_by_email(author_email)
     if user:
         item['real_author_name'] = user.username
         return
     user = GsuserManager.get_user_by_name(author_name)
     if user:
         item['real_author_name'] = user.username
示例#33
0
 def fillwith(self):
     self.pull_user = GsuserManager.get_userprofile_by_id(self.pull_user_id)
     self.merge_user = GsuserManager.get_userprofile_by_id(self.merge_user_id)
     self.source_repo = RepoManager.get_repo_by_id(self.source_repo_id)
     self.desc_repo = RepoManager.get_repo_by_id(self.desc_repo_id)
     self.short_title = self.title
     self.short_desc = self.desc
     if len(self.short_title) > 20:
         self.short_title = self.short_title[0:20] + '...'
     if len(self.short_desc) > 20:
         self.short_desc = self.short_desc[0:20] + '...'
     self.status_view = PULL_STATUS.VIEW_MAP[self.status]
     self.status_label = PULL_STATUS.LABEL_MAP[self.status]
示例#34
0
def get_user_repo_attr(username, reponame):
    nones = (None, None, None, None)
    user = GsuserManager.get_user_by_name(username)
    if not user:
        return nones
    userprofile = GsuserManager.get_userprofile_by_id(user.id)
    if not userprofile:
        return nones
    repo = RepoManager.get_repo_by_userId_name(user.id, reponame)
    if not repo:
        return nones
    abs_repopath = repo.get_abs_repopath()
    return (user, userprofile, repo, abs_repopath)
示例#35
0
def user(request, user_name):
    title = u'%s / 概括' % user_name
    gsuser = GsuserManager.get_user_by_name(user_name)
    if gsuser is None:
        raise Http404
    gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id)
    if gsuserprofile.is_team_account == 1 and TeamManager.is_teamMember(
            gsuser.id, request.user.id):
        return HttpResponseRedirect('/%s/-/dashboard/' % user_name)
    recommendsForm = RecommendsForm()
    repos = []
    if gsuser.id == request.user.id:
        repos = RepoManager.list_repo_by_userId(gsuser.id, 0, 100)
    else:
        repos = RepoManager.list_unprivate_repo_by_userId(gsuser.id, 0, 100)

    now = datetime.now()
    last30days = timeutils.getlast30days(now)
    last30days_commit = get_last30days_commit(gsuser)

    feedAction = FeedAction()

    raw_watch_repos = feedAction.get_watch_repos(gsuser.id, 0, 10)
    watch_repo_ids = [int(x[0]) for x in raw_watch_repos]
    watch_repos_map = RepoManager.merge_repo_map(watch_repo_ids)
    watch_repos = [
        watch_repos_map[x] for x in watch_repo_ids if x in watch_repos_map
    ]

    pri_user_feeds = feedAction.get_pri_user_feeds(gsuser.id, 0, 10)
    pub_user_feeds = feedAction.get_pub_user_feeds(gsuser.id, 0, 10)
    feeds_as_json = get_feeds_as_json(request, pri_user_feeds, pub_user_feeds)

    star_repos = RepoManager.list_star_repo(gsuser.id, 0, 20)

    response_dictionary = {
        'mainnav': 'user',
        'title': title,
        'recommendsForm': recommendsForm,
        'repos': repos,
        'watch_repos': watch_repos,
        'star_repos': star_repos,
        'last30days': last30days,
        'last30days_commit': last30days_commit,
        'feeds_as_json': feeds_as_json
    }
    response_dictionary.update(
        get_common_user_dict(request, gsuser, gsuserprofile))
    return render_to_response('user/user.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
示例#36
0
def stats(request, user_name):
    user = GsuserManager.get_user_by_name(user_name)
    if user is None:
        raise Http404
    stats_dict = get_stats_dict(request, user)
    gsuserprofile = GsuserManager.get_userprofile_by_id(user.id)
    response_dictionary = {
        'title': u'%s / 最近统计' % (user.username),
        'gsuserprofile': gsuserprofile
    }
    response_dictionary.update(stats_dict)
    return render_to_response('user/stats.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
示例#37
0
 def get_teamMember_by_teamUserId_userId(self, team_user_id, user_id):
     # for team user global permission
     if team_user_id == 0:
         teamMember = query_first(TeamMember, team_user_id, 'teammember_s_teamUserId_userId', [team_user_id, user_id])
         return teamMember
     team_userprofile = GsuserManager.get_userprofile_by_id(team_user_id)
     if team_userprofile and team_userprofile.is_team_account == 0:
         return None
     teamMember = query_first(TeamMember, team_user_id, 'teammember_s_teamUserId_userId', [team_user_id, user_id])
     if not teamMember:
         return None
     teamMember.user = GsuserManager.get_userprofile_by_id(user_id)
     teamMember.team_user = team_userprofile
     return teamMember
示例#38
0
文件: views.py 项目: ZheYuan/gitshell
def stats(request, user_name):
    title = u'%s / 统计' % user_name
    gsuser = GsuserManager.get_user_by_name(user_name)
    if gsuser is None:
        raise Http404
    gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id)
    now = datetime.now()
    last30days = timeutils.getlast30days(now)
    last30days_commit = get_last30days_commit(gsuser)
    response_dictionary = {'mainnav': 'user', 'title': title, 'last30days': last30days, 'last30days_commit': last30days_commit}
    response_dictionary.update(get_common_user_dict(request, gsuser, gsuserprofile))
    return render_to_response('user/stats.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
示例#39
0
def get_gitshell_username(name, email):
    global NAME_CACHE, EMAIL_CACHE
    if email in EMAIL_CACHE:
        return EMAIL_CACHE[email]
    if name in NAME_CACHE:
        return NAME_CACHE[name]
    user = GsuserManager.get_user_by_email(email)
    if user:
        EMAIL_CACHE[email] = user.username
        return user.username
    user = GsuserManager.get_user_by_name(name)
    if user:
        NAME_CACHE[name] = user.username
        return user.username
示例#40
0
def get_gitshell_username(name, email):
    global NAME_CACHE, EMAIL_CACHE
    if email in EMAIL_CACHE:
        return EMAIL_CACHE[email]
    if name in NAME_CACHE:
        return NAME_CACHE[name]
    user = GsuserManager.get_user_by_email(email)
    if user:
        EMAIL_CACHE[email] = user.username
        return user.username
    user = GsuserManager.get_user_by_name(name)
    if user:
        NAME_CACHE[name] = user.username
        return user.username
示例#41
0
 def fillwith(self):
     self.pull_user = GsuserManager.get_userprofile_by_id(self.pull_user_id)
     self.merge_user = GsuserManager.get_userprofile_by_id(
         self.merge_user_id)
     self.source_repo = RepoManager.get_repo_by_id(self.source_repo_id)
     self.desc_repo = RepoManager.get_repo_by_id(self.desc_repo_id)
     self.short_title = self.title
     self.short_desc = self.desc
     if len(self.short_title) > 20:
         self.short_title = self.short_title[0:20] + '...'
     if len(self.short_desc) > 20:
         self.short_desc = self.short_desc[0:20] + '...'
     self.status_view = PULL_STATUS.VIEW_MAP[self.status]
     self.status_label = PULL_STATUS.LABEL_MAP[self.status]
示例#42
0
文件: views.py 项目: ZheYuan/gitshell
def _join(request, joinForm, joinVia, tip, step):
    if step is None:
        step = '0'
    error = u''; title = u'注册'
    if step == '0' and request.method == 'POST':
        joinForm = JoinForm(request.POST)
        if joinForm.is_valid():
            email = joinForm.cleaned_data['email']
            username = joinForm.cleaned_data['username']
            password = joinForm.cleaned_data['password']
            ref_hash = joinForm.cleaned_data['ref_hash']
            user_by_email = GsuserManager.get_user_by_email(email)
            user_by_username = GsuserManager.get_user_by_name(username)
            if user_by_email is None and user_by_username is None:
                if ref_hash:
                    userViaRef = GsuserManager.get_userViaRef_by_refhash(ref_hash)
                    if userViaRef and _create_user_and_authenticate(request, username, email, password, ref_hash, True):
                        return HttpResponseRedirect('/join/3/')
                client_ip = _get_client_ip(request)
                cache_join_client_ip_count = cache.get(CacheKey.JOIN_CLIENT_IP % client_ip)
                if cache_join_client_ip_count is None:
                    cache_join_client_ip_count = 0
                cache_join_client_ip_count = cache_join_client_ip_count + 1
                cache.set(CacheKey.JOIN_CLIENT_IP % client_ip, cache_join_client_ip_count)
                if cache_join_client_ip_count < 10 and _create_user_and_authenticate(request, username, email, password, ref_hash, False):
                    return HttpResponseRedirect('/join/3/')
                Mailer().send_verify_account(email, username, password, ref_hash)
                goto = ''
                email_suffix = email.split('@')[-1]
                if email_suffix in COMMON_EMAIL_DOMAIN:
                    goto = COMMON_EMAIL_DOMAIN[email_suffix]
                return HttpResponseRedirect('/join/1/?goto=' + goto)
            error = u'欢迎回来, email: %s 或者 name: %s 已经注册过了, 您只需要直接登陆就行。' % (email, username)
        else:
            error = u'啊? 邮箱或验证码有误输入。注意大小写和前后空格。'
    if len(step) > 1:
        email = cache.get(step + '_email')
        username = cache.get(step + '_username')
        password = cache.get(step + '_password')
        ref_hash = cache.get(step + '_ref_hash')
        if email is None or username is None or password is None or not email_re.match(email) or not re.match("^[a-zA-Z0-9_-]+$", username) or username.startswith('-') or username in MAIN_NAVS:
            return HttpResponseRedirect('/join/4/')
        if _create_user_and_authenticate(request, username, email, password, ref_hash, True):
            return HttpResponseRedirect('/join/3/')
        else:
            error = u'啊? 用户名或密码有误输入,注意大小写和前后空格。'
    response_dictionary = {'step': step, 'error': error, 'title': title, 'joinForm': joinForm, 'joinVia': joinVia, 'tip': tip}
    return render_to_response('user/join.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
示例#43
0
 def list_star_user(self, repo_id, offset, row_count):
     stars = query(Star, None, 'star_l_repoId', [repo_id, offset, row_count])
     userprofiles = []
     for x in stars:
         user = GsuserManager.get_user_by_id(x.user_id)
         userprofile = GsuserManager.get_userprofile_by_id(x.user_id)
         if userprofile is None or userprofile.visibly == 1:
             x.visibly = 1
             x.save()
             continue
         userprofile.date_joined = time.mktime(user.date_joined.timetuple())
         userprofile.last_login = time.mktime(user.last_login.timetuple())
         userprofiles.append(userprofile)
     return userprofiles
示例#44
0
文件: views.py 项目: ZheYuan/gitshell
def find(request):
    user = None
    is_user_exist = False
    username = request.POST.get('username')
    if username is not None:
        if username in MAIN_NAVS:
            is_user_exist = True
        user = GsuserManager.get_user_by_name(username)
    email = request.POST.get('email')
    if email is not None:
        user = GsuserManager.get_user_by_email(email)
    if user is not None:
        is_user_exist = True
    response_dictionary = { 'is_user_exist': is_user_exist }
    return json_httpResponse(response_dictionary)
示例#45
0
def find(request):
    user = None
    is_user_exist = False
    username = request.POST.get('username')
    if username is not None:
        if username in MAIN_NAVS:
            is_user_exist = True
        user = GsuserManager.get_user_by_name(username)
    email = request.POST.get('email')
    if email is not None:
        user = GsuserManager.get_user_by_email(email)
    if user is not None:
        is_user_exist = True
    response_dictionary = {'is_user_exist': is_user_exist}
    return json_httpResponse(response_dictionary)
示例#46
0
文件: views.py 项目: ZheYuan/gitshell
def active(request, user_name):
    title = u'%s / 动态' % user_name
    gsuser = GsuserManager.get_user_by_name(user_name)
    if gsuser is None:
        raise Http404
    gsuserprofile = GsuserManager.get_userprofile_by_id(gsuser.id)
    feedAction = FeedAction()
    pri_user_feeds = feedAction.get_pri_user_feeds(gsuser.id, 0, 50)
    pub_user_feeds = feedAction.get_pub_user_feeds(gsuser.id, 0, 50)
    feeds_as_json = get_feeds_as_json(request, pri_user_feeds, pub_user_feeds)
    response_dictionary = {'mainnav': 'user', 'title': title, 'feeds_as_json': feeds_as_json}
    response_dictionary.update(get_common_user_dict(request, gsuser, gsuserprofile))
    return render_to_response('user/active.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
示例#47
0
 def list_star_user(self, repo_id, offset, row_count):
     stars = query(Star, None, 'star_l_repoId',
                   [repo_id, offset, row_count])
     userprofiles = []
     for x in stars:
         user = GsuserManager.get_user_by_id(x.user_id)
         userprofile = GsuserManager.get_userprofile_by_id(x.user_id)
         if userprofile is None or userprofile.visibly == 1:
             x.visibly = 1
             x.save()
             continue
         userprofile.date_joined = time.mktime(user.date_joined.timetuple())
         userprofile.last_login = time.mktime(user.last_login.timetuple())
         userprofiles.append(userprofile)
     return userprofiles
示例#48
0
 def _do_event(self, event):
     username = event['username']
     reponame = event['reponame']
     remote_git_url = event['remote_git_url']
     local_user = GsuserManager.get_user_by_name(username)
     local_repo = RepoManager.get_repo_by_name(username, reponame)
     if local_user is None or local_repo is None or local_repo.status == 0:
         return
     local_repo_path = local_repo.get_abs_repopath()
     if os.path.exists(local_repo_path):
         return
     args = ['/bin/bash', '/opt/bin/git-import-remote-repo.sh'
             ] + [local_repo_path, remote_git_url]
     try:
         popen = Popen(args, stdout=PIPE, shell=False, close_fds=True)
         output = popen.communicate()[0].strip()
         returncode = popen.returncode
         if returncode == 0:
             RepoManager.check_export_ok_file(local_repo)
             diff_size = long(output)
             RepoManager.update_user_repo_quote(local_user, local_repo,
                                                diff_size)
             local_repo.status = 0
             local_repo.save()
         else:
             local_repo.status = 500
             local_repo.save()
     except Exception, e:
         local_repo.status = 500
         local_repo.save()
         logger.exception(e)
示例#49
0
文件: views.py 项目: drew-sj/gitshell
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)
示例#50
0
def get_userprofile(request):
    if not hasattr(request, '_cached_userprofile'):
        if request.user.is_authenticated():
            request._cached_userprofile = GsuserManager.get_userprofile_by_id(request.user.id)
        else:
            request._cached_userprofile = Userprofile()
    return request._cached_userprofile
示例#51
0
文件: views.py 项目: drew-sj/gitshell
def email_verified(request, token):
    useremail_id = cache.get(token + '_useremail_id')
    usermail = GsuserManager.get_useremail_by_id(useremail_id)
    if usermail and usermail.is_verify == 0 and usermail.user_id == request.user.id:
        usermail.is_verify = 1
        usermail.save()
    return HttpResponseRedirect('/settings/emails/')
示例#52
0
def login_github_relieve(request):
    thirdpartyUser_find = GsuserManager.get_thirdpartyUser_by_id(
        request.user.id)
    if thirdpartyUser_find is not None:
        thirdpartyUser_find.delete()
    response_dictionary = {'code': 200, 'result': 'success'}
    return json_httpResponse(response_dictionary)
示例#53
0
    def _fillwith_notifMessages(self, notifMessages):
        repo_ids = [x.repo_id for x in notifMessages]
        userprofile_ids = [x.user_id for x in notifMessages]
        repo_dict = dict(
            (x.id, x) for x in RepoManager.list_repo_by_ids(repo_ids))
        userprofile_dict = dict(
            (x.id, x)
            for x in GsuserManager.list_userprofile_by_ids(userprofile_ids))
        for notifMessage in notifMessages:
            if notifMessage.repo_id in repo_dict:
                notifMessage.repo = repo_dict[notifMessage.repo_id]
            if notifMessage.from_user_id in userprofile_dict:
                notifMessage.from_userprofile = userprofile_dict[
                    notifMessage.from_user_id]

            if notifMessage.is_at_commit():
                commitHistory = RepoManager.get_commit_by_id(
                    notifMessage.relative_id)
                notifMessage.relative_obj = commitHistory
            elif notifMessage.is_at_issue() or notifMessage.is_issue_cate():
                issue = IssueManager.get_issue_by_id(notifMessage.relative_id)
                notifMessage.relative_obj = issue
            elif notifMessage.is_at_merge(
            ) or notifMessage.is_pull_request_cate():
                pullRequest = RepoManager.get_pullRequest_by_id(
                    notifMessage.relative_id)
                notifMessage.relative_obj = pullRequest
            elif notifMessage.is_at_issue_comment():
                issue_comment = IssueManager.get_issue_comment(
                    notifMessage.relative_id)
                notifMessage.relative_obj = issue_comment
        return notifMessages
示例#54
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'成功添加用户')
示例#55
0
def login_github_apply(request):
    error = u''
    code = request.GET.get('code')
    if code is None:
        error = u'GitHub 关联失败,没有相关 code'
    access_token = github_oauth_access_token(code)
    if access_token == '':
        error = u'GitHub 关联失败,获取不到 access_token,请再次重试'
    thirdpartyUser = github_get_thirdpartyUser(access_token)
    if thirdpartyUser is None or thirdpartyUser.tp_id is None or thirdpartyUser.tp_username is None:
        error = u'获取不到 GitHub 信息,请再次重试'
    thirdpartyUser_find = GsuserManager.get_thirdpartyUser_by_type_tpId(
        ThirdpartyUser.GITHUB, thirdpartyUser.tp_id)
    if thirdpartyUser_find is not None:
        error = u'该 GitHub 账户已经关联 Gitshell,请直接使用 GitHub 账户登录'
    if error != '':
        return HttpResponseRedirect(
            '/%s/-/repo/create/?%s#via-github' %
            (request.user.username,
             urllib.urlencode({'apply_error': error.encode('utf8')})))
    thirdpartyUser.user_type = ThirdpartyUser.GITHUB
    thirdpartyUser.access_token = access_token
    thirdpartyUser.id = request.user.id
    thirdpartyUser.init = 1
    thirdpartyUser.save()
    return HttpResponseRedirect('/%s/-/repo/create/#via-github' %
                                request.user.username)
示例#56
0
文件: views.py 项目: ZheYuan/gitshell
def group(request, username, group_id):
    teamUser = GsuserManager.get_user_by_name(username)
    teamUserprofile = GsuserManager.get_userprofile_by_id(teamUser.id)
    teamGroup = TeamManager.get_teamGroup_by_id(group_id)
    if not teamGroup or teamGroup.team_user_id != teamUser.id:
        raise Http404
    groupMembers = TeamManager.list_groupMember_by_teamGroupId(teamGroup.id)
    userIdInGroupSet = Set([x.member_user_id for x in groupMembers])
    teamMembers = TeamManager.list_teamMember_by_teamUserId(teamUser.id)
    teamMembersNotInGroup = [x for x in teamMembers if x.user_id not in userIdInGroupSet]
    current = 'settings'; sub_nav = 'groups'; title = u'%s / 设置 / 组管理 / %s' % (teamUser.username, teamGroup.name)
    response_dictionary = {'current': current, 'sub_nav': sub_nav, 'title': title, 'teamGroup': teamGroup, 'groupMembers': groupMembers, 'teamMembersNotInGroup': teamMembersNotInGroup}
    response_dictionary.update(_get_common_team_dict(request, teamUser, teamUserprofile))
    return render_to_response('team/group.html',
                          response_dictionary,
                          context_instance=RequestContext(request))