示例#1
1
    def run(self):
        while True:
            username = raw_input('username(%s): ' % getpass.getuser())
            if username == '': 
                username = getpass.getuser()
            if not re.match(r'[A-Za-z\.0-9]+', username):
                print 'Invalid Username'
            else: break
        while True:
            email = raw_input('email: ')
            if not re.match(r'[A-Za-z\.0-9\+]+@\w+(\.\w+)*', email):
                print 'Invalid email'
            else: break
        while True:
            passwd = getpass.getpass('password: '******'repeat: ')
            if passwd != rpasswd:
                print 'Password not matching!'
            else: break

        from vilya.models.user import User
        user = User()
        user.username = username
        user.email = email
        user.admin = True
        user.active = True
        user.set_password(passwd)
        user.save()
        print 'Super user created!'
示例#2
0
文件: git.py 项目: jackfrued/code-1
 def get_commit(self, sha):
     if self.object_type(sha) != 'commit':
         return None
     c = self.cat(sha)
     parent = c['parent'][-1] if c[
         'parent'] else None  # Weird, why would we want only the last one?
     author_name = c['author']['name']
     author_email = email_normalizer(author_name, c['author']['email'])
     author = User(name=author_name, email=author_email)
     committer_name = c['committer']['name']
     committer_email = email_normalizer(committer_name,
                                        c['committer']['email'])
     committer = User(name=committer_name, email=committer_email)
     message = (c['message'] + '\n\n' +
                remove_unknown_character(c['body'])).strip()
     author_time = c['author']['date']
     commit_time = c['committer']['date']
     return Commit(self.project_name,
                   sha=sha,
                   tree=c['tree'],
                   parent=parent,
                   author=author,
                   author_time=author_time,
                   committer=committer,
                   commit_time=commit_time,
                   message=message)
示例#3
0
 def test_get_user_new_badges(self):
     user = User("qingfeng")
     with new_badge(user.username) as badge:
         badge.award(item_id=user.username)
         eq_(len(user.get_new_badges()), 1)
         user.clear_new_badges()
         eq_(len(user.get_new_badges()), 0)
示例#4
0
def _q_index(request):
    context = {}
    if request.method == "POST":
        name = request.get_form_var('name')
        password = request.get_form_var('password')
        email = request.get_form_var('email')
        description = request.get_form_var('description')

        # Forced mail format must be correct
        if not _validate_email(email):
            context['name'] = name
            context['not_validate_email'] = True
            context['password'] = password
            context['email'] = email
            context['description'] = description
            return st('users/new.html', **context)

        user = User.add(name=name,
                        password=password,
                        description=description,
                        email=email)
        if user:
            context['user'] = user
            user.set_session(request)
            request.user = user
            return request.redirect('/')
    users = User.gets_by()
    context['users'] = users
    return st('users/index.html', **context)
示例#5
0
文件: __init__.py 项目: leeccong/code
def _q_index(request):
    context = {}
    if request.method == "POST":
        name = request.get_form_var("name")
        password = request.get_form_var("password")
        email = request.get_form_var("email")
        description = request.get_form_var("description")

        # Forced mail format must be correct
        if not _validate_email(email):
            context["name"] = name
            context["not_validate_email"] = True
            context["password"] = password
            context["email"] = email
            context["description"] = description
            return st("users/new.html", **context)

        user = User.add(name=name, password=password, description=description, email=email)
        if user:
            context["user"] = user
            user.set_session(request)
            request.user = user
            return request.redirect("/")
    users = User.gets_by()
    context["users"] = users
    return st("users/index.html", **context)
示例#6
0
def card_info(request):
    user_or_team_id = request.get_form_var('user')
    team = Team.get_by_uid(user_or_team_id)
    user_existed = User.check_exist(user_or_team_id)
    if not team or user_existed:
        user = User(user_or_team_id)
        data = {
            'user': {'name': user_or_team_id, 'avatar': user.avatar_url,
                     'url': user.url,
                     'badges': [{'img': item.badge.get_image_url(),
                                 'name': item.badge.name,
                                 'reason': item.reason or item.badge.summary}
                                for item in user.get_badge_items()]}
        }
    else:
        members = team.user_ids[::-1]  # 根据团队的时间排序
        displayed_users = [User(uid) for uid in team.user_ids[:8]]
        data = {
            'team': {
                'id': team.uid,
                'name': team.name,
                'url': team.url,
                'desc': team.short_description,
                'profile_url': team.profile_url(),
                'members': [{'uid': u.name, 'avatar_url': u.avatar_url}
                            for u in displayed_users],
                'member_count': len(members)
            }
        }
    return json.dumps(data)
