##// END OF EJS Templates
Update LICENSE.md to include license information about Flot
Update LICENSE.md to include license information about Flot

File last commit:

r4116:ffd45b18 rhodecode-2.2.5-gpl
r4133:a1738072 rhodecode-2.2.5-gpl
Show More
repo.py
793 lines | 29.6 KiB | text/x-python | PythonLexer
when new repo is created make user follow it automatically,...
r786 # -*- coding: utf-8 -*-
fixed license issue #149
r1206 # 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.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
Code refactoring,models renames...
r629 # 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.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
Code refactoring,models renames...
r629 # You should have received a copy of the GNU General Public License
fixed license issue #149
r1206 # along with this program. If not, see <http://www.gnu.org/licenses/>.
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 """
rhodecode.model.repo
~~~~~~~~~~~~~~~~~~~~
Repository model for rhodecode
:created_on: Jun 5, 2010
:author: marcink
:copyright: (c) 2013 RhodeCode GmbH.
:license: GPLv3, see LICENSE for more details.
"""
Git Hooks are automatically installed in new repos...
r2404 from __future__ import with_statement
when new repo is created make user follow it automatically,...
r786 import os
import shutil
import logging
import traceback
Code refactoring,models renames...
r629 from datetime import datetime
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 from rhodecode.lib.utils import make_ui
when new repo is created make user follow it automatically,...
r786
Added VCS into rhodecode core for faster and easier deployments of new versions
r2007 from rhodecode.lib.vcs.backends import get_backend
Added gravatars into permissions view and permissions autocomplete
r2142 from rhodecode.lib.compat import json
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 from rhodecode.lib.utils2 import LazyProperty, safe_str, safe_unicode, \
Fixed bug with log_delete hook didn't properly store...
r4012 remove_prefix, obfuscate_url_pw, get_current_rhodecode_user
moved caching query to libs
r1669 from rhodecode.lib.caching_query import FromCache
#595 add rcextension hook for repository delete
r2904 from rhodecode.lib.hooks import log_create_repository, log_delete_repository
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
r1401
when new repo is created make user follow it automatically,...
r786 from rhodecode.model import BaseModel
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 from rhodecode.model.db import Repository, UserRepoToPerm, UserGroupRepoToPerm, \
UserRepoGroupToPerm, UserGroupRepoGroupToPerm, User, Permission, \
Statistics, UserGroup, RhodeCodeUi, RepoGroup, \
repository extra fields implementation...
r3308 RhodeCodeSetting, RepositoryField
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116
Added gravatars into permissions view and permissions autocomplete
r2142 from rhodecode.lib import helpers as h
managing users groups enforce permissions checks....
r3789 from rhodecode.lib.auth import HasRepoPermissionAny, HasUserGroupPermissionAny
recursive forks detach...
r3641 from rhodecode.lib.exceptions import AttachedForksError
managing users groups enforce permissions checks....
r3789 from rhodecode.model.scm import UserGroupList
#227 Initial version of repository groups permissions system...
r1982
Code refactoring,models renames...
r629 log = logging.getLogger(__name__)
Fixed permissions for users groups, group can have create repo permission now....
r1271
fixed Example celery config to ampq,...
r752 class RepoModel(BaseModel):
Code refactoring,models renames...
r629
Added associated classes into child models
r2522 cls = Repository
New repo model create function...
r2524 URL_SEPARATOR = Repository.url_sep()
Added associated classes into child models
r2522
- Manage User’s Groups: create, delete, rename, add/remove users inside....
r3714 def _get_user_group(self, users_group):
Mads Kiilerich
further cleanup of UsersGroup...
r3417 return self._get_instance(UserGroup, users_group,
callback=UserGroup.get_by_group_name)
#227 Initial version of repository groups permissions system...
r1982
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def _get_repo_group(self, repo_group):
return self._get_instance(RepoGroup, repo_group,
#227 Initial version of repository groups permissions system...
r1982 callback=RepoGroup.get_by_group_name)
- Manage User’s Groups: create, delete, rename, add/remove users inside....
r3714 def _create_default_perms(self, repository, private):
# create default permission
default = 'repository.read'
New default permissions definition for user group create
r3734 def_user = User.get_default_user()
- Manage User’s Groups: create, delete, rename, add/remove users inside....
r3714 for p in def_user.user_perms:
if p.permission.permission_name.startswith('repository.'):
default = p.permission.permission_name
break
default_perm = 'repository.none' if private else default
repo_to_perm = UserRepoToPerm()
repo_to_perm.permission = Permission.get_by_key(default_perm)
repo_to_perm.repository = repository
repo_to_perm.user_id = def_user.user_id
return repo_to_perm
Major refactoring, removed when possible calls to app globals....
r1036 @LazyProperty
def repos_path(self):
notification to commit author + gardening
r1716 """
Fixed spelling of get's to gets
r4089 Gets the repositories root path from database
Major refactoring, removed when possible calls to app globals....
r1036 """
Fixed problems with repository creation
r1017
Major refactoring, removed when possible calls to app globals....
r1036 q = self.sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one()
return q.ui_value
#56 hacking on forms, and model for users groups
r1013
Code refactoring,models renames...
r629 def get(self, repo_id, cache=False):
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 repo = self.sa.query(Repository) \
added action loggers to following repositories,...
r735 .filter(Repository.repo_id == repo_id)
Code refactoring,models renames...
r629
if cache:
repo = repo.options(FromCache("sql_cache_short",
added action loggers to following repositories,...
r735 "get_repo_%s" % repo_id))
Code refactoring,models renames...
r629 return repo.scalar()
API get_user and get_repo methods can fetch by id or names
r2010 def get_repo(self, repository):
Share common getter functions in base model, and remove duplicated functions from other models
r2432 return self._get_repo(repository)
API get_user and get_repo methods can fetch by id or names
r2010
added action loggers to following repositories,...
r735 def get_by_repo_name(self, repo_name, cache=False):
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 repo = self.sa.query(Repository) \
added action loggers to following repositories,...
r735 .filter(Repository.repo_name == repo_name)
if cache:
repo = repo.options(FromCache("sql_cache_short",
"get_repo_%s" % repo_name))
fixed Example celery config to ampq,...
r752 return repo.scalar()
added action loggers to following repositories,...
r735
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos...
r3163 def get_all_user_repos(self, user):
"""
Fixed spelling of get's to gets
r4089 Gets all repositories that user have at least read access
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos...
r3163
:param user:
"""
from rhodecode.lib.auth import AuthUser
user = self._get_user(user)
repos = AuthUser(user_id=user.user_id).permissions['repositories']
access_check = lambda r: r[1] in ['repository.read',
'repository.write',
'repository.admin']
repos = [x[0] for x in filter(access_check, repos.items())]
return Repository.query().filter(Repository.repo_name.in_(repos))
Code refactoring,models renames...
r629 def get_users_js(self):
users = self.sa.query(User).filter(User.active == True).all()
Added gravatars into permissions view and permissions autocomplete
r2142 return json.dumps([
{
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 'id': u.user_id,
'fname': u.name,
'lname': u.lastname,
'nname': u.username,
'gravatar_lnk': h.gravatar_url(u.email, 14)
Added gravatars into permissions view and permissions autocomplete
r2142 } for u in users]
)
Code refactoring,models renames...
r629
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def get_user_groups_js(self):
user_groups = self.sa.query(UserGroup) \
Mads Kiilerich
further cleanup of UsersGroup...
r3417 .filter(UserGroup.users_group_active == True).all()
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 user_groups = UserGroupList(user_groups, perm_set=['usergroup.read',
'usergroup.write',
'usergroup.admin'])
Added gravatars into permissions view and permissions autocomplete
r2142 return json.dumps([
{
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 'id': gr.users_group_id,
'grname': gr.users_group_name,
'grmembers': len(gr.members),
} for gr in user_groups]
Added gravatars into permissions view and permissions autocomplete
r2142 )
#56 hacking on forms, and model for users groups
r1013
Use common function for generation of grid data...
r3154 @classmethod
def _render_datatable(cls, tmpl, *args, **kwargs):
import rhodecode
from pylons import tmpl_context as c
from pylons.i18n.translation import _
_tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup
template = _tmpl_lookup.get_template('data_table/_dt_elements.html')
tmpl = template.get_def(tmpl)
kwargs.update(dict(_=_, h=h, c=c))
return tmpl.render(*args, **kwargs)
Added missing migrations, and move update_repoinfo to RepoModel...
r3309 @classmethod
def update_repoinfo(cls, repositories=None):
if not repositories:
repositories = Repository.getAll()
for repo in repositories:
Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated...
r3420 repo.update_changeset_cache()
Added missing migrations, and move update_repoinfo to RepoModel...
r3309
fixes issue #739 Delete/Edit repositories should only point to admin links if the user is an super admin.
r3245 def get_repos_as_dict(self, repos_list=None, admin=False, perm_check=True,
super_user_actions=False):
Use common function for generation of grid data...
r3154 _render = self._render_datatable
Add flag for permission check in _update_permissions function
r3827 from pylons import tmpl_context as c
Use common function for generation of grid data...
r3154
def quick_menu(repo_name):
return _render('quick_menu', repo_name)
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def repo_lnk(name, rtype, rstate, private, fork_of):
return _render('repo_name', name, rtype, rstate, private, fork_of,
Use common function for generation of grid data...
r3154 short_name=not admin, admin=False)
def last_change(last_change):
return _render("last_change", last_change)
def rss_lnk(repo_name):
return _render("rss", repo_name)
def atom_lnk(repo_name):
return _render("atom", repo_name)
def last_rev(repo_name, cs_cache):
return _render('revision', repo_name, cs_cache.get('revision'),
cs_cache.get('raw_id'), cs_cache.get('author'),
cs_cache.get('message'))
def desc(desc):
if c.visual.stylify_metatags:
return h.urlify_text(h.desc_stylize(h.truncate(desc, 60)))
else:
return h.urlify_text(h.truncate(desc, 60))
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def state(repo_state):
return _render("repo_state", repo_state)
Use common function for generation of grid data...
r3154 def repo_actions(repo_name):
fixes issue #739 Delete/Edit repositories should only point to admin links if the user is an super admin.
r3245 return _render('repo_actions', repo_name, super_user_actions)
Use common function for generation of grid data...
r3154
def owner_actions(user_id, username):
return _render('user_name', user_id, username)
repos_data = []
for repo in repos_list:
if perm_check:
# check permission at this level
if not HasRepoPermissionAny(
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 'repository.read', 'repository.write',
'repository.admin'
Use common function for generation of grid data...
r3154 )(repo.repo_name, 'get_repos_as_dict check'):
continue
cs_cache = repo.changeset_cache
row = {
"menu": quick_menu(repo.repo_name),
"raw_name": repo.repo_name.lower(),
"name": repo_lnk(repo.repo_name, repo.repo_type,
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 repo.repo_state, repo.private, repo.fork),
Use common function for generation of grid data...
r3154 "last_change": last_change(repo.last_db_change),
"last_changeset": last_rev(repo.repo_name, cs_cache),
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 "last_rev_raw": cs_cache.get('revision'),
Use common function for generation of grid data...
r3154 "desc": desc(repo.description),
"owner": h.person(repo.user.username),
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 "state": state(repo.repo_state),
Use common function for generation of grid data...
r3154 "rss": rss_lnk(repo.repo_name),
"atom": atom_lnk(repo.repo_name),
}
if admin:
row.update({
"action": repo_actions(repo.repo_name),
"owner": owner_actions(repo.user.user_id,
h.person(repo.user.username))
})
repos_data.append(row)
return {
"totalRecords": len(repos_list),
"startIndex": 0,
"sort": "name",
"dir": "asc",
"records": repos_data
}
fixes #288...
r1594 def _get_defaults(self, repo_name):
"""
Fixed spelling of get's to gets
r4089 Gets information about repository, and returns a dict for
fixes #288...
r1594 usage in forms
auto white-space removal
r1818
fixes #288...
r1594 :param repo_name:
"""
repo_info = Repository.get_by_repo_name(repo_name)
if repo_info is None:
return None
defaults = repo_info.get_dict()
Mads Kiilerich
breadcrumbs: make repo names link to summary pages
r3599 group, repo_name, repo_name_full = repo_info.groups_and_repo
fixes #288...
r1594 defaults['repo_name'] = repo_name
defaults['repo_group'] = getattr(group[-1] if group else None,
'group_id', None)
Fixed some issues with edit form...
r3089 for strip, k in [(0, 'repo_type'), (1, 'repo_enable_downloads'),
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 (1, 'repo_description'), (1, 'repo_enable_locking'),
(1, 'repo_landing_rev'), (0, 'clone_uri'),
(1, 'repo_private'), (1, 'repo_enable_statistics')]:
Fixed some issues with edit form...
r3089 attr = k
if strip:
attr = remove_prefix(k, 'repo_')
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 val = defaults[attr]
if k == 'repo_landing_rev':
val = ':'.join(defaults[attr])
defaults[k] = val
if k == 'clone_uri':
defaults['clone_uri_hidden'] = repo_info.clone_uri_hidden
Fixed some issues with edit form...
r3089
fixes #288...
r1594 # fill owner
if repo_info.user:
defaults.update({'user': repo_info.user.username})
else:
replacement_user = User.query().filter(User.admin ==
True).first().username
defaults.update({'user': replacement_user})
# fill repository users
for p in repo_info.repo_to_perm:
defaults.update({'u_perm_%s' % p.user.username:
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 p.permission.permission_name})
fixes #288...
r1594
# fill repository groups
for p in repo_info.users_group_to_perm:
defaults.update({'g_perm_%s' % p.users_group.users_group_name:
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 p.permission.permission_name})
fixes #288...
r1594
return defaults
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def update(self, repo, **kwargs):
Code refactoring,models renames...
r629 try:
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 cur_repo = self._get_repo(repo)
org_repo_name = cur_repo.repo_name
Fixed some issues with edit form...
r3089 if 'user' in kwargs:
cur_repo.user = User.get_by_username(kwargs['user'])
if 'repo_group' in kwargs:
cur_repo.group = RepoGroup.get(kwargs['repo_group'])
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 log.debug('Updating repo %s with params:%s' % (cur_repo, kwargs))
Simon Lopez
Repo type can't be changed. Fixes issue 836
r3859 for strip, k in [(1, 'repo_enable_downloads'),
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 (1, 'repo_description'),
(1, 'repo_enable_locking'),
(1, 'repo_landing_rev'),
(1, 'repo_private'),
(1, 'repo_enable_statistics'),
(0, 'clone_uri'),]:
Fixed some issues with edit form...
r3089 if k in kwargs:
val = kwargs[k]
if strip:
k = remove_prefix(k, 'repo_')
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 if k == 'clone_uri':
from rhodecode.model.validators import Missing
_change = kwargs.get('clone_uri_change')
if _change == Missing:
# we don't change the value, so use original one
val = cur_repo.clone_uri
Fixed some issues with edit form...
r3089 setattr(cur_repo, k, val)
Code refactoring,models renames...
r629
Fixed some issues with edit form...
r3089 new_name = cur_repo.get_new_name(kwargs['repo_name'])
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
r1539 cur_repo.repo_name = new_name
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins...
r3629 #if private flag is set, reset default permission to NONE
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
r1539
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins...
r3629 if kwargs.get('repo_private'):
EMPTY_PERM = 'repository.none'
RepoModel().grant_user_permission(
repo=cur_repo, user='default', perm=EMPTY_PERM
)
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 #handle extra fields
for field in filter(lambda k: k.startswith(RepositoryField.PREFIX),
kwargs):
repository extra fields implementation...
r3308 k = RepositoryField.un_prefix_key(field)
ex_field = RepositoryField.get_by_key_name(key=k, repo=cur_repo)
if ex_field:
ex_field.field_value = kwargs[field]
self.sa.add(ex_field)
Code refactoring,models renames...
r629 self.sa.add(cur_repo)
Fixed some issues with edit form...
r3089 if org_repo_name != new_name:
fixed saving settings on repositories inside groups, also fixes #187...
r1323 # rename repository
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 self._rename_filesystem_repo(old=org_repo_name, new=new_name)
Code refactoring,models renames...
r629
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
r1539 return cur_repo
Don't catch all exceptions
r3631 except Exception:
Code refactoring,models renames...
r629 log.error(traceback.format_exc())
raise
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def _create_repo(self, repo_name, repo_type, description, owner,
private=False, clone_uri=None, repo_group=None,
landing_rev='rev:tip', fork_of=None,
copy_fork_permissions=False, enable_statistics=False,
enable_locking=False, enable_downloads=False,
copy_group_permissions=False, state=Repository.STATE_PENDING):
Refactored create fork function to use new RepoModel functions instead of old...
r2652 """
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 Create repository inside database with PENDING state, this should be
only executed by create() repo. With exception of importing existing repos
Refactored create fork function to use new RepoModel functions instead of old...
r2652
"""
#235 forking page repo group selection...
r1722 from rhodecode.model.scm import ScmModel
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366
New repo model create function...
r2524 owner = self._get_user(owner)
fork_of = self._get_repo(fork_of)
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 repo_group = self._get_repo_group(repo_group)
Code refactoring,models renames...
r629 try:
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 repo_name = safe_unicode(repo_name)
description = safe_unicode(description)
#235 forking page repo group selection...
r1722 # repo name is just a name of repository
# while repo_name_full is a full qualified name that is combined
# with name and path of group
Added functional test create repo with a group...
r2529 repo_name_full = repo_name
New repo model create function...
r2524 repo_name = repo_name.split(self.URL_SEPARATOR)[-1]
fixed #47 adding a new repo that have a group chosen had wrong paths.
r1361
Code refactoring,models renames...
r629 new_repo = Repository()
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 new_repo.repo_state = state
Enable statistics are disabled by default now
r1075 new_repo.enable_statistics = False
New repo model create function...
r2524 new_repo.repo_name = repo_name_full
new_repo.repo_type = repo_type
new_repo.user = owner
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 new_repo.group = repo_group
New repo model create function...
r2524 new_repo.description = description or repo_name
new_repo.private = private
new_repo.clone_uri = clone_uri
new_repo.landing_rev = landing_rev
#235 forking page repo group selection...
r1722
Implemented #379 defaults settings page for creation of repositories...
r3056 new_repo.enable_statistics = enable_statistics
new_repo.enable_locking = enable_locking
new_repo.enable_downloads = enable_downloads
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 if repo_group:
new_repo.enable_locking = repo_group.enable_locking
inherit locking from parent
r2755
New repo model create function...
r2524 if fork_of:
parent_repo = fork_of
Code refactoring,models renames...
r629 new_repo.fork = parent_repo
self.sa.add(new_repo)
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 if fork_of and copy_fork_permissions:
repo = fork_of
user_perms = UserRepoToPerm.query() \
.filter(UserRepoToPerm.repository == repo).all()
group_perms = UserGroupRepoToPerm.query() \
.filter(UserGroupRepoToPerm.repository == repo).all()
for perm in user_perms:
UserRepoToPerm.create(perm.user, new_repo, perm.permission)
for perm in group_perms:
UserGroupRepoToPerm.create(perm.users_group, new_repo,
perm.permission)
elif repo_group and copy_group_permissions:
Code refactoring,models renames...
r629
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 user_perms = UserRepoGroupToPerm.query() \
.filter(UserRepoGroupToPerm.group == repo_group).all()
group_perms = UserGroupRepoGroupToPerm.query() \
.filter(UserGroupRepoGroupToPerm.group == repo_group).all()
Code refactoring,models renames...
r629
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 for perm in user_perms:
perm_name = perm.permission.permission_name.replace('group.', 'repository.')
perm_obj = Permission.get_by_key(perm_name)
UserRepoToPerm.create(perm.user, new_repo, perm_obj)
for perm in group_perms:
perm_name = perm.permission.permission_name.replace('group.', 'repository.')
perm_obj = Permission.get_by_key(perm_name)
UserGroupRepoToPerm.create(perm.users_group, new_repo, perm_obj)
implements #236 forking copy permission option
r1729 else:
- Manage User’s Groups: create, delete, rename, add/remove users inside....
r3714 perm_obj = self._create_default_perms(new_repo, private)
self.sa.add(perm_obj)
fixed issue with db transaction when filesystem creation of repository failed...
r1028
#235 forking page repo group selection...
r1722 # now automatically start following this repository as owner
when new repo is created make user follow it automatically,...
r786 ScmModel(self.sa).toggle_following_repo(new_repo.repo_id,
New repo model create function...
r2524 owner.user_id)
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 # we need to flush here, in order to check if database won't
# throw any exceptions, create filesystem dirs at the very end
self.sa.flush()
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
r1539 return new_repo
Don't catch all exceptions
r3631 except Exception:
Code refactoring,models renames...
r629 log.error(traceback.format_exc())
raise
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def create(self, form_data, cur_user):
Refactored create fork function to use new RepoModel functions instead of old...
r2652 """
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 Create repository using celery tasks
Refactored create fork function to use new RepoModel functions instead of old...
r2652
:param form_data:
:param cur_user:
"""
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 from rhodecode.lib.celerylib import tasks, run_task
return run_task(tasks.create_repo, form_data, cur_user)
New repo model create function...
r2524
Add flag for permission check in _update_permissions function
r3827 def _update_permissions(self, repo, perms_new=None, perms_updates=None,
check_perms=True):
- Manage User’s Groups: create, delete, rename, add/remove users inside....
r3714 if not perms_new:
perms_new = []
if not perms_updates:
perms_updates = []
# update permissions
for member, perm, member_type in perms_updates:
if member_type == 'user':
# this updates existing one
self.grant_user_permission(
repo=repo, user=member, perm=perm
)
else:
managing users groups enforce permissions checks....
r3789 #check if we have permissions to alter this usergroup
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 req_perms = (
'usergroup.read', 'usergroup.write', 'usergroup.admin')
if not check_perms or HasUserGroupPermissionAny(*req_perms)(
member):
self.grant_user_group_permission(
managing users groups enforce permissions checks....
r3789 repo=repo, group_name=member, perm=perm
)
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 # set new permissions
- Manage User’s Groups: create, delete, rename, add/remove users inside....
r3714 for member, perm, member_type in perms_new:
if member_type == 'user':
self.grant_user_permission(
repo=repo, user=member, perm=perm
)
else:
managing users groups enforce permissions checks....
r3789 #check if we have permissions to alter this usergroup
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 req_perms = (
'usergroup.read', 'usergroup.write', 'usergroup.admin')
if not check_perms or HasUserGroupPermissionAny(*req_perms)(
member):
self.grant_user_group_permission(
managing users groups enforce permissions checks....
r3789 repo=repo, group_name=member, perm=perm
)
- Manage User’s Groups: create, delete, rename, add/remove users inside....
r3714
Code refactoring,models renames...
r629 def create_fork(self, form_data, cur_user):
#235 forking page repo group selection...
r1722 """
Simple wrapper into executing celery task for fork creation
auto white-space removal
r1818
#235 forking page repo group selection...
r1722 :param form_data:
:param cur_user:
"""
Code refactoring,models renames...
r629 from rhodecode.lib.celerylib import tasks, run_task
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 return run_task(tasks.create_repo_fork, form_data, cur_user)
Code refactoring,models renames...
r629
Fixed bug with log_delete hook didn't properly store...
r4012 def delete(self, repo, forks=None, fs_remove=True, cur_user=None):
recursive forks detach...
r3641 """
Delete given repository, forks parameter defines what do do with
attached forks. Throws AttachedForksError if deleted repo has attached
forks
:param repo:
:param forks: str 'delete' or 'detach'
repo rescann should detach forks of zombie repos,...
r3694 :param fs_remove: remove(archive) repo from filesystem
recursive forks detach...
r3641 """
Fixed bug with log_delete hook didn't properly store...
r4012 if not cur_user:
Replaced fallback username from ? to None in hook loggers
r4018 cur_user = getattr(get_current_rhodecode_user(), 'username', None)
Share common getter functions in base model, and remove duplicated functions from other models
r2432 repo = self._get_repo(repo)
New repo model create function...
r2524 if repo:
recursive forks detach...
r3641 if forks == 'detach':
for r in repo.forks:
r.fork = None
self.sa.add(r)
elif forks == 'delete':
for r in repo.forks:
self.delete(r, forks='delete')
elif [f for f in repo.forks]:
raise AttachedForksError()
#595 add rcextension hook for repository delete
r2904 old_repo_dict = repo.get_dict()
owner = repo.user
New repo model create function...
r2524 try:
self.sa.delete(repo)
repo rescann should detach forks of zombie repos,...
r3694 if fs_remove:
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 self._delete_filesystem_repo(repo)
repo rescann should detach forks of zombie repos,...
r3694 else:
log.debug('skipping removal from filesystem')
#595 add rcextension hook for repository delete
r2904 log_delete_repository(old_repo_dict,
Fixed bug with log_delete hook didn't properly store...
r4012 deleted_by=cur_user)
Don't catch all exceptions
r3631 except Exception:
New repo model create function...
r2524 log.error(traceback.format_exc())
raise
Code refactoring,models renames...
r629
#227 Initial version of repository groups permissions system...
r1982 def grant_user_permission(self, repo, user, perm):
"""
Grant permission for user on given repository, or update existing one
if found
:param repo: Instance of Repository, repository_id, or repository name
:param user: Instance of User, user_id or username
:param perm: Instance of Permission, or permission_name
"""
Share common getter functions in base model, and remove duplicated functions from other models
r2432 user = self._get_user(user)
repo = self._get_repo(repo)
permission = self._get_perm(perm)
#227 Initial version of repository groups permissions system...
r1982
# check if we have that permission already
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 obj = self.sa.query(UserRepoToPerm) \
.filter(UserRepoToPerm.user == user) \
.filter(UserRepoToPerm.repository == repo) \
#227 Initial version of repository groups permissions system...
r1982 .scalar()
if obj is None:
# create new !
obj = UserRepoToPerm()
obj.repository = repo
obj.user = user
obj.permission = permission
self.sa.add(obj)
Permissions on group can be set in recursive mode setting defined permission to all children...
r2820 log.debug('Granted perm %s to %s on %s' % (perm, user, repo))
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 return obj
#227 Initial version of repository groups permissions system...
r1982
def revoke_user_permission(self, repo, user):
"""
Revoke permission for user on given repository
:param repo: Instance of Repository, repository_id, or repository name
:param user: Instance of User, user_id or username
"""
Added gravatars into permissions view and permissions autocomplete
r2142
Share common getter functions in base model, and remove duplicated functions from other models
r2432 user = self._get_user(user)
repo = self._get_repo(repo)
#227 Initial version of repository groups permissions system...
r1982
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 obj = self.sa.query(UserRepoToPerm) \
.filter(UserRepoToPerm.repository == repo) \
.filter(UserRepoToPerm.user == user) \
Permissions on group can be set in recursive mode setting defined permission to all children...
r2820 .scalar()
if obj:
self.sa.delete(obj)
log.debug('Revoked perm on %s on %s' % (repo, user))
Code refactoring,models renames...
r629
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def grant_user_group_permission(self, repo, group_name, perm):
#227 Initial version of repository groups permissions system...
r1982 """
fixed tests and missing replacements from 5f1850e4712a
r3415 Grant permission for user group on given repository, or update
#227 Initial version of repository groups permissions system...
r1982 existing one if found
:param repo: Instance of Repository, repository_id, or repository name
:param group_name: Instance of UserGroup, users_group_id,
fixed tests and missing replacements from 5f1850e4712a
r3415 or user group name
#227 Initial version of repository groups permissions system...
r1982 :param perm: Instance of Permission, or permission_name
"""
Share common getter functions in base model, and remove duplicated functions from other models
r2432 repo = self._get_repo(repo)
- Manage User’s Groups: create, delete, rename, add/remove users inside....
r3714 group_name = self._get_user_group(group_name)
Share common getter functions in base model, and remove duplicated functions from other models
r2432 permission = self._get_perm(perm)
#227 Initial version of repository groups permissions system...
r1982
# check if we have that permission already
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 obj = self.sa.query(UserGroupRepoToPerm) \
.filter(UserGroupRepoToPerm.users_group == group_name) \
.filter(UserGroupRepoToPerm.repository == repo) \
#227 Initial version of repository groups permissions system...
r1982 .scalar()
if obj is None:
# create new
Mads Kiilerich
further cleanup of UsersGroup...
r3417 obj = UserGroupRepoToPerm()
#227 Initial version of repository groups permissions system...
r1982
obj.repository = repo
obj.users_group = group_name
obj.permission = permission
self.sa.add(obj)
Permissions on group can be set in recursive mode setting defined permission to all children...
r2820 log.debug('Granted perm %s to %s on %s' % (perm, group_name, repo))
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 return obj
#227 Initial version of repository groups permissions system...
r1982
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def revoke_user_group_permission(self, repo, group_name):
#227 Initial version of repository groups permissions system...
r1982 """
fixed tests and missing replacements from 5f1850e4712a
r3415 Revoke permission for user group on given repository
#227 Initial version of repository groups permissions system...
r1982
:param repo: Instance of Repository, repository_id, or repository name
:param group_name: Instance of UserGroup, users_group_id,
fixed tests and missing replacements from 5f1850e4712a
r3415 or user group name
#227 Initial version of repository groups permissions system...
r1982 """
Share common getter functions in base model, and remove duplicated functions from other models
r2432 repo = self._get_repo(repo)
- Manage User’s Groups: create, delete, rename, add/remove users inside....
r3714 group_name = self._get_user_group(group_name)
#227 Initial version of repository groups permissions system...
r1982
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 obj = self.sa.query(UserGroupRepoToPerm) \
.filter(UserGroupRepoToPerm.repository == repo) \
.filter(UserGroupRepoToPerm.users_group == group_name) \
Permissions on group can be set in recursive mode setting defined permission to all children...
r2820 .scalar()
if obj:
self.sa.delete(obj)
log.debug('Revoked perm to %s on %s' % (repo, group_name))
#56 added ajax removal of users groups,...
r1015
added cache reset, stats reset, and delete into repository settings in admin....
r708 def delete_stats(self, repo_name):
#235 forking page repo group selection...
r1722 """
removes stats for given repo
auto white-space removal
r1818
#235 forking page repo group selection...
r1722 :param repo_name:
"""
fix reset statistics call if there are no statistics yet
r3314 repo = self._get_repo(repo_name)
added cache reset, stats reset, and delete into repository settings in admin....
r708 try:
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 obj = self.sa.query(Statistics) \
.filter(Statistics.repository == repo).scalar()
fix reset statistics call if there are no statistics yet
r3314 if obj:
self.sa.delete(obj)
Don't catch all exceptions
r3631 except Exception:
added cache reset, stats reset, and delete into repository settings in admin....
r708 log.error(traceback.format_exc())
raise
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def _create_filesystem_repo(self, repo_name, repo_type, repo_group,
clone_uri=None, repo_store_location=None):
docs update for repo model
r787 """
fixed #47 adding a new repo that have a group chosen had wrong paths.
r1361 makes repository on filesystem. It's group aware means it'll create
a repository within a group, and alter the paths accordingly of
group location
source code cleanup: remove trailing white space, normalize file endings
r1203
docs update for repo model
r787 :param repo_name:
:param alias:
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 :param parent:
#47 fixed group aware on adding new repo
r1350 :param clone_uri:
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 :param repo_store_location:
docs update for repo model
r787 """
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 from rhodecode.lib.utils import is_valid_repo, is_valid_repo_group
Created install_git_hook more verbose version of previos code....
r2618 from rhodecode.model.scm import ScmModel
assure that we don't have an empty description when creating a repo
r1517
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 if '/' in repo_name:
raise ValueError('repo_name must not contain groups got `%s`' % repo_name)
if isinstance(repo_group, RepoGroup):
new_parent_path = os.sep.join(repo_group.full_path_splitted)
#47 fixed group aware on adding new repo
r1350 else:
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 new_parent_path = repo_group or ''
Implemented simple gist functionality ref #530....
r3840 if repo_store_location:
_paths = [repo_store_location]
else:
_paths = [self.repos_path, new_parent_path, repo_name]
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 # we need to make it str for mercurial
Implemented simple gist functionality ref #530....
r3840 repo_path = os.path.join(*map(lambda x: safe_str(x), _paths))
#47 fixed group aware on adding new repo
r1350
fixes #266 Rhodecode allows to create repo with the same name and in the same parent as group
r1550 # check if this path is not a repository
if is_valid_repo(repo_path, self.repos_path):
raise Exception('This path %s is a valid repository' % repo_path)
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
r1401
fixes #266 Rhodecode allows to create repo with the same name and in the same parent as group
r1550 # check if this path is a group
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 if is_valid_repo_group(repo_path, self.repos_path):
fixes #266 Rhodecode allows to create repo with the same name and in the same parent as group
r1550 raise Exception('This path %s is a valid group' % repo_path)
fixes #288...
r1594
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 log.info('creating repo %s in %s from url: `%s`' % (
repo_name, safe_unicode(repo_path),
obfuscate_url_pw(clone_uri)))
backend = get_backend(repo_type)
if repo_type == 'hg':
baseui = make_ui('db', clear_session=False)
# patch and reset hooks section of UI config to not run any
# hooks on creating remote repo
for k, v in baseui.configitems('hooks'):
baseui.setconfig('hooks', k, None)
repo = backend(repo_path, create=True, src_url=clone_uri, baseui=baseui)
elif repo_type == 'git':
Implemented simple gist functionality ref #530....
r3840 repo = backend(repo_path, create=True, src_url=clone_uri, bare=True)
Git Hooks are automatically installed in new repos...
r2404 # add rhodecode hook into this repo
Implemented simple gist functionality ref #530....
r3840 ScmModel().install_git_hook(repo=repo)
init bare repos for git now by default. This is recommended setup for remotes repositories
r2321 else:
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 raise Exception('Not supported repo_type %s expected hg/git' % repo_type)
log.debug('Created repo %s with %s backend'
% (safe_unicode(repo_name), safe_unicode(repo_type)))
Implemented simple gist functionality ref #530....
r3840 return repo
Code refactoring,models renames...
r629
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def _rename_filesystem_repo(self, old, new):
docs update for repo model
r787 """
renames repository on filesystem
source code cleanup: remove trailing white space, normalize file endings
r1203
docs update for repo model
r787 :param old: old name
:param new: new name
"""
garden...
r1976 log.info('renaming repo from %s to %s' % (old, new))
Code refactoring,models renames...
r629
Major refactoring, removed when possible calls to app globals....
r1036 old_path = os.path.join(self.repos_path, old)
new_path = os.path.join(self.repos_path, new)
Code refactoring,models renames...
r629 if os.path.isdir(new_path):
#227 Initial version of repository groups permissions system...
r1982 raise Exception(
'Was trying to rename to already existing dir %s' % new_path
)
Code refactoring,models renames...
r629 shutil.move(old_path, new_path)
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 def _delete_filesystem_repo(self, repo):
docs update for repo model
r787 """
removes repo from filesystem, the removal is acctually made by
added rm__ prefix into dir, and rename internat .hg/.git dirs so this
repository is no longer valid for rhodecode, can be undeleted later on
by reverting the renames on this repository
source code cleanup: remove trailing white space, normalize file endings
r1203
docs update for repo model
r787 :param repo: repo object
"""
Major refactoring, removed when possible calls to app globals....
r1036 rm_path = os.path.join(self.repos_path, repo.repo_name)
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 log.info("Removing repository %s" % (rm_path,))
don't disable .git directory for bare repos on deleting, ref #413
r2327 # disable hg/git internal that it doesn't get detected as repo
fixed deletion of repository on filesystem, works based on scm type for git and hg....
r668 alias = repo.repo_type
don't disable .git directory for bare repos on deleting, ref #413
r2327
bare = getattr(repo.scm_instance, 'bare', False)
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 # skip this for bare git repos
don't disable .git directory for bare repos on deleting, ref #413
r2327 if not bare:
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 # disable VCS repo
vcs_path = os.path.join(rm_path, '.%s' % alias)
if os.path.exists(vcs_path):
shutil.move(vcs_path, os.path.join(rm_path, 'rm__.%s' % alias))
removed %f from datetime formatting doesn't work on py25 :/
r2553 _now = datetime.now()
fill miliseconds with 0 since it can return <6 digit number
r2592 _ms = str(_now.microsecond).rjust(6, '0')
removed %f from datetime formatting doesn't work on py25 :/
r2553 _d = 'rm__%s__%s' % (_now.strftime('%Y%m%d_%H%M%S_' + _ms),
Fixed issue with rm__ system that put removed repos in root location, it can lead to making a heavy copy, and remove operation.
r2949 repo.just_name)
if repo.group:
args = repo.group.full_path_splitted + [_d]
_d = os.path.join(*args)
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116
if os.path.isdir(rm_path):
shutil.move(rm_path, os.path.join(self.repos_path, _d))