##// END OF EJS Templates
disable file editing when not on branch head fixes issue #462
marcink -
r3237:f5dd76e2 beta
parent child Browse files
Show More
@@ -128,6 +128,7 b' class FilesController(BaseRepoController'
128 128 c.branch = request.GET.get('branch', None)
129 129 c.f_path = f_path
130 130 c.annotate = annotate
131 c.changeset = self.__get_cs_or_redirect(revision, repo_name)
131 132 cur_rev = c.changeset.revision
132 133
133 134 # prev link
@@ -160,6 +161,9 b' class FilesController(BaseRepoController'
160 161 c.file_changeset = (c.changeset
161 162 if c.changeset.revision < file_last_cs.revision
162 163 else file_last_cs)
164 #determine if we're on branch head
165 _branches = c.rhodecode_repo.branches
166 c.on_branch_head = revision in _branches.keys() + _branches.values()
163 167 _hist = []
164 168 c.file_history = []
165 169 if c.load_full_history:
@@ -260,7 +264,7 b' class FilesController(BaseRepoController'
260 264 @LoginRequired()
261 265 @HasRepoPermissionAnyDecorator('repository.write', 'repository.admin')
262 266 def edit(self, repo_name, revision, f_path):
263 repo = Repository.get_by_repo_name(repo_name)
267 repo = c.rhodecode_db_repo
264 268 if repo.enable_locking and repo.locked[0]:
265 269 h.flash(_('This repository is has been locked by %s on %s')
266 270 % (h.person_by_id(repo.locked[0]),
@@ -269,6 +273,17 b' class FilesController(BaseRepoController'
269 273 return redirect(h.url('files_home',
270 274 repo_name=repo_name, revision='tip'))
271 275
276 # check if revision is a branch identifier- basically we cannot
277 # create multiple heads via file editing
278 _branches = repo.scm_instance.branches
279 # check if revision is a branch name or branch hash
280 if revision not in _branches.keys() + _branches.values():
281 h.flash(_('You can only edit files with revision '
282 'being a valid branch '), category='warning')
283 return redirect(h.url('files_home',
284 repo_name=repo_name, revision='tip',
285 f_path=f_path))
286
272 287 r_post = request.POST
273 288
274 289 c.cs = self.__get_cs_or_redirect(revision, repo_name)
@@ -277,7 +292,7 b' class FilesController(BaseRepoController'
277 292 if c.file.is_binary:
278 293 return redirect(url('files_home', repo_name=c.repo_name,
279 294 revision=c.cs.raw_id, f_path=f_path))
280
295 c.default_message = _('Edited file %s via RhodeCode') % (f_path)
281 296 c.f_path = f_path
282 297
283 298 if r_post:
@@ -289,8 +304,7 b' class FilesController(BaseRepoController'
289 304 mode = detect_mode(first_line, 0)
290 305 content = convert_line_endings(r_post.get('content'), mode)
291 306
292 message = r_post.get('message') or (_('Edited %s via RhodeCode')
293 % (f_path))
307 message = r_post.get('message') or c.default_message
294 308 author = self.rhodecode_user.full_contact
295 309
296 310 if content == old_content:
@@ -298,7 +312,6 b' class FilesController(BaseRepoController'
298 312 category='warning')
299 313 return redirect(url('changeset_home', repo_name=c.repo_name,
300 314 revision='tip'))
301
302 315 try:
303 316 self.scm_model.commit_change(repo=c.rhodecode_repo,
304 317 repo_name=repo_name, cs=c.cs,
@@ -334,15 +347,14 b' class FilesController(BaseRepoController'
334 347 redirect_after=False)
335 348 if c.cs is None:
336 349 c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias)
337
350 c.default_message = (_('Added file via RhodeCode'))
338 351 c.f_path = f_path
339 352
340 353 if r_post:
341 354 unix_mode = 0
342 355 content = convert_line_endings(r_post.get('content'), unix_mode)
343 356
344 message = r_post.get('message') or (_('Added %s via RhodeCode')
345 % (f_path))
357 message = r_post.get('message') or c.default_message
346 358 location = r_post.get('location')
347 359 filename = r_post.get('filename')
348 360 file_obj = r_post.get('upload_file', None)
@@ -3544,6 +3544,11 b' div.gravatar img {'
3544 3544 background-position: 0 -15px;
3545 3545
3546 3546 }
3547
3548 .ui-btn.disabled{
3549 color: #999;
3550 }
3551
3547 3552 .ui-btn.xsmall{
3548 3553 padding: 1px 2px 1px 1px;
3549 3554 }
@@ -3568,12 +3573,19 b' div.gravatar img {'
3568 3573 outline: none;
3569 3574 }
3570 3575 .ui-btn:hover{
3571 background-position: 0 0px;
3576 background-position: 0 -15px;
3572 3577 text-decoration: none;
3573 3578 color: #515151;
3574 3579 box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 0 3px #FFFFFF !important;
3575 3580 }
3576 3581
3582 .ui-btn.disabled:hover{
3583 background-position:none;
3584 color: #999;
3585 text-decoration: none;
3586 box-shadow: none !important;
3587 }
3588
3577 3589 .ui-btn.red{
3578 3590 color:#fff;
3579 3591 background-color: #c43c35;
@@ -75,7 +75,7 b''
75 75 <textarea id="editor" name="content" style="display:none"></textarea>
76 76 </div>
77 77 <div style="padding: 10px;color:#666666">${_('commit message')}</div>
78 <textarea id="commit" name="message" style="height: 100px;width: 99%;margin-left:4px"></textarea>
78 <textarea id="commit" name="message" style="height: 100px;width: 99%;margin-left:4px" placeholder="${c.default_message}"></textarea>
79 79 </div>
80 80 <div style="text-align: l;padding-top: 5px">
81 81 ${h.submit('commit',_('Commit changes'),class_="ui-btn")}
@@ -61,7 +61,7 b''
61 61 <pre id="editor_pre"></pre>
62 62 <textarea id="editor" name="content" style="display:none">${h.escape(c.file.content)|n}</textarea>
63 63 <div style="padding: 10px;color:#666666">${_('commit message')}</div>
64 <textarea id="commit" name="message" style="height: 60px;width: 99%;margin-left:4px"></textarea>
64 <textarea id="commit" name="message" style="height: 60px;width: 99%;margin-left:4px" placeholder="${c.default_message}"></textarea>
65 65 </div>
66 66 <div style="text-align: left;padding-top: 5px">
67 67 ${h.submit('commit',_('Commit changes'),class_="ui-btn")}
@@ -25,8 +25,10 b''
25 25 ${h.link_to(_('show as raw'),h.url('files_raw_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")}
26 26 ${h.link_to(_('download as raw'),h.url('files_rawfile_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")}
27 27 % if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name):
28 % if not c.file.is_binary:
29 ${h.link_to(_('edit'),h.url('files_edit_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")}
28 % if c.on_branch_head and c.file.is_binary is False:
29 ${h.link_to(_('edit on branch:%s' % c.changeset.branch),h.url('files_edit_home',repo_name=c.repo_name,revision=c.changeset.branch,f_path=c.f_path),class_="ui-btn")}
30 %else:
31 ${h.link_to(_('edit on branch:?'), '#', class_="ui-btn disabled tooltip", title=_('Editing files allowed only when on branch head revision'))}
30 32 % endif
31 33 % endif
32 34 </div>
General Comments 0
You need to be logged in to leave comments. Login now