##// 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 c.branch = request.GET.get('branch', None)
128 c.branch = request.GET.get('branch', None)
129 c.f_path = f_path
129 c.f_path = f_path
130 c.annotate = annotate
130 c.annotate = annotate
131 c.changeset = self.__get_cs_or_redirect(revision, repo_name)
131 cur_rev = c.changeset.revision
132 cur_rev = c.changeset.revision
132
133
133 # prev link
134 # prev link
@@ -160,6 +161,9 b' class FilesController(BaseRepoController'
160 c.file_changeset = (c.changeset
161 c.file_changeset = (c.changeset
161 if c.changeset.revision < file_last_cs.revision
162 if c.changeset.revision < file_last_cs.revision
162 else file_last_cs)
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 _hist = []
167 _hist = []
164 c.file_history = []
168 c.file_history = []
165 if c.load_full_history:
169 if c.load_full_history:
@@ -260,7 +264,7 b' class FilesController(BaseRepoController'
260 @LoginRequired()
264 @LoginRequired()
261 @HasRepoPermissionAnyDecorator('repository.write', 'repository.admin')
265 @HasRepoPermissionAnyDecorator('repository.write', 'repository.admin')
262 def edit(self, repo_name, revision, f_path):
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 if repo.enable_locking and repo.locked[0]:
268 if repo.enable_locking and repo.locked[0]:
265 h.flash(_('This repository is has been locked by %s on %s')
269 h.flash(_('This repository is has been locked by %s on %s')
266 % (h.person_by_id(repo.locked[0]),
270 % (h.person_by_id(repo.locked[0]),
@@ -269,6 +273,17 b' class FilesController(BaseRepoController'
269 return redirect(h.url('files_home',
273 return redirect(h.url('files_home',
270 repo_name=repo_name, revision='tip'))
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 r_post = request.POST
287 r_post = request.POST
273
288
274 c.cs = self.__get_cs_or_redirect(revision, repo_name)
289 c.cs = self.__get_cs_or_redirect(revision, repo_name)
@@ -277,7 +292,7 b' class FilesController(BaseRepoController'
277 if c.file.is_binary:
292 if c.file.is_binary:
278 return redirect(url('files_home', repo_name=c.repo_name,
293 return redirect(url('files_home', repo_name=c.repo_name,
279 revision=c.cs.raw_id, f_path=f_path))
294 revision=c.cs.raw_id, f_path=f_path))
280
295 c.default_message = _('Edited file %s via RhodeCode') % (f_path)
281 c.f_path = f_path
296 c.f_path = f_path
282
297
283 if r_post:
298 if r_post:
@@ -289,8 +304,7 b' class FilesController(BaseRepoController'
289 mode = detect_mode(first_line, 0)
304 mode = detect_mode(first_line, 0)
290 content = convert_line_endings(r_post.get('content'), mode)
305 content = convert_line_endings(r_post.get('content'), mode)
291
306
292 message = r_post.get('message') or (_('Edited %s via RhodeCode')
307 message = r_post.get('message') or c.default_message
293 % (f_path))
294 author = self.rhodecode_user.full_contact
308 author = self.rhodecode_user.full_contact
295
309
296 if content == old_content:
310 if content == old_content:
@@ -298,7 +312,6 b' class FilesController(BaseRepoController'
298 category='warning')
312 category='warning')
299 return redirect(url('changeset_home', repo_name=c.repo_name,
313 return redirect(url('changeset_home', repo_name=c.repo_name,
300 revision='tip'))
314 revision='tip'))
301
302 try:
315 try:
303 self.scm_model.commit_change(repo=c.rhodecode_repo,
316 self.scm_model.commit_change(repo=c.rhodecode_repo,
304 repo_name=repo_name, cs=c.cs,
317 repo_name=repo_name, cs=c.cs,
@@ -334,15 +347,14 b' class FilesController(BaseRepoController'
334 redirect_after=False)
347 redirect_after=False)
335 if c.cs is None:
348 if c.cs is None:
336 c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias)
349 c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias)
337
350 c.default_message = (_('Added file via RhodeCode'))
338 c.f_path = f_path
351 c.f_path = f_path
339
352
340 if r_post:
353 if r_post:
341 unix_mode = 0
354 unix_mode = 0
342 content = convert_line_endings(r_post.get('content'), unix_mode)
355 content = convert_line_endings(r_post.get('content'), unix_mode)
343
356
344 message = r_post.get('message') or (_('Added %s via RhodeCode')
357 message = r_post.get('message') or c.default_message
345 % (f_path))
346 location = r_post.get('location')
358 location = r_post.get('location')
347 filename = r_post.get('filename')
359 filename = r_post.get('filename')
348 file_obj = r_post.get('upload_file', None)
360 file_obj = r_post.get('upload_file', None)
@@ -3544,6 +3544,11 b' div.gravatar img {'
3544 background-position: 0 -15px;
3544 background-position: 0 -15px;
3545
3545
3546 }
3546 }
3547
3548 .ui-btn.disabled{
3549 color: #999;
3550 }
3551
3547 .ui-btn.xsmall{
3552 .ui-btn.xsmall{
3548 padding: 1px 2px 1px 1px;
3553 padding: 1px 2px 1px 1px;
3549 }
3554 }
@@ -3568,12 +3573,19 b' div.gravatar img {'
3568 outline: none;
3573 outline: none;
3569 }
3574 }
3570 .ui-btn:hover{
3575 .ui-btn:hover{
3571 background-position: 0 0px;
3576 background-position: 0 -15px;
3572 text-decoration: none;
3577 text-decoration: none;
3573 color: #515151;
3578 color: #515151;
3574 box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 0 3px #FFFFFF !important;
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 .ui-btn.red{
3589 .ui-btn.red{
3578 color:#fff;
3590 color:#fff;
3579 background-color: #c43c35;
3591 background-color: #c43c35;
@@ -75,7 +75,7 b''
75 <textarea id="editor" name="content" style="display:none"></textarea>
75 <textarea id="editor" name="content" style="display:none"></textarea>
76 </div>
76 </div>
77 <div style="padding: 10px;color:#666666">${_('commit message')}</div>
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 </div>
79 </div>
80 <div style="text-align: l;padding-top: 5px">
80 <div style="text-align: l;padding-top: 5px">
81 ${h.submit('commit',_('Commit changes'),class_="ui-btn")}
81 ${h.submit('commit',_('Commit changes'),class_="ui-btn")}
@@ -61,7 +61,7 b''
61 <pre id="editor_pre"></pre>
61 <pre id="editor_pre"></pre>
62 <textarea id="editor" name="content" style="display:none">${h.escape(c.file.content)|n}</textarea>
62 <textarea id="editor" name="content" style="display:none">${h.escape(c.file.content)|n}</textarea>
63 <div style="padding: 10px;color:#666666">${_('commit message')}</div>
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 </div>
65 </div>
66 <div style="text-align: left;padding-top: 5px">
66 <div style="text-align: left;padding-top: 5px">
67 ${h.submit('commit',_('Commit changes'),class_="ui-btn")}
67 ${h.submit('commit',_('Commit changes'),class_="ui-btn")}
@@ -25,8 +25,10 b''
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")}
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 ${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")}
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 % if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name):
27 % if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name):
28 % if not c.file.is_binary:
28 % if c.on_branch_head and c.file.is_binary is False:
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")}
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 % endif
32 % endif
31 % endif
33 % endif
32 </div>
34 </div>
General Comments 0
You need to be logged in to leave comments. Login now