annotate rhodecode/model/repo.py @ 1530:04027bdb876c beta

Refactoring of model get functions
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 08 Oct 2011 02:02:25 +0200
parents 142a05597cba
children bd604cf75c5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
1 # -*- coding: utf-8 -*-
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
2 """
811
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 787
diff changeset
3 rhodecode.model.repo
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 787
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
5
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
6 Repository model for rhodecode
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1119
diff changeset
7
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
8 :created_on: Jun 5, 2010
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
9 :author: marcink
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1119
diff changeset
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
11 :license: GPLv3, see COPYING for more details.
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
12 """
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
13 # This program is free software: you can redistribute it and/or modify
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
14 # it under the terms of the GNU General Public License as published by
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
16 # (at your option) any later version.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1119
diff changeset
17 #
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # This program is distributed in the hope that it will be useful,
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # GNU General Public License for more details.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1119
diff changeset
22 #
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # You should have received a copy of the GNU General Public License
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
25 import os
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
26 import shutil
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
27 import logging
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
28 import traceback
367
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
29 from datetime import datetime
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
30
1045
3fc9183e05dd another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
31 from sqlalchemy.orm import joinedload, make_transient
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
32
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
33 from vcs.utils.lazy import LazyProperty
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
34 from vcs.backends import get_backend
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
35
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
36 from rhodecode.lib import safe_str
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
37
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
38 from rhodecode.model import BaseModel
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
39 from rhodecode.model.caching_query import FromCache
708
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
40 from rhodecode.model.db import Repository, RepoToPerm, User, Permission, \
1323
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
41 Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, Group
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
42 from rhodecode.model.user import UserModel
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
43
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 log = logging.getLogger(__name__)
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
46
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
47 class RepoModel(BaseModel):
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
48
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
49 @LazyProperty
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
50 def repos_path(self):
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
51 """Get's the repositories root path from database
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
52 """
1017
ade3414a8b61 Fixed problems with repository creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1015
diff changeset
53
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
54 q = self.sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one()
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
55 return q.ui_value
1013
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
56
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
57 def get(self, repo_id, cache=False):
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
58 repo = self.sa.query(Repository)\
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
59 .filter(Repository.repo_id == repo_id)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
60
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
61 if cache:
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
62 repo = repo.options(FromCache("sql_cache_short",
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
63 "get_repo_%s" % repo_id))
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
64 return repo.scalar()
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
65
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
66 def get_by_repo_name(self, repo_name, cache=False):
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
67 repo = self.sa.query(Repository)\
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
68 .filter(Repository.repo_name == repo_name)
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
69
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
70 if cache:
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
71 repo = repo.options(FromCache("sql_cache_short",
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
72 "get_repo_%s" % repo_name))
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
73 return repo.scalar()
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
74
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
75
298
15e96b5a2685 autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents: 296
diff changeset
76 def get_users_js(self):
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
77
328
cec5cbc956c0 Repository managment permissions, fixed found bugs updated js, added extra checks for doubled users and non active ones
Marcin Kuzminski <marcin@python-works.com>
parents: 299
diff changeset
78 users = self.sa.query(User).filter(User.active == True).all()
298
15e96b5a2685 autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents: 296
diff changeset
79 u_tmpl = '''{id:%s, fname:"%s", lname:"%s", nname:"%s"},'''
1013
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
80 users_array = '[%s]' % '\n'.join([u_tmpl % (u.user_id, u.name,
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
81 u.lastname, u.username)
298
15e96b5a2685 autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents: 296
diff changeset
82 for u in users])
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
83 return users_array
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
84
1013
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
85 def get_users_groups_js(self):
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
86 users_groups = self.sa.query(UsersGroup)\
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
87 .filter(UsersGroup.users_group_active == True).all()
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
88
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
89 g_tmpl = '''{id:%s, grname:"%s",grmembers:"%s"},'''
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
90
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
91 users_groups_array = '[%s]' % '\n'.join([g_tmpl % \
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
92 (gr.users_group_id, gr.users_group_name,
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
93 len(gr.members))
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
94 for gr in users_groups])
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
95 return users_groups_array
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
96
367
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
97 def update(self, repo_name, form_data):
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 try:
822
d5a71348ee4d small code fixes to repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 811
diff changeset
99 cur_repo = self.get_by_repo_name(repo_name, cache=False)
367
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
100
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
101 #update permissions
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
102 for member, perm, member_type in form_data['perms_updates']:
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
103 if member_type == 'user':
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
104 r2p = self.sa.query(RepoToPerm)\
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1517
diff changeset
105 .filter(RepoToPerm.user == User.get_by_username(member))\
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
106 .filter(RepoToPerm.repository == cur_repo)\
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
107 .one()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
108
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
109 r2p.permission = self.sa.query(Permission)\
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
110 .filter(Permission.permission_name ==
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
111 perm).scalar()
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
112 self.sa.add(r2p)
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
113 else:
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
114 g2p = self.sa.query(UsersGroupRepoToPerm)\
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
115 .filter(UsersGroupRepoToPerm.users_group ==
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
116 UsersGroup.get_by_group_name(member))\
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
117 .filter(UsersGroupRepoToPerm.repository ==
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
118 cur_repo).one()
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
119
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
120 g2p.permission = self.sa.query(Permission)\
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
121 .filter(Permission.permission_name ==
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
122 perm).scalar()
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
123 self.sa.add(g2p)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
124
367
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
125 #set new permissions
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
126 for member, perm, member_type in form_data['perms_new']:
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
127 if member_type == 'user':
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
128 r2p = RepoToPerm()
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
129 r2p.repository = cur_repo
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1517
diff changeset
130 r2p.user = User.get_by_username(member)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
131
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
132 r2p.permission = self.sa.query(Permission)\
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
133 .filter(Permission.
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
134 permission_name == perm)\
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
135 .scalar()
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
136 self.sa.add(r2p)
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
137 else:
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
138 g2p = UsersGroupRepoToPerm()
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
139 g2p.repository = cur_repo
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
140 g2p.users_group = UsersGroup.get_by_group_name(member)
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
141 g2p.permission = self.sa.query(Permission)\
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
142 .filter(Permission.
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
143 permission_name == perm)\
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
144 .scalar()
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
145 self.sa.add(g2p)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
146
367
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
147 #update current repo
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
148 for k, v in form_data.items():
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
149 if k == 'user':
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1517
diff changeset
150 cur_repo.user = User.get_by_username(v)
1323
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
151 elif k == 'repo_name':
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
152 cur_repo.repo_name = form_data['repo_name_full']
1379
7ca0b584c912 fixes #205 db value was not set to none after moving out of group
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
153 elif k == 'repo_group':
1323
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
154 cur_repo.group_id = v
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
155
367
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
156 else:
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
157 setattr(cur_repo, k, v)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
158
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
159 self.sa.add(cur_repo)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
160
1323
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
161 if repo_name != form_data['repo_name_full']:
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
162 # rename repository
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
163 self.__rename_repo(old=repo_name,
a7a772ea7b95 fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents: 1271
diff changeset
164 new=form_data['repo_name_full'])
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
165
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166 self.sa.commit()
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
167 except:
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
168 log.error(traceback.format_exc())
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169 self.sa.rollback()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
170 raise
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
171
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
172 def create(self, form_data, cur_user, just_db=False, fork=False):
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1361
diff changeset
173
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174 try:
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
175 if fork:
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
176 repo_name = form_data['fork_name']
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
177 org_name = form_data['repo_name']
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
178 org_full_name = org_name
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
179
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
180 else:
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
181 org_name = repo_name = form_data['repo_name']
1361
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1351
diff changeset
182 repo_name_full = form_data['repo_name_full']
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1351
diff changeset
183
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
184 new_repo = Repository()
1075
f726a939d2d4 Enable statistics are disabled by default now
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
185 new_repo.enable_statistics = False
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
186 for k, v in form_data.items():
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
187 if k == 'repo_name':
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1361
diff changeset
188 if fork:
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1361
diff changeset
189 v = repo_name
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1361
diff changeset
190 else:
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1361
diff changeset
191 v = repo_name_full
1350
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
192 if k == 'repo_group':
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
193 k = 'group_id'
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
194
1517
142a05597cba assure that we don't have an empty description when creating a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
195 if k == 'description':
142a05597cba assure that we don't have an empty description when creating a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
196 v = v or repo_name
142a05597cba assure that we don't have an empty description when creating a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
197
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198 setattr(new_repo, k, v)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
199
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
200 if fork:
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
201 parent_repo = self.sa.query(Repository)\
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1361
diff changeset
202 .filter(Repository.repo_name == org_full_name).one()
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
203 new_repo.fork = parent_repo
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
204
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
205 new_repo.user_id = cur_user.user_id
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
206 self.sa.add(new_repo)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
207
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
208 #create default permission
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 367
diff changeset
209 repo_to_perm = RepoToPerm()
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 399
diff changeset
210 default = 'repository.read'
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1517
diff changeset
211 for p in User.get_by_username('default').user_perms:
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 399
diff changeset
212 if p.permission.permission_name.startswith('repository.'):
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 399
diff changeset
213 default = p.permission.permission_name
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 399
diff changeset
214 break
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
215
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 399
diff changeset
216 default_perm = 'repository.none' if form_data['private'] else default
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
217
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 367
diff changeset
218 repo_to_perm.permission_id = self.sa.query(Permission)\
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
219 .filter(Permission.permission_name == default_perm)\
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
220 .one().permission_id
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
221
1028
f42ee60e673b fixed issue with db transaction when filesystem creation of repository failed
Marcin Kuzminski <marcin@python-works.com>
parents: 1020
diff changeset
222 repo_to_perm.repository = new_repo
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1517
diff changeset
223 repo_to_perm.user_id = User.get_by_username('default').user_id
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
224
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 367
diff changeset
225 self.sa.add(repo_to_perm)
1028
f42ee60e673b fixed issue with db transaction when filesystem creation of repository failed
Marcin Kuzminski <marcin@python-works.com>
parents: 1020
diff changeset
226
f42ee60e673b fixed issue with db transaction when filesystem creation of repository failed
Marcin Kuzminski <marcin@python-works.com>
parents: 1020
diff changeset
227 if not just_db:
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
228 self.__create_repo(repo_name, form_data['repo_type'],
1350
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
229 form_data['repo_group'],
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
230 form_data['clone_uri'])
1028
f42ee60e673b fixed issue with db transaction when filesystem creation of repository failed
Marcin Kuzminski <marcin@python-works.com>
parents: 1020
diff changeset
231
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
232 self.sa.commit()
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
233
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
234 #now automatically start following this repository as owner
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
235 from rhodecode.model.scm import ScmModel
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
236 ScmModel(self.sa).toggle_following_repo(new_repo.repo_id,
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
237 cur_user.user_id)
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
238
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
239 except:
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
240 log.error(traceback.format_exc())
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
241 self.sa.rollback()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
242 raise
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
243
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
244 def create_fork(self, form_data, cur_user):
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
245 from rhodecode.lib.celerylib import tasks, run_task
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
246 run_task(tasks.create_repo_fork, form_data, cur_user)
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
247
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
248 def delete(self, repo):
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
249 try:
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
250 self.sa.delete(repo)
668
dff6d5cb8bba fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents: 659
diff changeset
251 self.__delete_repo(repo)
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
252 self.sa.commit()
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
253 except:
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
254 log.error(traceback.format_exc())
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
255 self.sa.rollback()
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
256 raise
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
257
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
258 def delete_perm_user(self, form_data, repo_name):
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
259 try:
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 367
diff changeset
260 self.sa.query(RepoToPerm)\
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
261 .filter(RepoToPerm.repository \
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
262 == self.get_by_repo_name(repo_name))\
399
f5c1eec9f376 rename repo2perm into repo_to_perm
Marcin Kuzminski <marcin@python-works.com>
parents: 367
diff changeset
263 .filter(RepoToPerm.user_id == form_data['user_id']).delete()
299
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
264 self.sa.commit()
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
265 except:
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
266 log.error(traceback.format_exc())
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
267 self.sa.rollback()
d303aacb3349 repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents: 298
diff changeset
268 raise
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
269
1015
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1014
diff changeset
270 def delete_perm_users_group(self, form_data, repo_name):
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1014
diff changeset
271 try:
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
272 self.sa.query(UsersGroupRepoToPerm)\
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
273 .filter(UsersGroupRepoToPerm.repository \
1015
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1014
diff changeset
274 == self.get_by_repo_name(repo_name))\
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
275 .filter(UsersGroupRepoToPerm.users_group_id \
1015
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1014
diff changeset
276 == form_data['users_group_id']).delete()
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1014
diff changeset
277 self.sa.commit()
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1014
diff changeset
278 except:
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1014
diff changeset
279 log.error(traceback.format_exc())
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1014
diff changeset
280 self.sa.rollback()
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1014
diff changeset
281 raise
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1014
diff changeset
282
708
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
283 def delete_stats(self, repo_name):
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
284 try:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
285 self.sa.query(Statistics)\
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
286 .filter(Statistics.repository == \
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
287 self.get_by_repo_name(repo_name)).delete()
708
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
288 self.sa.commit()
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
289 except:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
290 log.error(traceback.format_exc())
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
291 self.sa.rollback()
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
292 raise
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
293
1350
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
294 def __create_repo(self, repo_name, alias, new_parent_id, clone_uri=False):
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
295 """
1361
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1351
diff changeset
296 makes repository on filesystem. It's group aware means it'll create
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1351
diff changeset
297 a repository within a group, and alter the paths accordingly of
87ca17540603 fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1351
diff changeset
298 group location
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1119
diff changeset
299
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
300 :param repo_name:
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
301 :param alias:
1350
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
302 :param parent_id:
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
303 :param clone_uri:
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
304 """
1507
7d687ed11929 changed check_... functions from their stupid names to something less retarded :)
Marcin Kuzminski <marcin@python-works.com>
parents: 1505
diff changeset
305 from rhodecode.lib.utils import is_valid_repo
1517
142a05597cba assure that we don't have an empty description when creating a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
306
1350
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
307 if new_parent_id:
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
308 paths = Group.get(new_parent_id).full_path.split(Group.url_sep())
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
309 new_parent_path = os.sep.join(paths)
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
310 else:
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
311 new_parent_path = ''
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
312
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
313 repo_path = os.path.join(*map(lambda x:safe_str(x),
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
314 [self.repos_path, new_parent_path, repo_name]))
1350
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
315
1507
7d687ed11929 changed check_... functions from their stupid names to something less retarded :)
Marcin Kuzminski <marcin@python-works.com>
parents: 1505
diff changeset
316 if is_valid_repo(repo_path, self.repos_path) is False:
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
317 log.info('creating repo %s in %s @ %s', repo_name, repo_path,
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
318 clone_uri)
659
758f64f3fbda extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents: 651
diff changeset
319 backend = get_backend(alias)
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
320
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
321 backend(repo_path, create=True, src_url=clone_uri)
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
322
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1393
diff changeset
323
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
324 def __rename_repo(self, old, new):
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
325 """
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
326 renames repository on filesystem
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1119
diff changeset
327
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
328 :param old: old name
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
329 :param new: new name
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
330 """
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 328
diff changeset
331 log.info('renaming repo from %s to %s', old, new)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
332
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
333 old_path = os.path.join(self.repos_path, old)
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
334 new_path = os.path.join(self.repos_path, new)
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 328
diff changeset
335 if os.path.isdir(new_path):
1492
7592484e84d3 fixed exception message
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
336 raise Exception('Was trying to rename to already existing dir %s' \
7592484e84d3 fixed exception message
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
337 % new_path)
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
338 shutil.move(old_path, new_path)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
339
668
dff6d5cb8bba fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents: 659
diff changeset
340 def __delete_repo(self, repo):
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
341 """
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
342 removes repo from filesystem, the removal is acctually made by
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
343 added rm__ prefix into dir, and rename internat .hg/.git dirs so this
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
344 repository is no longer valid for rhodecode, can be undeleted later on
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
345 by reverting the renames on this repository
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1119
diff changeset
346
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
347 :param repo: repo object
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
348 """
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
349 rm_path = os.path.join(self.repos_path, repo.repo_name)
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
350 log.info("Removing %s", rm_path)
668
dff6d5cb8bba fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents: 659
diff changeset
351 #disable hg/git
dff6d5cb8bba fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents: 659
diff changeset
352 alias = repo.repo_type
dff6d5cb8bba fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents: 659
diff changeset
353 shutil.move(os.path.join(rm_path, '.%s' % alias),
dff6d5cb8bba fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents: 659
diff changeset
354 os.path.join(rm_path, 'rm__.%s' % alias))
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
355 #disable repo
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
356 shutil.move(rm_path, os.path.join(self.repos_path, 'rm__%s__%s' \
1119
143b37b7b4aa fixes #126, all credits go to cejones <chad.jones@milwaukeetool.com>
Marcin Kuzminski <marcin@python-works.com>
parents: 1112
diff changeset
357 % (datetime.today()\
143b37b7b4aa fixes #126, all credits go to cejones <chad.jones@milwaukeetool.com>
Marcin Kuzminski <marcin@python-works.com>
parents: 1112
diff changeset
358 .strftime('%Y%m%d_%H%M%S_%f'),
143b37b7b4aa fixes #126, all credits go to cejones <chad.jones@milwaukeetool.com>
Marcin Kuzminski <marcin@python-works.com>
parents: 1112
diff changeset
359 repo.repo_name)))