##// END OF EJS Templates
notification to commit author + gardening
marcink -
r1716:7d1fc253 beta
parent child Browse files
Show More
@@ -67,13 +67,13 b' class ApiController(JSONRPCController):'
67 67 return None
68 68
69 69 return dict(id=user.user_id,
70 username=user.username,
71 firstname=user.name,
72 lastname=user.lastname,
73 email=user.email,
74 active=user.active,
75 admin=user.admin,
76 ldap=user.ldap_dn)
70 username=user.username,
71 firstname=user.name,
72 lastname=user.lastname,
73 email=user.email,
74 active=user.active,
75 admin=user.admin,
76 ldap=user.ldap_dn)
77 77
78 78 @HasPermissionAllDecorator('hg.admin')
79 79 def get_users(self, apiuser):
@@ -112,7 +112,7 b' class ApiController(JSONRPCController):'
112 112 :param ldap_dn:
113 113 """
114 114
115 if self.get_user(apiuser, username):
115 if User.get_by_username(username):
116 116 raise JSONRPCError("user %s already exist" % username)
117 117
118 118 try:
@@ -280,17 +280,17 b' class ChangesetController(BaseRepoContro'
280 280 revision=revision,
281 281 f_path=request.POST.get('f_path'),
282 282 line_no=request.POST.get('line'))
283 Session.commit()
283 Session().commit()
284 284 return redirect(h.url('changeset_home', repo_name=repo_name,
285 285 revision=revision))
286 286
287 287 @jsonify
288 def delete_comment(self, comment_id):
288 def delete_comment(self, repo_name, comment_id):
289 289 co = ChangesetComment.get(comment_id)
290 290 owner = lambda : co.author.user_id == c.rhodecode_user.user_id
291 291 if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
292 292 ChangesetCommentsModel().delete(comment=co)
293 Session.commit()
293 Session().commit()
294 294 return True
295 295 else:
296 296 raise HTTPForbidden()
@@ -54,9 +54,11 b' log = logging.getLogger(__name__)'
54 54
55 55
56 56 class PasswordGenerator(object):
57 """This is a simple class for generating password from
58 different sets of characters
59 usage:
57 """
58 This is a simple class for generating password from different sets of
59 characters
60 usage::
61
60 62 passwd_gen = PasswordGenerator()
61 63 #print 8-letter password containing only big and small letters
62 64 of alphabet
@@ -420,7 +422,8 b' class LoginRequired(object):'
420 422
421 423
422 424 class NotAnonymous(object):
423 """Must be logged in to execute this function else
425 """
426 Must be logged in to execute this function else
424 427 redirect to login page"""
425 428
426 429 def __call__(self, func):
@@ -497,7 +500,8 b' class PermsDecorator(object):'
497 500
498 501
499 502 class HasPermissionAllDecorator(PermsDecorator):
500 """Checks for access permission for all given predicates. All of them
503 """
504 Checks for access permission for all given predicates. All of them
501 505 have to be meet in order to fulfill the request
502 506 """
503 507
@@ -508,7 +512,8 b' class HasPermissionAllDecorator(PermsDec'
508 512
509 513
510 514 class HasPermissionAnyDecorator(PermsDecorator):
511 """Checks for access permission for any of given predicates. In order to
515 """
516 Checks for access permission for any of given predicates. In order to
512 517 fulfill the request any of predicates must be meet
513 518 """
514 519
@@ -519,7 +524,8 b' class HasPermissionAnyDecorator(PermsDec'
519 524
520 525
521 526 class HasRepoPermissionAllDecorator(PermsDecorator):
522 """Checks for access permission for all given predicates for specific
527 """
528 Checks for access permission for all given predicates for specific
523 529 repository. All of them have to be meet in order to fulfill the request
524 530 """
525 531
@@ -535,7 +541,8 b' class HasRepoPermissionAllDecorator(Perm'
535 541
536 542
537 543 class HasRepoPermissionAnyDecorator(PermsDecorator):
538 """Checks for access permission for any of given predicates for specific
544 """
545 Checks for access permission for any of given predicates for specific
539 546 repository. In order to fulfill the request any of predicates must be meet
540 547 """
541 548
@@ -168,7 +168,7 b' class DbManage(object):'
168 168 #CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
169 169 for step in upgrade_steps:
170 170 print ('performing upgrade step %s' % step)
171 callable = getattr(UpgradeSteps(self), 'step_%s' % step)()
171 getattr(UpgradeSteps(self), 'step_%s' % step)()
172 172
173 173 def fix_repo_paths(self):
174 174 """Fixes a old rhodecode version path into new one without a '*'
@@ -10,7 +10,7 b' import urllib'
10 10 import math
11 11
12 12 from datetime import datetime
13 from pygments.formatters import HtmlFormatter
13 from pygments.formatters.html import HtmlFormatter
14 14 from pygments import highlight as code_highlight
15 15 from pylons import url, request, config
16 16 from pylons.i18n.translation import _, ungettext
@@ -151,7 +151,8 b' class SmtpMailer(object):'
151 151 'a dict in format {"filename":"filepath"}')
152 152
153 153 def get_content(self, msg_file):
154 """Get content based on type, if content is a string do open first
154 """
155 Get content based on type, if content is a string do open first
155 156 else just read because it's a probably open file object
156 157
157 158 :param msg_file:
@@ -389,11 +389,7 b' def repo2db_mapper(initial_repo_list, re'
389 389 if user is None:
390 390 raise Exception('Missing administrative account !')
391 391 added = []
392 # fixup groups paths to new format on the fly
393 # TODO: remove this in future
394 for g in RepoGroup.query().all():
395 g.group_name = g.get_new_name(g.name)
396 sa.add(g)
392
397 393 for name, repo in initial_repo_list.items():
398 394 group = map_groups(name.split(Repository.url_sep()))
399 395 if not rm.get_by_repo_name(name, cache=False):
@@ -485,8 +481,7 b' def create_test_env(repos_test_path, con'
485 481 install test repository into tmp dir
486 482 """
487 483 from rhodecode.lib.db_manage import DbManage
488 from rhodecode.tests import HG_REPO, GIT_REPO, NEW_HG_REPO, NEW_GIT_REPO, \
489 HG_FORK, GIT_FORK, TESTS_TMP_PATH
484 from rhodecode.tests import HG_REPO, TESTS_TMP_PATH
490 485 import tarfile
491 486 import shutil
492 487 from os.path import abspath
@@ -73,7 +73,7 b' class BaseModel(object):'
73 73 else:
74 74 self.sa = meta.Session()
75 75
76 def __get_instance(self, cls, instance):
76 def _get_instance(self, cls, instance):
77 77 """
78 78 Get's instance of given cls using some simple lookup mechanism
79 79
@@ -41,7 +41,7 b' log = logging.getLogger(__name__)'
41 41 class ChangesetCommentsModel(BaseModel):
42 42
43 43 def __get_changeset_comment(self, changeset_comment):
44 return self.__get_instance(ChangesetComment, changeset_comment)
44 return self._get_instance(ChangesetComment, changeset_comment)
45 45
46 46 def _extract_mentions(self, s):
47 47 user_objects = []
@@ -65,7 +65,9 b' class ChangesetCommentsModel(BaseModel):'
65 65 """
66 66 if text:
67 67 repo = Repository.get(repo_id)
68 desc = repo.scm_instance.get_changeset(revision).message
68 cs = repo.scm_instance.get_changeset(revision)
69 desc = cs.message
70 author = cs.author_email
69 71 comment = ChangesetComment()
70 72 comment.repo = repo
71 73 comment.user_id = user_id
@@ -90,11 +92,21 b' class ChangesetCommentsModel(BaseModel):'
90 92 )
91 93 body = text
92 94 recipients = ChangesetComment.get_users(revision=revision)
93 recipients += self._extract_mentions(body)
95 # add changeset author
96 recipients += [User.get_by_email(author)]
97
94 98 NotificationModel().create(created_by=user_id, subject=subj,
95 99 body=body, recipients=recipients,
96 100 type_=Notification.TYPE_CHANGESET_COMMENT)
97 101
102 mention_recipients = set(self._extract_mentions(body)).difference(recipients)
103 if mention_recipients:
104 subj = _('[Mention]') + ' ' + subj
105 NotificationModel().create(created_by=user_id, subject=subj,
106 body = body, recipients = mention_recipients,
107 type_=Notification.TYPE_CHANGESET_COMMENT)
108
109 self.sa.commit()
98 110 return comment
99 111
100 112 def delete(self, comment):
@@ -323,6 +323,15 b' class User(Base, BaseModel):'
323 323 "get_api_key_%s" % api_key))
324 324 return q.scalar()
325 325
326 @classmethod
327 def get_by_email(cls, email, cache=False):
328 q = cls.query().filter(cls.email == email)
329
330 if cache:
331 q = q.options(FromCache("sql_cache_short",
332 "get_api_key_%s" % email))
333 return q.scalar()
334
326 335 def update_lastlogin(self):
327 336 """Update user lastlogin"""
328 337
@@ -36,19 +36,15 b' from rhodecode.model.db import Notificat'
36 36
37 37 log = logging.getLogger(__name__)
38 38
39
39 40 class NotificationModel(BaseModel):
40 41
41 42
42 43 def __get_user(self, user):
43 if isinstance(user, User):
44 return user
45 elif isinstance(user, basestring):
44 if isinstance(user, basestring):
46 45 return User.get_by_username(username=user)
47 elif isinstance(user, int):
48 return User.get(user)
49 46 else:
50 raise Exception('Unsupported user must be one of int,'
51 'str or User object')
47 return self._get_instance(User, user)
52 48
53 49 def __get_notification(self, notification):
54 50 if isinstance(notification, Notification):
@@ -82,7 +78,9 b' class NotificationModel(BaseModel):'
82 78
83 79 recipients_objs = []
84 80 for u in recipients:
85 recipients_objs.append(self.__get_user(u))
81 obj = self.__get_user(u)
82 if obj:
83 recipients_objs.append(obj)
86 84 recipients_objs = set(recipients_objs)
87 85 return Notification.create(created_by=created_by_obj, subject=subject,
88 86 body=body, recipients=recipients_objs,
@@ -33,16 +33,17 b' from rhodecode.lib.caching_query import '
33 33 from rhodecode.model import BaseModel
34 34 from rhodecode.model.db import User, Permission, UserToPerm, UserRepoToPerm
35 35
36
37 36 log = logging.getLogger(__name__)
38 37
39 38
40 39 class PermissionModel(BaseModel):
41 """Permissions model for RhodeCode
40 """
41 Permissions model for RhodeCode
42 42 """
43 43
44 44 def get_permission(self, permission_id, cache=False):
45 """Get's permissions by id
45 """
46 Get's permissions by id
46 47
47 48 :param permission_id: id of permission to get from database
48 49 :param cache: use Cache for this query
@@ -54,7 +55,8 b' class PermissionModel(BaseModel):'
54 55 return perm.get(permission_id)
55 56
56 57 def get_permission_by_name(self, name, cache=False):
57 """Get's permissions by given name
58 """
59 Get's permissions by given name
58 60
59 61 :param name: name to fetch
60 62 :param cache: Use cache for this query
@@ -78,7 +80,7 b' class PermissionModel(BaseModel):'
78 80 ' your database' % len(u2p))
79 81
80 82 try:
81 #stage 1 change defaults
83 # stage 1 change defaults
82 84 for p in u2p:
83 85 if p.permission.permission_name.startswith('repository.'):
84 86 p.permission = self.get_permission_by_name(
@@ -103,7 +105,7 b' class PermissionModel(BaseModel):'
103 105 form_result['default_perm'])
104 106 self.sa.add(r2p)
105 107
106 #stage 3 set anonymous access
108 # stage 3 set anonymous access
107 109 if perm_user.username == 'default':
108 110 perm_user.active = bool(form_result['anonymous'])
109 111 self.sa.add(perm_user)
@@ -28,8 +28,6 b' import logging'
28 28 import traceback
29 29 from datetime import datetime
30 30
31 from sqlalchemy.orm import joinedload, make_transient
32
33 31 from vcs.utils.lazy import LazyProperty
34 32 from vcs.backends import get_backend
35 33
@@ -39,7 +37,6 b' from rhodecode.lib.caching_query import '
39 37 from rhodecode.model import BaseModel
40 38 from rhodecode.model.db import Repository, UserRepoToPerm, User, Permission, \
41 39 Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, RepoGroup
42 from rhodecode.model.user import UserModel
43 40
44 41 log = logging.getLogger(__name__)
45 42
@@ -48,7 +45,8 b' class RepoModel(BaseModel):'
48 45
49 46 @LazyProperty
50 47 def repos_path(self):
51 """Get's the repositories root path from database
48 """
49 Get's the repositories root path from database
52 50 """
53 51
54 52 q = self.sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one()
@@ -141,10 +139,11 b' class RepoModel(BaseModel):'
141 139 # update permissions
142 140 for member, perm, member_type in form_data['perms_updates']:
143 141 if member_type == 'user':
142 _member = User.get_by_username(member)
144 143 r2p = self.sa.query(UserRepoToPerm)\
145 .filter(UserRepoToPerm.user == User.get_by_username(member))\
146 .filter(UserRepoToPerm.repository == cur_repo)\
147 .one()
144 .filter(UserRepoToPerm.user == _member)\
145 .filter(UserRepoToPerm.repository == cur_repo)\
146 .one()
148 147
149 148 r2p.permission = self.sa.query(Permission)\
150 149 .filter(Permission.permission_name ==
@@ -316,8 +315,8 b' class RepoModel(BaseModel):'
316 315 obj = self.sa.query(UsersGroupRepoToPerm)\
317 316 .filter(UsersGroupRepoToPerm.repository \
318 317 == self.get_by_repo_name(repo_name))\
319 .filter(UsersGroupRepoToPerm.users_group_id \
320 == form_data['users_group_id']).one()
318 .filter(UsersGroupRepoToPerm.users_group_id
319 == form_data['users_group_id']).one()
321 320 self.sa.delete(obj)
322 321 self.sa.commit()
323 322 except:
@@ -351,7 +350,8 b' class RepoModel(BaseModel):'
351 350 from rhodecode.lib.utils import is_valid_repo, is_valid_repos_group
352 351
353 352 if new_parent_id:
354 paths = RepoGroup.get(new_parent_id).full_path.split(RepoGroup.url_sep())
353 paths = RepoGroup.get(new_parent_id)\
354 .full_path.split(RepoGroup.url_sep())
355 355 new_parent_path = os.sep.join(paths)
356 356 else:
357 357 new_parent_path = ''
@@ -24,12 +24,14 b''
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26 26 import logging
27 from rhodecode.model.db import BaseModel, UserRepoToPerm, Permission
28 from rhodecode.model.meta import Session
27 from rhodecode.model import BaseModel
28 from rhodecode.model.db import UserRepoToPerm, Permission
29 29
30 30 log = logging.getLogger(__name__)
31 31
32
32 33 class RepositoryPermissionModel(BaseModel):
34
33 35 def get_user_permission(self, repository, user):
34 36 return UserRepoToPerm.query() \
35 37 .filter(UserRepoToPerm.user == user) \
@@ -47,14 +49,14 b' class RepositoryPermissionModel(BaseMode'
47 49 p.user = user
48 50 p.repository = repository
49 51 p.permission = permission
50 Session.add(p)
51 Session.commit()
52 self.sa.add(p)
53 self.sa.commit()
52 54
53 55 def delete_user_permission(self, repository, user):
54 56 current = self.get_user_permission(repository, user)
55 57 if current:
56 Session.delete(current)
57 Session.commit()
58 self.sa.delete(current)
59 self.sa.commit()
58 60
59 61 def update_or_delete_user_permission(self, repository, user, permission):
60 62 if permission:
@@ -27,8 +27,6 b' import time'
27 27 import traceback
28 28 import logging
29 29
30 from sqlalchemy.exc import DatabaseError
31
32 30 from vcs import get_backend
33 31 from vcs.exceptions import RepositoryError
34 32 from vcs.utils.lazy import LazyProperty
@@ -119,12 +117,14 b' class CachedRepoList(object):'
119 117 yield tmp_d
120 118
121 119 class ScmModel(BaseModel):
122 """Generic Scm Model
120 """
121 Generic Scm Model
123 122 """
124 123
125 124 @LazyProperty
126 125 def repos_path(self):
127 """Get's the repositories root path from database
126 """
127 Get's the repositories root path from database
128 128 """
129 129
130 130 q = self.sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one()
@@ -132,7 +132,8 b' class ScmModel(BaseModel):'
132 132 return q.ui_value
133 133
134 134 def repo_scan(self, repos_path=None):
135 """Listing of repositories in given path. This path should not be a
135 """
136 Listing of repositories in given path. This path should not be a
136 137 repository itself. Return a dictionary of repository objects
137 138
138 139 :param repos_path: path to directory containing repositories
@@ -147,11 +148,11 b' class ScmModel(BaseModel):'
147 148 repos_list = {}
148 149
149 150 for name, path in get_filesystem_repos(repos_path, recursive=True):
150
151
151 152 # name need to be decomposed and put back together using the /
152 153 # since this is internal storage separator for rhodecode
153 154 name = Repository.url_sep().join(name.split(os.sep))
154
155
155 156 try:
156 157 if name in repos_list:
157 158 raise RepositoryError('Duplicate repository name %s '
@@ -198,7 +199,7 b' class ScmModel(BaseModel):'
198 199 :param repo_name: this repo that should invalidation take place
199 200 """
200 201 CacheInvalidation.set_invalidate(repo_name)
201 CacheInvalidation.set_invalidate(repo_name+"_README")
202 CacheInvalidation.set_invalidate(repo_name + "_README")
202 203
203 204 def toggle_following_repo(self, follow_repo_id, user_id):
204 205
@@ -50,6 +50,7 b" PERM_WEIGHTS = {'repository.none': 0,"
50 50
51 51
52 52 class UserModel(BaseModel):
53
53 54 def get(self, user_id, cache=False):
54 55 user = self.sa.query(User)
55 56 if cache:
@@ -26,22 +26,21 b''
26 26 import logging
27 27 import traceback
28 28
29 from rhodecode.lib.caching_query import FromCache
30
31 29 from rhodecode.model import BaseModel
32 30 from rhodecode.model.db import UsersGroupMember, UsersGroup
33 31
34 32 log = logging.getLogger(__name__)
35 33
34
36 35 class UsersGroupModel(BaseModel):
37 36
38 37 def __get_users_group(self, users_group):
39 return self.__get_instance(UsersGroup, users_group)
38 return self._get_instance(UsersGroup, users_group)
40 39
41 def get(self, users_group_id, cache = False):
40 def get(self, users_group_id, cache=False):
42 41 return UsersGroup.get(users_group_id)
43 42
44 def get_by_name(self, name, cache = False, case_insensitive = False):
43 def get_by_name(self, name, cache=False, case_insensitive=False):
45 44 return UsersGroup.get_by_group_name(name, cache, case_insensitive)
46 45
47 46 def create(self, form_data):
General Comments 0
You need to be logged in to leave comments. Login now