コード例 #1
0
ファイル: repos.py プロジェクト: pombredanne/rhodecode
    def repo_public_journal(self, repo_name):
        """
        Set's this repository to be visible in public journal,
        in other words assing default user to follow this repo

        :param repo_name:
        """

        cur_token = request.POST.get('auth_token')
        token = get_token()
        if cur_token == token:
            try:
                repo_id = Repository.by_repo_name(repo_name).repo_id
                user_id = User.by_username('default').user_id
                self.scm_model.toggle_following_repo(repo_id, user_id)
                h.flash(_('Updated repository visibility in public journal'),
                        category='success')
            except:
                h.flash(_('An error occurred during setting this'
                          ' repository in public journal'),
                        category='error')

        else:
            h.flash(_('Token mismatch'), category='error')
        return redirect(url('edit_repo', repo_name=repo_name))
コード例 #2
0
ファイル: test_login.py プロジェクト: pombredanne/rhodecode
    def test_forgot_password(self):
        response = self.app.get(url(controller='login',
                                    action='password_reset'))
        self.assertEqual(response.status , '200 OK')

        username = '******'
        password = '******'
        email = '*****@*****.**'
        name = 'passwd'
        lastname = 'reset'

        new = User()
        new.username = username
        new.password = password
        new.email = email
        new.name = name
        new.lastname = lastname
        new.api_key = generate_api_key(username)
        self.sa.add(new)
        self.sa.commit()

        response = self.app.post(url(controller='login',
                                     action='password_reset'),
                                 {'email':email, })

        self.checkSessionFlash(response, 'Your password reset link was sent')

        response = response.follow()

        # BAD KEY

        key = "bad"
        response = self.app.get(url(controller='login',
                                    action='password_reset_confirmation',
                                    key=key))
        self.assertEqual(response.status, '302 Found')
        self.assertTrue(response.location.endswith(url('reset_password')))

        # GOOD KEY

        key = User.by_username(username).api_key

        response = self.app.get(url(controller='login',
                                    action='password_reset_confirmation',
                                    key=key))
        self.assertEqual(response.status, '302 Found')
        self.assertTrue(response.location.endswith(url('login_home')))

        self.checkSessionFlash(response,
                               ('Your password reset was successful, '
                                'new password has been sent to your email'))

        response = response.follow()
コード例 #3
0
ファイル: login.py プロジェクト: pombredanne/rhodecode
    def index(self):
        #redirect if already logged in
        c.came_from = request.GET.get('came_from', None)

        if self.rhodecode_user.is_authenticated \
                            and self.rhodecode_user.username != 'default':

            return redirect(url('home'))

        if request.POST:
            #import Login Form validator class
            login_form = LoginForm()
            try:
                c.form_result = login_form.to_python(dict(request.POST))
                #form checks for username/password, now we're authenticated
                username = c.form_result['username']
                user = User.by_username(username,
                                                   case_insensitive=True)
                auth_user = AuthUser(user.user_id)
                auth_user.set_authenticated()
                session['rhodecode_user'] = auth_user
                session.save()

                log.info('user %s is now authenticated and stored in session',
                         username)
                user.update_lastlogin()

                if c.came_from:
                    return redirect(c.came_from)
                else:
                    return redirect(url('home'))

            except formencode.Invalid, errors:
                return htmlfill.render(
                    render('/login.html'),
                    defaults=errors.value,
                    errors=errors.error_dict or {},
                    prefix_error=False,
                    encoding="UTF-8")
