##// END OF EJS Templates
Use repo-scann at latest possible state....
Use repo-scann at latest possible state. - we can ensure every config/checks were made before that step - it should fix issues with custom GIT paths

File last commit:

r3749:b950b884 beta
r3832:07f8039e beta
Show More
forks.py
193 lines | 7.2 KiB | text/x-python | PythonLexer
Added simple forks page, resolves issue #179
r1301 # -*- coding: utf-8 -*-
"""
rhodecode.controllers.forks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
forks controller for rhodecode
:created_on: Apr 23, 2011
:author: marcink
2012 copyrights
r1824 :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com>
Added simple forks page, resolves issue #179
r1301 :license: GPLv3, see COPYING for more details.
"""
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
#235 forking page repo group selection...
r1722 import formencode
import traceback
from formencode import htmlfill
Added simple forks page, resolves issue #179
r1301
#235 forking page repo group selection...
r1722 from pylons import tmpl_context as c, request, url
from pylons.controllers.util import redirect
from pylons.i18n.translation import _
import rhodecode.lib.helpers as h
Added simple forks page, resolves issue #179
r1301
from rhodecode.lib.helpers import Page
#235 forking page repo group selection...
r1722 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator, \
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 NotAnonymous, HasRepoPermissionAny, HasPermissionAllDecorator,\
HasPermissionAnyDecorator
Added simple forks page, resolves issue #179
r1301 from rhodecode.lib.base import BaseRepoController, render
Mads Kiilerich
fork: 'Update after clone' only makes sense if the update hook will maintain it
r3571 from rhodecode.model.db import Repository, RepoGroup, UserFollowing, User,\
RhodeCodeUi
#235 forking page repo group selection...
r1722 from rhodecode.model.repo import RepoModel
from rhodecode.model.forms import RepoForkForm
- Manage User’s Groups: create, delete, rename, add/remove users inside....
r3714 from rhodecode.model.scm import ScmModel, RepoGroupList
failsafe the GET `page` argument
r2845 from rhodecode.lib.utils2 import safe_int
Added simple forks page, resolves issue #179
r1301
log = logging.getLogger(__name__)
class ForksController(BaseRepoController):
def __before__(self):
super(ForksController, self).__before__()
#235 forking page repo group selection...
r1722 def __load_defaults(self):
- Manage User’s Groups: create, delete, rename, add/remove users inside....
r3714 acl_groups = RepoGroupList(RepoGroup.query().all(),
filter out repo groups choices to only ones that you have write+ access to. Before it was read+ access and you got proper...
r3239 perm_set=['group.write', 'group.admin'])
c.repo_groups = RepoGroup.groups_choices(groups=acl_groups)
#235 forking page repo group selection...
r1722 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
added landing revision into fork create form
r2485 choices, c.landing_revs = ScmModel().get_repo_landing_revs()
c.landing_revs_choices = choices
can update context var needs to be defined in __load_defaults
r3743 c.can_update = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_UPDATE).ui_active
#235 forking page repo group selection...
r1722
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.get_by_repo_name(repo_name)
repo = db_repo.scm_instance
if c.repo_info is None:
- #683 fixed difference between messages about not mapped repositories
r3110 h.not_mapped_error(repo_name)
#235 forking page repo group selection...
r1722 return redirect(url('repos'))
New default permissions definition for user group create
r3734 c.default_user_id = User.get_default_user().user_id
#235 forking page repo group selection...
r1722 c.in_public_journal = UserFollowing.query()\
.filter(UserFollowing.user_id == c.default_user_id)\
.filter(UserFollowing.follows_repository == c.repo_info).scalar()
if c.repo_info.stats:
- fixed issue with missing commits on some repos commands...
r1807 last_rev = c.repo_info.stats.stat_on_revision+1
#235 forking page repo group selection...
r1722 else:
last_rev = 0
c.stats_revision = last_rev
- fixed issue with missing commits on some repos commands...
r1807 c.repo_last_rev = repo.count() if repo.revisions else 0
#235 forking page repo group selection...
r1722
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 = RepoModel()._get_defaults(repo_name)
fixes #732
r3236 # alter the description to indicate a fork
defaults['description'] = ('fork of repository: %s \n%s'
% (defaults['repo_name'],
defaults['description']))
Enabled compare engine for tags...
r3010 # add suffix to fork
defaults['repo_name'] = '%s-fork' % defaults['repo_name']
fixes #732
r3236
#235 forking page repo group selection...
r1722 return defaults
auth decorators are not used anymore on __before__...
r3749 @LoginRequired()
#235 forking page repo group selection...
r1722 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
'repository.admin')
Added simple forks page, resolves issue #179
r1301 def forks(self, repo_name):
usage of request.GET is now more consistent
r3748 p = safe_int(request.GET.get('page', 1), 1)
added tests for forks and followers pages
r1375 repo_id = c.rhodecode_db_repo.repo_id
fixed missing permissions check on forks page
r2176 d = []
for r in Repository.get_repo_forks(repo_id):
if not HasRepoPermissionAny(
'repository.read', 'repository.write', 'repository.admin'
)(r.repo_name, 'get forks check'):
continue
d.append(r)
Added simple forks page, resolves issue #179
r1301 c.forks_pager = Page(d, page=p, items_per_page=20)
c.forks_data = render('/forks/forks_data.html')
Javascripts rewrite: updated yui to latest 2.9, simplified ajax loading for multiple pages. Removed YUI dev package
r1421 if request.environ.get('HTTP_X_PARTIAL_XHR'):
Added simple forks page, resolves issue #179
r1301 return c.forks_data
return render('/forks/forks.html')
#235 forking page repo group selection...
r1722
auth decorators are not used anymore on __before__...
r3749 @LoginRequired()
#235 forking page repo group selection...
r1722 @NotAnonymous()
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository')
#235 forking page repo group selection...
r1722 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
'repository.admin')
def fork(self, repo_name):
c.repo_info = Repository.get_by_repo_name(repo_name)
if not c.repo_info:
- #683 fixed difference between messages about not mapped repositories
r3110 h.not_mapped_error(repo_name)
#235 forking page repo group selection...
r1722 return redirect(url('home'))
defaults = self.__load_data(repo_name)
return htmlfill.render(
render('forks/fork.html'),
defaults=defaults,
encoding="UTF-8",
force_defaults=False
)
auth decorators are not used anymore on __before__...
r3749 @LoginRequired()
#235 forking page repo group selection...
r1722 @NotAnonymous()
RhodeCode now has a option to explicitly set forking permissions. ref #508...
r2709 @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository')
#235 forking page repo group selection...
r1722 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
'repository.admin')
def fork_create(self, repo_name):
self.__load_defaults()
c.repo_info = Repository.get_by_repo_name(repo_name)
_form = RepoForkForm(old_data={'repo_type': c.repo_info.repo_type},
added landing revision into fork create form
r2485 repo_groups=c.repo_groups_choices,
landing_revs=c.landing_revs_choices)()
#235 forking page repo group selection...
r1722 form_result = {}
try:
form_result = _form.to_python(dict(request.POST))
Mads Kiilerich
fork: 'Update after clone' only makes sense if the update hook will maintain it
r3571 # an approximation that is better than nothing
if not RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_UPDATE).ui_active:
form_result['update_after_clone'] = False
#235 forking page repo group selection...
r1722 # create fork is done sometimes async on celery, db transaction
# management is handled there.
Refactored create fork function to use new RepoModel functions instead of old...
r2652 RepoModel().create_fork(form_result, self.rhodecode_user.user_id)
Mads Kiilerich
stay on repo after forking and show full path to new fork...
r3566 fork_url = h.link_to(form_result['repo_name_full'],
linkify names on fork/create repos in tooltip messages
r3547 h.url('summary_home', repo_name=form_result['repo_name_full']))
Mads Kiilerich
consistently capitalize initial letter in flash messages
r3565 h.flash(h.literal(_('Forked repository %s as %s') \
linkify names on fork/create repos in tooltip messages
r3547 % (repo_name, fork_url)),
#235 forking page repo group selection...
r1722 category='success')
except formencode.Invalid, errors:
c.new_repo = errors.value['repo_name']
return htmlfill.render(
render('forks/fork.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
encoding="UTF-8")
except Exception:
log.error(traceback.format_exc())
h.flash(_('An error occurred during repository forking %s') %
repo_name, category='error')
Mads Kiilerich
stay on repo after forking and show full path to new fork...
r3566 return redirect(h.url('summary_home', repo_name=repo_name))