示例#7
0
    def test_single_project(self):
        skip_test()
        u_to = User("admin")
        u_from = User("testuser")
        to_proj = self._prj("test", "admin")
        self._add(to_proj, u_to, "README.md", "hi")
        from_proj = self._prj("testuser/test", "testuser", to_proj.id)
        self._add(from_proj, u_from, "README.md", "hello")
        pullreq = PullRequest.open(from_proj, "master", to_proj, "master")
        ticket = Ticket(None, None, to_proj.id, "title", "desc", "testuser",
                        None, None)
        pullreq = add_pull(ticket, pullreq, u_from)

        iss = ProjectIssue.add(title='title1',
                               description='desc1',
                               creator='owner',
                               project=to_proj.id)
        IssuePRSearch.index_a_project(to_proj)
        res = IssueSearch.search_a_phrase('title1', to_proj.id)
        res = SearchEngine.decode(res, ('issue_id', ))
        res = [id for id, in res]
        assert len(res) == 1
        assert res[0] == iss.id
        res = PullRequestSearch.search_a_phrase('title', to_proj.id)
        res = SearchEngine.decode(res, ('issue_id', ))
        res = [id for id, in res]
        assert len(res) == 1
示例#8
0
    def add_user(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user or not team:
            return dict(r=1, error="team不存在")

        user_id = request.get_form_var('user_id', '')
        identity = int(request.get_form_var('identity', 0))

        if not team.is_owner(user.name) \
                or identity not in TEAM_IDENTITY_INFO.keys():
            return dict(r=1, error="没有权限")

        rl = TeamUserRelationship.get(team_id=team.id, user_id=user_id)
        if not rl:
            team.add_user(User(user_id), identity)
        elif identity == rl.identity:
            return dict(r=1, error="该用户已存在")
        elif rl.is_owner and team.n_owners == 1:
            return dict(r=1, error="只剩一个creator, 不能改变身份")
        else:
            rl.identity = identity
            rl.save()

        avatar_url = User(user_id).avatar_url
        team_add_member_signal.send(
            user.name, team_uid=team.uid, team_name=team.name,
            receiver=user_id, identity=TEAM_IDENTITY_INFO[identity]["name"])
        return dict(r=0, uid=user_id, avatar_url=avatar_url)
示例#9
0
文件: irc.py 项目: 000fan000/code
 def irc_receiver_filter(receivers, target):
     from vilya.models.user import User
     rs = set()
     for receiver in receivers:
         user = User(receiver)
         if user and user.notify_irc(target):
             rs.add(receiver)
     return rs
示例#10
0
 def test_simple_user(self):
     u = User('testu')
     assert u.name == 'testu'
     assert 'douvatar' in u.avatar_url
     assert u.get_badges() == []
     assert u.email == '*****@*****.**'
     assert u.username == 'testu'
     assert u.url == '/people/testu/'
示例#11
0
 def test_user_with_email_from_outside_douba(self):
     u = User('testu', '*****@*****.**')
     assert u.name == 'testu'
     assert 'douvatar' in u.avatar_url
     assert u.get_badges() == []
     assert u.email == '*****@*****.**'
     assert u.username == 'testu'
     assert u.url == '/people/testu/'
示例#12
0
 def irc_receiver_filter(receivers, target):
     from vilya.models.user import User
     rs = set()
     for receiver in receivers:
         user = User(receiver)
         if user and user.notify_irc(target):
             rs.add(receiver)
     return rs
示例#13
0
 def addrs_by_usernames(usernames, target=None):
     addrs = set()
     for username in usernames:
         user = User(username) if username else None
         if user:
             if (target and user.notify_email(target)) or not target:
                 addrs.add(user.email)
                 addrs = addrs.union(user.settings.notif_other_emails)
     return addrs
示例#14
0
文件: mailer.py 项目: 000fan000/code
 def addrs_by_usernames(usernames, target=None):
     addrs = set()
     for username in usernames:
         user = User(username) if username else None
         if user:
             if (target and user.notify_email(target)) or not target:
                 addrs.add(user.email)
                 addrs = addrs.union(user.settings.notif_other_emails)
     return addrs
示例#15
0
    def add_participant(self, username):
        participants = self.participants
        if username and username not in participants:
            participants.append(username)
            self.set_props_item('participants', participants)

            user = User(username)
            user.add_participated_pull_request(self.id)
        return self.participants
示例#16
0
文件: ticket.py 项目: leeccong/code
    def add_participant(self, username):
        participants = self.participants
        if username and username not in participants:
            participants.append(username)
            self.set_props_item('participants', participants)

            user = User(username)
            user.add_participated_pull_request(self.id)
        return self.participants
示例#17
0
 def setUp(self):
     super(FollowTest, self).setUp()
     user_name1 = 'zhangchi'
     email = '*****@*****.**' % user_name1
     self.zhangchi = User(user_name1, email)
     user_name2 = 'lijunpeng'
     email = '*****@*****.**' % user_name2
     self.lijunpeng = User(user_name2, email)
     self.api_token_zhangchi = self.create_api_token('zhangchi')
     self.api_token_lijunpeng = self.create_api_token('lijunpeng')
示例#18
0
def autocomplete_users(request):
    q = request.get_form_var('q')
    users = CodeDoubanProject.search_for_owners(name=q, limit=7)
    data = {
        'users': [{
            'name': user,
            'avatar': User(user).avatar_url,
            'url': User(user).url
        } for user in users]
    }
    return json.dumps(data)
示例#19
0
文件: people.py 项目: leeccong/code
 def _q_index(self, request):
     name = self.name
     your_projects = CodeDoubanProject.get_projects(owner=name, sortby="lru")
     actions = get_user_feed(name).get_actions(0, 20)
     user = User(name)
     teams = Team.get_by_user_id(user.name)
     badge_items = user.get_badge_items()
     followers_count = user.followers_count
     following_count = user.following_count
     if user and user.username == name and user.get_new_badges():
         user.clear_new_badges()
     return st("people.html", **locals())
示例#20
0
文件: feed.py 项目: leeccong/code
 def get_related_user_inbox_feeds(self):
     ''' user_timeline of actor, actor's followers, project owner,
         project's watchers, extra_receivers '''
     sender = User(self._sender)
     followers = sender.get_followers() if sender else []
     project = self._project
     if project:
         proj_users = [u.username for u in project.get_watch_users()]
         proj_users.append(project.owner.username)
     else:
         proj_users = []
     receivers = {self._sender} | set(followers) | set(proj_users) | self._receivers  # noqa
     return [get_user_inbox(r) for r in receivers]
示例#21
0
    def test_get_user_submitted_pull_requests(self):
        title = 'test title'
        desc = 'test desc'
        u = User('testu%s' % time.time())
        p1_t1 = Ticket.add(self.proj1.id, title, desc, u.username)
        assert u.get_user_submit_pull_requests() != []
        assert u.n_user_open_submit_pull_requests == 1

        p1_t1.close('testuser')
        assert u.get_user_submit_pull_requests() == []
        assert u.n_user_open_submit_pull_requests == 0

        assert u.n_open_pull_requests == 0
示例#22
0
    def test_get_user_submitted_pull_requests(self):
        title = 'test title'
        desc = 'test desc'
        u = User('testu%s' % time.time())
        p1_t1 = Ticket.add(self.proj2.id, title, desc, u.username)
        assert u.get_user_submit_pull_requests() != []
        assert u.n_user_open_submit_pull_requests == 1

        p1_t1.close('testuser')
        assert u.get_user_submit_pull_requests() == []
        assert u.n_user_open_submit_pull_requests == 0

        assert u.n_open_pull_requests == 0
示例#23
0
 def test_follow(self):
     User('testuser2').follow('testuser1')
     User('testuser3').follow('testuser1')
     assert len(User('testuser1').get_followers()) == 2
     User('testuser3').follow('testuser1')
     assert len(User('testuser1').get_followers()) == 2
     User('testuser3').unfollow('testuser1')
     assert len(User('testuser1').get_followers()) == 1
     User('testuser2').unfollow('testuser1')
     assert len(User('testuser1').get_followers()) == 0
示例#24
0
    def __init__(self, repo, commit):
        self.repo = repo
        self._commit = commit
        self.type = 'commit'
        self.repo_name = repo.name
        parent = commit['parent'][0] if commit['parent'] else None
        self.parent = parent
        self.parents = commit['parent']
        message = ("%s\n\n%s" %
                   (commit['message'], remove_unknown_character(
                       commit['body']))).strip()
        self.message = message
        self.message_header = commit['message']
        self.message_body = commit['body']
        self.sha = commit['sha']
        self.tree = commit['tree']
        self.has_author_link = True

        # author
        author_name = commit['author']['name']
        self.author_name = author_name
        author_email = commit['author']['email']
        self.author_email = author_email
        self.email = author_email
        code_author_name = get_author_by_email(author_email, None)
        if code_author_name is None:
            self.has_author_link = False
            author = User(name=author_name, email=author_email)
        else:
            author = User(name=code_author_name, email=author_email)
        self.author = author
        author_date = datetime.fromtimestamp(
            commit['author']['time'], FixedOffset(commit['author']['offset']))
        self.author_time = author_date
        author_timestamp = str(commit['author']['time'])
        self.author_timestamp = author_timestamp
        self.time = author_date

        # committer
        committer_name = commit['committer']['name']
        committer_email = email_normalizer(committer_name,
                                           commit['committer']['email'])
        committer = User(name=committer_name, email=committer_email)
        self.committer = committer
        committer_date = datetime.fromtimestamp(
            commit['committer']['time'],
            FixedOffset(commit['committer']['offset']))
        self.committer_time = committer_date
        self.commit_time = committer_date  # FIXME: remove this!
示例#25
0
 def get_related_user_inbox_feeds(self):
     ''' user_timeline of actor, actor's followers, project owner,
         project's watchers, extra_receivers '''
     sender = User(self._sender)
     followers = sender.get_followers() if sender else []
     project = self._project
     if project:
         proj_users = [u.username for u in project.get_watch_users()]
         proj_users.append(project.owner.username)
     else:
         proj_users = []
     receivers = {
         self._sender
     } | set(followers) | set(proj_users) | self._receivers  # noqa
     return [get_user_inbox(r) for r in receivers]
示例#26
0
def get_git_path_info(path):
    path_split = path.split("/")
    git_name = path_split[1]
    # raw path: project_id.git
    if git_name.endswith('.git'):
        project = Project.get_by_name(git_name[:-4])
        if project:
            path_split[1] = "%s.git" % project.id
            return '/'.join(path_split)
    else:
        owner_name, git_name = path_split[1:3]
        # user project: user/project.git
        user = User.get_by_name(owner_name)
        if user:
            project = Project.get_by_name_and_owner(git_name[:-4], user.id)
            if project:
                path_split[1] = ""
                path_split[2] = "%s.git" % project.id
                return '/'.join(path_split[1:])
            return
        # org project: org/project.git
        org = Organization.get_by_name(owner_name)
        if org:
            project = Project.get_by_name_and_owner(git_name[:-4], user.id)
            if project:
                path_split[1] = ""
                path_split[2] = "%s.git" % project.id
                return '/'.join(path_split[1:])
示例#27
0
def get_git_path_info(path):
    path_split = path.split("/")
    git_name = path_split[1]
    # raw path: project_id.git
    if git_name.endswith('.git'):
        project = Project.get_by_name(git_name[:-4])
        if project:
            path_split[1] = "%s.git" % project.id
            return '/'.join(path_split)
    else:
        owner_name, git_name = path_split[1:3]
        # user project: user/project.git
        user = User.get_by_name(owner_name)
        if user:
            project = Project.get_by_name_and_owner(git_name[:-4], user.id)
            if project:
                path_split[1] = ""
                path_split[2] = "%s.git" % project.id
                return '/'.join(path_split[1:])
            return
        # org project: org/project.git
        org = Organization.get_by_name(owner_name)
        if org:
            project = Project.get_by_name_and_owner(git_name[:-4], user.id)
            if project:
                path_split[1] = ""
                path_split[2] = "%s.git" % project.id
                return '/'.join(path_split[1:])
示例#28
0
文件: pull.py 项目: jackfrued/code-1
    def comment(self, request):
        if request.method == 'POST':
            content = request.get_form_var('content').decode('utf-8')
            if not content.strip():
                return {'error': 'Content is empty!'}
            user = request.user
            current_user = request.user
            author = user.name
            comment = self.ticket.add_comment(content, author)
            ticket = self.ticket
            pullreq = self.pullreq
            project = self.project
            html = st('/pull/ticket_comment.html', **locals())

            if request.get_form_var('comment_and_close'):

                close_pull(ticket, pullreq, user, content, comment, request)

                return dict(r=0, reload=1, redirect_to=self.url)
            elif request.get_form_var('comment_and_reopen'):
                if not pullreq.is_temp_pull():
                    ticket.open(author)
                return dict(r=0, reload=1, redirect_to=self.url)
            else:
                at_users = get_mentions_from_text(content)
                for u in at_users:
                    User(u).add_invited_pull_request(ticket.id)
            return dict(r=0, html=html)
        return request.redirect(self.url)
示例#29
0
文件: git.py 项目: jackfrued/code-1
 def get_commits(self, path='', ref='HEAD'):
     if self.object_type(ref, path) != 'tree':
         raise IOError('get_commits works on a tree')
     bag = {}
     for item in self._list_tree(ref, path):
         sha = item['id']
         bag[sha] = {
             'id': sha,
             'mode': item['mode'],
             'type': item['type'],
             'name': item['name'],
             'path': item['path'],
         }
         latest_commit_sha = self.latest_commit(item['path'], ref)
         if latest_commit_sha:
             l_com = self.cat(latest_commit_sha)
             user = l_com['author']['email']
             user_t = user.split('@')[0] if '@' in user else user
             bag[sha]['contributor'] = user_t
             if check_douban_email(user):
                 bag[sha]['contributor_url'] = User(user_t).url
             else:
                 bag[sha]['contributor_url'] = False
             bag[sha]['message'] = l_com['message']
             bag[sha]['hash'] = latest_commit_sha
             bag[sha]['age'] = compute_relative_time(l_com['author']['ts'])
         else:
             bag[sha]['contributor'] = ''
             bag[sha]['contributor_url'] = ''
             bag[sha]['message'] = ''
             bag[sha]['hash'] = ''
             bag[sha]['age'] = ''
     return bag
示例#30
0
def add_team(request):
    user = request.user
    if not user:
        return request.redirect("/")

    uid = request.get_form_var('uid') or ''
    name = request.get_form_var('name') or ''
    description = request.get_form_var('description') or ''

    errors = ""
    if request.method == "POST":
        teams = Team.gets()
        team_uid_pattern = re.compile(r'[a-zA-Z0-9\_]*')
        if not uid:
            error = 'uid_not_exists'
        elif not name:
            error = 'name_not_exists'
        elif uid != re.findall(team_uid_pattern, uid)[0]:
            error = 'invilid_uid'
        elif uid in [team.uid for team in teams]:
            error = 'uid_existed'
        elif User.check_exist(uid):
            error = 'user_id_existed'
        elif name in [team.name for team in teams]:
            error = 'name_existed'
        else:
            team = Team.add(uid, name, description)
            if team:
                team_created_signal.send(user.name,
                                         team_name=team.name,
                                         team_uid=team.uid)
                team.add_user(user, TEAM_OWNER)
                return request.redirect(team.url)

    return st('/teams/add_team.html', **locals())
示例#31
0
def get_related_feeds(actor, project=None, extra_receivers=[], team_ids=[]):
    # FIXME: team_ids->team_id, 貌似没看到 team_ids 的需求
    ''' user_timeline of actor, actor's followers, project owner,
        project's watchers, extra_receivers;
        team_timeline of project related team, team_ids;
        public_timeline;
        user_profile_timeline of actor '''
    followers = User(actor).get_followers() if actor else []
    proj_users = []
    if project:
        proj_users += [u.username for u in project.get_watch_users()]
        proj_users.append(project.owner.username)
    users = filter(
        None,
        list(set([actor] + followers + proj_users + list(extra_receivers))))
    feeds = [get_user_inbox(user) for user in users]
    if project:
        rls = TeamProjectRelationship.gets(project_id=project.id)
        feeds.extend([get_team_feed(rl.team_id) for rl in rls])
    if team_ids:
        feeds.extend([get_team_feed(id) for id in team_ids])
    feeds.append(get_public_feed())
    if actor:
        feeds.append(get_user_feed(actor))
    return feeds
示例#32
0
def add_team(request):
    user = request.user
    if not user:
        return request.redirect("/")

    uid = request.get_form_var('uid') or ''
    name = request.get_form_var('name') or ''
    description = request.get_form_var('description') or ''

    errors = ""
    if request.method == "POST":
        teams = Team.gets()
        team_uid_pattern = re.compile(r'[a-zA-Z0-9\_]*')
        if not uid:
            error = 'uid_not_exists'
        elif not name:
            error = 'name_not_exists'
        elif uid != re.findall(team_uid_pattern, uid)[0]:
            error = 'invilid_uid'
        elif uid in [team.uid for team in teams]:
            error = 'uid_existed'
        elif User.check_exist(uid):
            error = 'user_id_existed'
        elif name in [team.name for team in teams]:
            error = 'name_existed'
        else:
            team = Team.add(uid, name, description)
            if team:
                team_created_signal.send(user.name,
                                         team_name=team.name,
                                         team_uid=team.uid)
                team.add_user(user, TEAM_OWNER)
                return request.redirect(team.url)

    return st('/teams/add_team.html', **locals())
示例#33
0
 def get_info(self, without_commits=False):
     #authors = self.git.get_gitstats_data().authors
     info = {
         'url': self.repo_url,
         'name': self.name,
         'description': self.summary,
         'product': self.product,
         'watched_count': self.get_watched_count(self.id),
         'committers_count': len(self.committers),
         'forked_count': self.get_forked_count(self.id),
         'open_issues_count': self.n_open_issues,
         'open_tickets_count': self.n_open_tickets,
         'owner': {
             'name': self.owner_name,
             'avatar': User(self.owner_id).avatar_url,
         },
     }
     forked_from = self.get_forked_from()
     if forked_from:
         info.update({"forked_from": forked_from.get_info(without_commits)})
     if not without_commits:
         commit = self.repo.get_commit('HEAD')
         if commit:
             info['last_commit'] = commit.as_dict()
     return info
示例#34
0
    def merge(self, merger, message_header, message_body):
        # TODO: Use User only
        if merger and isinstance(merger, basestring):
            merger = User(merger)
        if not isinstance(merger, User):
            raise Exception("User is needed to merge pull")
        env = make_git_env(merger)

        worktree = self.temp_dir
        merge_commit_sha = None
        try:
            if self.pull.is_up_to_date():
                return ''

            from_sha = self.from_sha
            to_sha = self.to_sha
            repo = self.pull.pull_clone(worktree)
            if self.from_local:
                ref = self.pull.pull_fetch_local(repo)
            else:
                ref = self.pull.pull_fetch_remote(repo)
            repo.merge(ref, message_header, message_body, no_ff=True, _env=env)
            repo.push('origin', self.pull.to_ref)
            merge_commit_sha = self.sha(self.pull.to_ref)
            self.pull._save_merged(merger.name, from_sha, to_sha)
        finally:
            shutil.rmtree(worktree)
        return merge_commit_sha
示例#35
0
    def add_codereview(self, request):
        content = request.data.get('content')
        from_sha = request.data.get('from_sha')
        to_sha = request.data.get('to_sha')
        old_path = request.data.get('old_path')
        new_path = request.data.get('new_path')
        from_oid = request.data.get('from_oid')
        to_oid = request.data.get('to_oid')
        new_no = request.data.get('new_no')
        old_no = request.data.get('old_no', '')

        for t in ('content', 'from_sha', 'old_path', 'new_path', 'from_oid',
                  'to_oid', 'new_no'):
            val = locals()[t]
            if not val.strip():
                raise MissingFieldError(t)
        old_no = int(old_no) if old_no.isdigit() else LINECOMMENT_INDEX_EMPTY
        new_no = int(new_no) if new_no.isdigit() else LINECOMMENT_INDEX_EMPTY

        author = request.data.get('username')
        if not author:
            author = request.user.name
        self.ticket.add_codereview(from_sha, to_sha, old_path, new_path,
                                   from_oid, to_oid, old_no, new_no, author,
                                   content)

        at_users = get_mentions_from_text(content)
        for u in at_users:
            User(u).add_invited_pull_request(self.ticket.id)
        return {'ok': True}
示例#36
0
 def check_permission(self, request, proj_name):
     project = CodeDoubanProject.get_by_name(proj_name)
     user = request.user
     if not project or \
        not user and project.intern_banned or \
        user and user.is_intern and project.intern_banned \
        and not project.is_admin(user.username):
         return request.redirect(User.create_login_url(request.url))
示例#37
0
 def check_permission(self, request, proj_name):
     project = CodeDoubanProject.get_by_name(proj_name)
     user = request.user
     if not project or \
        not user and project.intern_banned or \
        user and user.is_intern and project.intern_banned \
        and not project.is_admin(user.username):
         return request.redirect(User.create_login_url(request.url))
示例#38
0
def _get_user_by_name(name):
    user = {}
    _user = User(name)
    user = dict(
        name=_user.name,
        icon=_user.avatar_url,
    )
    return user
示例#39
0
 def __init__(self, project_id, ticket_number, hl_description):
     self.ticket = Ticket.get_by_projectid_and_ticketnumber(
         project_id, ticket_number)
     self.ticket_project = CodeDoubanProject.get(self.ticket.project_id)
     self.author = User(self.ticket.author)
     self.ticket_url = self.ticket.url
     self.hl_description = hl_description if hl_description \
         else self.ticket.description
示例#40
0
def card_info(request):
    user_or_team_id = request.get_form_var('user')
    team = Team.get_by_uid(user_or_team_id)
    user_existed = User.check_exist(user_or_team_id)
    if not team or user_existed:
        user = User(user_or_team_id)
        data = {
            'user': {
                'name':
                user_or_team_id,
                'avatar':
                user.avatar_url,
                'url':
                user.url,
                'badges': [{
                    'img': item.badge.get_image_url(),
                    'name': item.badge.name,
                    'reason': item.reason or item.badge.summary
                } for item in user.get_badge_items()]
            }
        }
    else:
        members = team.user_ids[::-1]  # 根据团队的时间排序
        displayed_users = [User(uid) for uid in team.user_ids[:8]]
        data = {
            'team': {
                'id':
                team.uid,
                'name':
                team.name,
                'url':
                team.url,
                'desc':
                team.short_description,
                'profile_url':
                team.profile_url(),
                'members': [{
                    'uid': u.name,
                    'avatar_url': u.avatar_url
                } for u in displayed_users],
                'member_count':
                len(members)
            }
        }
    return json.dumps(data)
示例#41
0
文件: oauth.py 项目: 000fan000/code
def __token_grant_by_password(apikey):
    username = __check_request_required_var('username')
    password = __check_request_required_var('password')
    user = User.get_by_name(username)
    if not DEVELOP_MODE and user and not user.validate_password(password):
        raise InvalidRequest(err.username_password_mismatch)

    token = ApiToken.add(apikey.client_id, username)
    return json.dumps(token.token_dict())
示例#42
0
 def test_single_project(self):
     skip_test()
     u_to = User("admin")
     u_from = User("testuser")
     to_proj = self._prj("test", "admin")
     self._add(to_proj, u_to, "README.md", "hi")
     from_proj = self._prj("testuser/test", "testuser", to_proj.id)
     self._add(from_proj, u_from, "README.md", "hello")
     pullreq = PullRequest.open(from_proj, "master", to_proj, "master")
     ticket = Ticket(None, None, to_proj.id, "title", "desc", "testuser",
                     None, None)
     pullreq = add_pull(ticket, pullreq, u_from)
     ticket = pullreq.ticket
     PullRequestSearch.index_a_project_pr(to_proj)
     res = PullRequestSearch.search_a_phrase('title', to_proj.id)
     res = SearchEngine.decode(res, ('to_proj_id', ))
     res = [id for id, in res]
     assert len(res) == 1
示例#43
0
def _q_lookup(request, name):
    if name == 'static':
        return StaticUI(request)
    if name == 'fair':
        return FairUI(request)
    if CodeDoubanProject.exists(name):
        return CodeUI(name)
    if User.check_exist(name):
        return UserPrefixedRepoAdapter(name)
示例#44
0
def __token_grant_by_password(apikey):
    username = __check_request_required_var('username')
    password = __check_request_required_var('password')
    user = User.get_by_name(username)
    if not DEVELOP_MODE and user and not user.validate_password(password):
        raise InvalidRequest(err.username_password_mismatch)

    token = ApiToken.add(apikey.client_id, username)
    return json.dumps(token.token_dict())
示例#45
0
文件: project.py 项目: 377262688/code
 def owner_name(self):
     from vilya.models.user import User
     from vilya.models.organization import Organization
     if self.kind == KIND_USER:
         user = User.get_by(id=self.owner_id)
         return user.name
     else:
         org = Organization.get_by(id=self.owner_id)
         return org.name
示例#46
0
文件: utils.py 项目: 377262688/code
def api_list_user(users):
    rs = []
    for username in users:
        user = User.get_by_name(username)
        rs.append({'username': user.username,
                   'avatar_url': user.avatar_url,
                   'email': user.email,
                   'url': user.url, })
    return rs
示例#47
0
def _q_lookup(request, name):
    if name == 'static':
        return StaticUI(request)
    if name == 'fair':
        return FairUI(request)
    if CodeDoubanProject.exists(name):
        return CodeUI(name)
    if User.check_exist(name):
        return UserPrefixedRepoAdapter(name)
示例#48
0
文件: commit.py 项目: 377262688/code
    def __init__(self, repo, commit):
        self.repo = repo
        self._commit = commit
        self.type = 'commit'
        self.repo_name = repo.name
        parent = commit['parent'][0] if commit['parent'] else None
        self.parent = parent
        self.parents = commit['parent']
        message = ("%s\n\n%s" % (
            commit['message'],
            remove_unknown_character(commit['body']))
        ).strip()
        self.message = message
        self.message_header = commit['message']
        self.message_body = commit['body']
        self.sha = commit['sha']
        self.tree = commit['tree']

        author_name = commit['author']['name']
        self.author_name = author_name
        author_email = email_normalizer(author_name, commit['author']['email'])
        self.author_email = author_email
        self.email = author_email
        # FIXME: user
        #author = User(name=author_name, email=author_email)
        author = User.get_by_name(author_name)
        self.author = author
        author_date = datetime.fromtimestamp(commit['author']['time'],
                                             FixedOffset(commit['author']['offset']))
        author_timestamp = str(commit['author']['time'])
        self.author_time = author_date
        self.author_timestamp = author_timestamp
        self.time = author_date

        committer_name = commit['committer']['name']
        committer_email = email_normalizer(
            committer_name, commit['committer']['email'])
        # FIXME: user
        #committer = User(name=committer_name, email=committer_email)
        committer = User.get_by_name(committer_name)
        self.committer = committer
        committer_date = datetime.fromtimestamp(commit['committer']['time'],
                                             FixedOffset(commit['committer']['offset']))
        self.committer_time = committer_date
示例#49
0
文件: login.py 项目: 377262688/code
def _q_index(request):
    if request.method == 'POST':
        name = request.get_form_var('login')
        password = request.get_form_var('password')
        user = User.get_by_name(name)
        if user and user.validate_password(password):
            user.set_session(request)
            request.user = user
            return request.redirect('/')
    return st('login.html')
示例#50
0
 def setUp(self):
     super(FollowTest, self).setUp()
     user_name1 = 'zhangchi'
     email = '*****@*****.**' % user_name1
     self.zhangchi = User(user_name1, email)
     user_name2 = 'lijunpeng'
     email = '*****@*****.**' % user_name2
     self.lijunpeng = User(user_name2, email)
     self.api_token_zhangchi = self.create_api_token('zhangchi')
     self.api_token_lijunpeng = self.create_api_token('lijunpeng')
示例#51
0
 def __init__(self, header):
     self.login = None
     self.passwd = None
     self.user = None
     try:
         auth_type, auth_string = header.split()
         login, passwd = b64decode(auth_string).split(':')
         self.login = login
         self.passwd = passwd
         self.user = User.get_by_name(login)
     except (ValueError, TypeError):
         pass
示例#52
0
def _q_lookup(request, name):
    if name in ['static', 'js', 'css']:
        return StaticUI(request, name)

    user = User.get_by_name(name)
    if user:
        return UserUI(user)

    org = Organization.get_by_name(name)
    if org:
        return OrganizationUI(org)

    raise TraversalError
示例#53
0
    def _q_lookup(self, request, name):
        from vilya.views.api.v1.users import UserUI
        from vilya.views.api.v1.organizations import OrganizationUI

        user = User.get_by_name(name)
        if user:
            return UserUI(user)

        org = Organization.get_by_name(name)
        if org:
            return OrganizationUI(org)

        raise TraversalError
示例#54
0
文件: login.py 项目: leeccong/code
def _q_index(request):
    if request.method == 'POST':
        name = request.get_form_var('username')
        password = request.get_form_var('password')
        user = User.get_by_name(name)
        if user and user.validate_password(password):
            continue_url = request.get_form_var(
                'continue', '') or request.get_form_var('Referer', '')
            request.user = user
            set_user(user.id)
            return json.dumps({"r": 0, "continue": continue_url or "/"})
        return json.dumps({"r": 1})
    return st('login.html')
示例#55
0
文件: badge.py 项目: leeccong/code
 def people(self, request):
     current_user = request.user
     badge = self.badge
     if not current_user:
         return request.redirect("/badge/%s/" % badge.id)
     if current_user.name not in ["liwanjin", "xutao"]:
         return request.redirect("/badge/%s/" % badge.id)
     if request.method != "POST":
         return request.redirect("/badge/%s/" % badge.id)
     name = request.get_form_var("name")
     reason = request.get_form_var("reason")
     if not name:
         return request.redirect("/badge/%s/" % badge.id)
     if not User.check_exist(name):
         return request.redirect("/badge/%s/" % badge.id)
     badge.award(name, reason=reason)
     return request.redirect("/badge/%s/" % badge.id)
示例#56
0
文件: web.py 项目: 377262688/code
    def start_request(self, request):
        Publisher.start_request(self, request)
        os.environ['SQLSTORE_SOURCE'] = request.get_url()

        resp = request.response
        resp.set_content_type('text/html; charset=utf-8')
        resp.set_header('Pragma', 'no-cache')
        resp.set_header('Cache-Control', 'must-revalidate, no-cache, private')
        # FIXME: quixote with origin?
        resp.set_header('Access-Control-Allow-Origin', '*')
        request.enable_ajax = False
        request.browser = request.guess_browser_version()
        request.method = request.get_method()
        request.url = request.get_path()
        request.is_mobile = is_mobile_device(request)
        request.start_time = time.time()
        request.user = User.check_session(request)

        import_obj_set("request", request)
示例#57
0
文件: app_sina.py 项目: leeccong/code
def authfunc(env, username, passwd):
    if DEVELOP_MODE or (env['REMOTE_ADDR'] == '127.0.0.1'
                        and env['HTTP_HOST'] == 'localhost:8080'):
        return True

    if not passwd:
        return

    if username == 'code' and passwd == 'code':
        return True

    user = User.get_by_name(username)
    if user and user.validate_password(passwd):
        return True

    is_push = 'service=git-receive-pack' in env['QUERY_STRING'] \
              or '/git-receive-pack' in env['PATH_INFO']
    if is_push:
        pass
        # FIXME: push permission
    return True