Show More
@@ -151,7 +151,7 b' class SettingsController(BaseController)' | |||
|
151 | 151 | def fork_create(self, repo_name): |
|
152 | 152 | repo_model = RepoModel() |
|
153 | 153 | c.repo_info = repo_model.get(repo_name) |
|
154 | _form = RepoForkForm()() | |
|
154 | _form = RepoForkForm(old_data={'repo_type':c.repo_info.repo_type})() | |
|
155 | 155 | form_result = {} |
|
156 | 156 | try: |
|
157 | 157 | form_result = _form.to_python(dict(request.POST)) |
@@ -11,28 +11,28 b' from rhodecode.lib.utils import get_repo' | |||
|
11 | 11 | from rhodecode.model import meta |
|
12 | 12 | from rhodecode.model.hg import _get_repos_cached, \ |
|
13 | 13 | _get_repos_switcher_cached |
|
14 | ||
|
14 | from vcs import BACKENDS | |
|
15 | 15 | class BaseController(WSGIController): |
|
16 | ||
|
16 | ||
|
17 | 17 | def __before__(self): |
|
18 | 18 | c.rhodecode_version = __version__ |
|
19 | 19 | c.rhodecode_name = config['rhodecode_title'] |
|
20 | 20 | c.repo_name = get_repo_slug(request) |
|
21 | 21 | c.cached_repo_list = _get_repos_cached() |
|
22 | 22 | c.repo_switcher_list = _get_repos_switcher_cached(c.cached_repo_list) |
|
23 | ||
|
23 | c.backends = BACKENDS.keys() | |
|
24 | 24 | if c.repo_name: |
|
25 | 25 | cached_repo = c.cached_repo_list.get(c.repo_name) |
|
26 | ||
|
26 | ||
|
27 | 27 | if cached_repo: |
|
28 | 28 | c.repository_tags = cached_repo.tags |
|
29 | 29 | c.repository_branches = cached_repo.branches |
|
30 | 30 | else: |
|
31 | 31 | c.repository_tags = {} |
|
32 | 32 | c.repository_branches = {} |
|
33 | ||
|
33 | ||
|
34 | 34 | self.sa = meta.Session() |
|
35 | ||
|
35 | ||
|
36 | 36 | def __call__(self, environ, start_response): |
|
37 | 37 | """Invoke the Controller""" |
|
38 | 38 | # WSGIController.__call__ dispatches to the Controller method |
@@ -289,18 +289,20 b' def send_email(recipients, subject, body' | |||
|
289 | 289 | |
|
290 | 290 | @task |
|
291 | 291 | def create_repo_fork(form_data, cur_user): |
|
292 | import os | |
|
293 | 292 | from rhodecode.model.repo import RepoModel |
|
294 | ||
|
293 | from vcs import get_backend | |
|
294 | log = create_repo_fork.get_logger() | |
|
295 | 295 | repo_model = RepoModel(get_session()) |
|
296 | 296 | repo_model.create(form_data, cur_user, just_db=True, fork=True) |
|
297 | ||
|
298 |
repos_path = get_hg_ui_settings()['paths_root_path'] |
|
|
299 |
repo_path = os.path.join(repos_path, |
|
|
297 | repo_name = form_data['repo_name'] | |
|
298 | repos_path = get_hg_ui_settings()['paths_root_path'] | |
|
299 | repo_path = os.path.join(repos_path, repo_name) | |
|
300 | 300 | repo_fork_path = os.path.join(repos_path, form_data['fork_name']) |
|
301 | alias = form_data['repo_type'] | |
|
301 | 302 | |
|
302 | MercurialRepository(str(repo_fork_path), True, clone_url=str(repo_path)) | |
|
303 | ||
|
303 | log.info('creating repo fork %s as %s', repo_name, repo_path) | |
|
304 | backend = get_backend(alias) | |
|
305 | backend(str(repo_fork_path), create=True, src_url=str(repo_path)) | |
|
304 | 306 | |
|
305 | 307 | def __get_codes_stats(repo_name): |
|
306 | 308 | LANGUAGES_EXTENSIONS = ['action', 'adp', 'ashx', 'asmx', |
@@ -345,8 +345,9 b' def repo2db_mapper(initial_repo_list, re' | |||
|
345 | 345 | form_data = { |
|
346 | 346 | 'repo_name':name, |
|
347 | 347 | 'repo_type':repo.alias, |
|
348 |
'description':repo.description |
|
|
349 |
|
|
|
348 | 'description':repo.description \ | |
|
349 | if repo.description != 'unknown' else \ | |
|
350 | '%s repository' % name, | |
|
350 | 351 | 'private':False |
|
351 | 352 | } |
|
352 | 353 | rm.create(form_data, user, just_db=True) |
@@ -30,6 +30,7 b' from rhodecode.model.user import UserMod' | |||
|
30 | 30 | from rhodecode.model.repo import RepoModel |
|
31 | 31 | from rhodecode.model.db import User |
|
32 | 32 | from webhelpers.pylonslib.secure_form import authentication_token |
|
33 | from vcs import BACKENDS | |
|
33 | 34 | import formencode |
|
34 | 35 | import logging |
|
35 | 36 | import os |
@@ -147,6 +148,15 b' def ValidRepoName(edit, old_data):' | |||
|
147 | 148 | |
|
148 | 149 | return _ValidRepoName |
|
149 | 150 | |
|
151 | def ValidForkType(old_data): | |
|
152 | class _ValidForkType(formencode.validators.FancyValidator): | |
|
153 | ||
|
154 | def to_python(self, value, state): | |
|
155 | if old_data['repo_type'] != value: | |
|
156 | raise formencode.Invalid(_('Fork have to be the same type as original'), value, state) | |
|
157 | return value | |
|
158 | return _ValidForkType | |
|
159 | ||
|
150 | 160 | class ValidPerms(formencode.validators.FancyValidator): |
|
151 | 161 | messages = {'perm_new_user_name':_('This username is not valid')} |
|
152 | 162 | |
@@ -292,7 +302,7 b' def RepoForm(edit=False, old_data={}):' | |||
|
292 | 302 | repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data)) |
|
293 | 303 | description = UnicodeString(strip=True, min=1, not_empty=True) |
|
294 | 304 | private = StringBoolean(if_missing=False) |
|
295 | ||
|
305 | repo_type = OneOf(BACKENDS.keys()) | |
|
296 | 306 | if edit: |
|
297 | 307 | user = All(Int(not_empty=True), ValidRepoUser) |
|
298 | 308 | |
@@ -306,7 +316,7 b' def RepoForkForm(edit=False, old_data={}' | |||
|
306 | 316 | fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data)) |
|
307 | 317 | description = UnicodeString(strip=True, min=1, not_empty=True) |
|
308 | 318 | private = StringBoolean(if_missing=False) |
|
309 | ||
|
319 | repo_type = All(ValidForkType(old_data), OneOf(BACKENDS.keys())) | |
|
310 | 320 | return _RepoForkForm |
|
311 | 321 | |
|
312 | 322 | def RepoSettingsForm(edit=False, old_data={}): |
@@ -21,7 +21,7 b' Created on Jun 5, 2010' | |||
|
21 | 21 | model for handling repositories actions |
|
22 | 22 | :author: marcink |
|
23 | 23 | """ |
|
24 | ||
|
24 | from vcs.backends import get_repo, get_backend | |
|
25 | 25 | from datetime import datetime |
|
26 | 26 | from pylons import app_globals as g |
|
27 | 27 | from rhodecode.model.db import Repository, RepoToPerm, User, Permission |
@@ -151,7 +151,7 b' class RepoModel(object):' | |||
|
151 | 151 | self.sa.add(repo_to_perm) |
|
152 | 152 | self.sa.commit() |
|
153 | 153 | if not just_db: |
|
154 | self.__create_repo(repo_name) | |
|
154 | self.__create_repo(repo_name, form_data['repo_type']) | |
|
155 | 155 | except: |
|
156 | 156 | log.error(traceback.format_exc()) |
|
157 | 157 | self.sa.rollback() |
@@ -182,13 +182,13 b' class RepoModel(object):' | |||
|
182 | 182 | self.sa.rollback() |
|
183 | 183 | raise |
|
184 | 184 | |
|
185 | def __create_repo(self, repo_name): | |
|
185 | def __create_repo(self, repo_name, alias): | |
|
186 | 186 | from rhodecode.lib.utils import check_repo |
|
187 | 187 | repo_path = os.path.join(g.base_path, repo_name) |
|
188 | 188 | if check_repo(repo_name, g.base_path): |
|
189 | 189 | log.info('creating repo %s in %s', repo_name, repo_path) |
|
190 | from vcs.backends.hg import MercurialRepository | |
|
191 |
|
|
|
190 | backend = get_backend(alias) | |
|
191 | backend(repo_path, create=True) | |
|
192 | 192 | |
|
193 | 193 | def __rename_repo(self, old, new): |
|
194 | 194 | log.info('renaming repo from %s to %s', old, new) |
@@ -35,6 +35,14 b'' | |||
|
35 | 35 | </div> |
|
36 | 36 | </div> |
|
37 | 37 | <div class="field"> |
|
38 | <div class="label"> | |
|
39 | <label for="repo_type">${_('Type')}:</label> | |
|
40 | </div> | |
|
41 | <div class="input"> | |
|
42 | ${h.select('repo_type','hg',c.backends,class_="small")} | |
|
43 | </div> | |
|
44 | </div> | |
|
45 | <div class="field"> | |
|
38 | 46 | <div class="label label-textarea"> |
|
39 | 47 | <label for="description">${_('Description')}:</label> |
|
40 | 48 | </div> |
@@ -32,6 +32,14 b'' | |||
|
32 | 32 | </div> |
|
33 | 33 | </div> |
|
34 | 34 | <div class="field"> |
|
35 | <div class="label"> | |
|
36 | <label for="repo_type">${_('Type')}:</label> | |
|
37 | </div> | |
|
38 | <div class="input"> | |
|
39 | ${h.select('repo_type','hg',c.backends,class_="small")} | |
|
40 | </div> | |
|
41 | </div> | |
|
42 | <div class="field"> | |
|
35 | 43 | <div class="label label-textarea"> |
|
36 | 44 | <label for="description">${_('Description')}:</label> |
|
37 | 45 | </div> |
@@ -35,7 +35,14 b'' | |||
|
35 | 35 | ${h.text('repo_name',class_="small")} |
|
36 | 36 | </div> |
|
37 | 37 | </div> |
|
38 | ||
|
38 | <div class="field"> | |
|
39 | <div class="label"> | |
|
40 | <label for="repo_type">${_('Type')}:</label> | |
|
41 | </div> | |
|
42 | <div class="input"> | |
|
43 | ${h.select('repo_type','hg',c.backends,class_="small")} | |
|
44 | </div> | |
|
45 | </div> | |
|
39 | 46 | <div class="field"> |
|
40 | 47 | <div class="label label-textarea"> |
|
41 | 48 | <label for="description">${_('Description')}:</label> |
@@ -30,6 +30,7 b'' | |||
|
30 | 30 | </div> |
|
31 | 31 | <div class="input"> |
|
32 | 32 | ${h.text('fork_name',class_="small")} |
|
33 | ${h.hidden('repo_type',c.repo_info.repo_type)} | |
|
33 | 34 | </div> |
|
34 | 35 | </div> |
|
35 | 36 | <div class="field"> |
@@ -17,8 +17,8 b' class TestLoginController(TestController' | |||
|
17 | 17 | assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status |
|
18 | 18 | assert response.session['rhodecode_user'].username == 'test_admin', 'wrong logged in user' |
|
19 | 19 | response = response.follow() |
|
20 |
assert ' |
|
|
21 | ||
|
20 | assert 'vcs_test repository' in response.body | |
|
21 | ||
|
22 | 22 | def test_login_regular_ok(self): |
|
23 | 23 | response = self.app.post(url(controller='login', action='index'), |
|
24 | 24 | {'username':'test_regular', |
@@ -27,9 +27,9 b' class TestLoginController(TestController' | |||
|
27 | 27 | assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status |
|
28 | 28 | assert response.session['rhodecode_user'].username == 'test_regular', 'wrong logged in user' |
|
29 | 29 | response = response.follow() |
|
30 |
assert ' |
|
|
30 | assert 'vcs_test repository' in response.body | |
|
31 | 31 | assert '<a title="Admin" href="/_admin">' not in response.body |
|
32 | ||
|
32 | ||
|
33 | 33 | def test_login_ok_came_from(self): |
|
34 | 34 | test_came_from = '/_admin/users' |
|
35 | 35 | response = self.app.post(url(controller='login', action='index', came_from=test_came_from), |
@@ -37,11 +37,11 b' class TestLoginController(TestController' | |||
|
37 | 37 | 'password':'test12'}) |
|
38 | 38 | assert response.status == '302 Found', 'Wrong response code from came from redirection' |
|
39 | 39 | response = response.follow() |
|
40 | ||
|
40 | ||
|
41 | 41 | assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status |
|
42 | 42 | assert 'Users administration' in response.body, 'No proper title in response' |
|
43 | ||
|
44 | ||
|
43 | ||
|
44 | ||
|
45 | 45 | def test_login_short_password(self): |
|
46 | 46 | response = self.app.post(url(controller='login', action='index'), |
|
47 | 47 | {'username':'error', |
@@ -55,15 +55,15 b' class TestLoginController(TestController' | |||
|
55 | 55 | {'username':'error', |
|
56 | 56 | 'password':'test12'}) |
|
57 | 57 | assert response.status == '200 OK', 'Wrong response from login page' |
|
58 | ||
|
58 | ||
|
59 | 59 | assert 'invalid user name' in response.body, 'No error username message in response' |
|
60 | 60 | assert 'invalid password' in response.body, 'No error password message in response' |
|
61 | ||
|
62 | ||
|
61 | ||
|
62 | ||
|
63 | 63 | def test_register(self): |
|
64 | 64 | response = self.app.get(url(controller='login', action='register')) |
|
65 | 65 | assert 'Sign Up to rhodecode' in response.body, 'wrong page for user registration' |
|
66 | ||
|
66 | ||
|
67 | 67 | def test_register_err_same_username(self): |
|
68 | 68 | response = self.app.post(url(controller='login', action='register'), |
|
69 | 69 | {'username':'test_admin', |
@@ -71,10 +71,10 b' class TestLoginController(TestController' | |||
|
71 | 71 | 'email':'goodmail@domain.com', |
|
72 | 72 | 'name':'test', |
|
73 | 73 | 'lastname':'test'}) |
|
74 | ||
|
74 | ||
|
75 | 75 | assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status |
|
76 |
assert 'This username already exists' in response.body |
|
|
77 | ||
|
76 | assert 'This username already exists' in response.body | |
|
77 | ||
|
78 | 78 | def test_register_err_wrong_data(self): |
|
79 | 79 | response = self.app.post(url(controller='login', action='register'), |
|
80 | 80 | {'username':'xs', |
@@ -82,20 +82,20 b' class TestLoginController(TestController' | |||
|
82 | 82 | 'email':'goodmailm', |
|
83 | 83 | 'name':'test', |
|
84 | 84 | 'lastname':'test'}) |
|
85 | ||
|
85 | ||
|
86 | 86 | assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status |
|
87 | 87 | assert 'An email address must contain a single @' in response.body |
|
88 | 88 | assert 'Please enter a value' in response.body |
|
89 | ||
|
90 | ||
|
91 | ||
|
89 | ||
|
90 | ||
|
91 | ||
|
92 | 92 | def test_register_ok(self): |
|
93 | 93 | username = 'test_regular4' |
|
94 | 94 | password = 'qweqwe' |
|
95 | 95 | email = 'marcin@test.com' |
|
96 | 96 | name = 'testname' |
|
97 | 97 | lastname = 'testlastname' |
|
98 | ||
|
98 | ||
|
99 | 99 | response = self.app.post(url(controller='login', action='register'), |
|
100 | 100 | {'username':username, |
|
101 | 101 | 'password':password, |
@@ -103,23 +103,23 b' class TestLoginController(TestController' | |||
|
103 | 103 | 'name':name, |
|
104 | 104 | 'lastname':lastname}) |
|
105 | 105 | print response.body |
|
106 |
assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status |
|
|
106 | assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status | |
|
107 | 107 | assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration' |
|
108 | ||
|
108 | ||
|
109 | 109 | ret = self.sa.query(User).filter(User.username == 'test_regular4').one() |
|
110 | 110 | assert ret.username == username , 'field mismatch %s %s' % (ret.username, username) |
|
111 | 111 | assert check_password(password, ret.password) == True , 'password mismatch' |
|
112 | 112 | assert ret.email == email , 'field mismatch %s %s' % (ret.email, email) |
|
113 | 113 | assert ret.name == name , 'field mismatch %s %s' % (ret.name, name) |
|
114 | 114 | assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname) |
|
115 | ||
|
116 | ||
|
117 |
def test_forgot_password_wrong_mail(self): |
|
|
115 | ||
|
116 | ||
|
117 | def test_forgot_password_wrong_mail(self): | |
|
118 | 118 | response = self.app.post(url(controller='login', action='password_reset'), |
|
119 | 119 | {'email':'marcin@wrongmail.org', }) |
|
120 | ||
|
120 | ||
|
121 | 121 | assert "That e-mail address doesn't exist" in response.body, 'Missing error message about wrong email' |
|
122 | ||
|
122 | ||
|
123 | 123 | def test_forgot_password(self): |
|
124 | 124 | response = self.app.get(url(controller='login', action='password_reset')) |
|
125 | 125 | assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status |
@@ -129,19 +129,19 b' class TestLoginController(TestController' | |||
|
129 | 129 | email = 'marcin@python-works.com' |
|
130 | 130 | name = 'passwd' |
|
131 | 131 | lastname = 'reset' |
|
132 | ||
|
132 | ||
|
133 | 133 | response = self.app.post(url(controller='login', action='register'), |
|
134 | 134 | {'username':username, |
|
135 | 135 | 'password':password, |
|
136 | 136 | 'email':email, |
|
137 | 137 | 'name':name, |
|
138 |
'lastname':lastname}) |
|
|
138 | 'lastname':lastname}) | |
|
139 | 139 | #register new user for email test |
|
140 | 140 | response = self.app.post(url(controller='login', action='password_reset'), |
|
141 | 141 | {'email':email, }) |
|
142 | 142 | print response.session['flash'] |
|
143 | 143 | assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration' |
|
144 | 144 | assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset' |
|
145 | ||
|
146 | ||
|
147 | ||
|
145 | ||
|
146 | ||
|
147 |
General Comments 0
You need to be logged in to leave comments.
Login now