コード例 #4
0
ファイル: repo.py プロジェクト: pombredanne/rhodecode
    def update(self, repo_name, form_data):
        try:
            cur_repo = self.get_by_repo_name(repo_name, cache=False)

            # update permissions
            for member, perm, member_type in form_data["perms_updates"]:
                if member_type == "user":
                    r2p = (
                        self.sa.query(RepoToPerm)
                        .filter(RepoToPerm.user == User.by_username(member))
                        .filter(RepoToPerm.repository == cur_repo)
                        .one()
                    )

                    r2p.permission = self.sa.query(Permission).filter(Permission.permission_name == perm).scalar()
                    self.sa.add(r2p)
                else:
                    g2p = (
                        self.sa.query(UsersGroupRepoToPerm)
                        .filter(UsersGroupRepoToPerm.users_group == UsersGroup.get_by_group_name(member))
                        .filter(UsersGroupRepoToPerm.repository == cur_repo)
                        .one()
                    )

                    g2p.permission = self.sa.query(Permission).filter(Permission.permission_name == perm).scalar()
                    self.sa.add(g2p)

            # set new permissions
            for member, perm, member_type in form_data["perms_new"]:
                if member_type == "user":
                    r2p = RepoToPerm()
                    r2p.repository = cur_repo
                    r2p.user = User.by_username(member)

                    r2p.permission = self.sa.query(Permission).filter(Permission.permission_name == perm).scalar()
                    self.sa.add(r2p)
                else:
                    g2p = UsersGroupRepoToPerm()
                    g2p.repository = cur_repo
                    g2p.users_group = UsersGroup.get_by_group_name(member)
                    g2p.permission = self.sa.query(Permission).filter(Permission.permission_name == perm).scalar()
                    self.sa.add(g2p)

            # update current repo
            for k, v in form_data.items():
                if k == "user":
                    cur_repo.user = User.by_username(v)
                elif k == "repo_name":
                    cur_repo.repo_name = form_data["repo_name_full"]
                elif k == "repo_group":
                    cur_repo.group_id = v

                else:
                    setattr(cur_repo, k, v)

            self.sa.add(cur_repo)

            if repo_name != form_data["repo_name_full"]:
                # rename repository
                self.__rename_repo(old=repo_name, new=form_data["repo_name_full"])

            self.sa.commit()
        except:
            log.error(traceback.format_exc())
            self.sa.rollback()
            raise
コード例 #5
0
ファイル: repos.py プロジェクト: pombredanne/rhodecode
    def __load_data(self, repo_name=None):
        """
        Load defaults settings for edit, and update

        :param repo_name:
        """
        self.__load_defaults()

        c.repo_info = db_repo = Repository.by_repo_name(repo_name)
        repo = scm_repo = db_repo.scm_instance

        if c.repo_info is None:
            h.flash(_('%s repository is not mapped to db perhaps'
                      ' it was created or renamed from the filesystem'
                      ' please run the application again'
                      ' in order to rescan repositories') % repo_name,
                      category='error')

            return redirect(url('repos'))

        c.default_user_id = User.by_username('default').user_id
        c.in_public_journal = self.sa.query(UserFollowing)\
            .filter(UserFollowing.user_id == c.default_user_id)\
            .filter(UserFollowing.follows_repository == c.repo_info).scalar()

        if c.repo_info.stats:
            last_rev = c.repo_info.stats.stat_on_revision
        else:
            last_rev = 0
        c.stats_revision = last_rev

        c.repo_last_rev = repo.count() - 1 if repo.revisions else 0

        if last_rev == 0 or c.repo_last_rev == 0:
            c.stats_percentage = 0
        else:
            c.stats_percentage = '%.2f' % ((float((last_rev)) /
                                            c.repo_last_rev) * 100)

        defaults = c.repo_info.get_dict()
        group, repo_name = c.repo_info.groups_and_repo
        defaults['repo_name'] = repo_name
        defaults['repo_group'] = getattr(group[-1] if group else None,
                                         'group_id', None)

        #fill owner
        if c.repo_info.user:
            defaults.update({'user': c.repo_info.user.username})
        else:
            replacement_user = self.sa.query(User)\
            .filter(User.admin == True).first().username
            defaults.update({'user': replacement_user})

        #fill repository users
        for p in c.repo_info.repo_to_perm:
            defaults.update({'u_perm_%s' % p.user.username:
                             p.permission.permission_name})

        #fill repository groups
        for p in c.repo_info.users_group_to_perm:
            defaults.update({'g_perm_%s' % p.users_group.users_group_name:
                             p.permission.permission_name})

        return defaults