# HG changeset patch # User Marcin Kuzminski # Date 1359242329 -3600 # Node ID f5dd76e2a7af3769c7bc05ab364adf3810b71148 # Parent 48b176df890c694dcda2a7a6dc47573d2d76ca63 disable file editing when not on branch head fixes issue #462 diff -r 48b176df890c -r f5dd76e2a7af rhodecode/controllers/files.py --- a/rhodecode/controllers/files.py Sat Jan 26 23:18:51 2013 +0100 +++ b/rhodecode/controllers/files.py Sun Jan 27 00:18:49 2013 +0100 @@ -128,6 +128,7 @@ c.branch = request.GET.get('branch', None) c.f_path = f_path c.annotate = annotate + c.changeset = self.__get_cs_or_redirect(revision, repo_name) cur_rev = c.changeset.revision # prev link @@ -160,6 +161,9 @@ c.file_changeset = (c.changeset if c.changeset.revision < file_last_cs.revision else file_last_cs) + #determine if we're on branch head + _branches = c.rhodecode_repo.branches + c.on_branch_head = revision in _branches.keys() + _branches.values() _hist = [] c.file_history = [] if c.load_full_history: @@ -260,7 +264,7 @@ @LoginRequired() @HasRepoPermissionAnyDecorator('repository.write', 'repository.admin') def edit(self, repo_name, revision, f_path): - repo = Repository.get_by_repo_name(repo_name) + repo = c.rhodecode_db_repo if repo.enable_locking and repo.locked[0]: h.flash(_('This repository is has been locked by %s on %s') % (h.person_by_id(repo.locked[0]), @@ -269,6 +273,17 @@ return redirect(h.url('files_home', repo_name=repo_name, revision='tip')) + # check if revision is a branch identifier- basically we cannot + # create multiple heads via file editing + _branches = repo.scm_instance.branches + # check if revision is a branch name or branch hash + if revision not in _branches.keys() + _branches.values(): + h.flash(_('You can only edit files with revision ' + 'being a valid branch '), category='warning') + return redirect(h.url('files_home', + repo_name=repo_name, revision='tip', + f_path=f_path)) + r_post = request.POST c.cs = self.__get_cs_or_redirect(revision, repo_name) @@ -277,7 +292,7 @@ if c.file.is_binary: return redirect(url('files_home', repo_name=c.repo_name, revision=c.cs.raw_id, f_path=f_path)) - + c.default_message = _('Edited file %s via RhodeCode') % (f_path) c.f_path = f_path if r_post: @@ -289,8 +304,7 @@ mode = detect_mode(first_line, 0) content = convert_line_endings(r_post.get('content'), mode) - message = r_post.get('message') or (_('Edited %s via RhodeCode') - % (f_path)) + message = r_post.get('message') or c.default_message author = self.rhodecode_user.full_contact if content == old_content: @@ -298,7 +312,6 @@ category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, revision='tip')) - try: self.scm_model.commit_change(repo=c.rhodecode_repo, repo_name=repo_name, cs=c.cs, @@ -334,15 +347,14 @@ redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) - + c.default_message = (_('Added file via RhodeCode')) c.f_path = f_path if r_post: unix_mode = 0 content = convert_line_endings(r_post.get('content'), unix_mode) - message = r_post.get('message') or (_('Added %s via RhodeCode') - % (f_path)) + message = r_post.get('message') or c.default_message location = r_post.get('location') filename = r_post.get('filename') file_obj = r_post.get('upload_file', None) diff -r 48b176df890c -r f5dd76e2a7af rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css Sat Jan 26 23:18:51 2013 +0100 +++ b/rhodecode/public/css/style.css Sun Jan 27 00:18:49 2013 +0100 @@ -3544,6 +3544,11 @@ background-position: 0 -15px; } + +.ui-btn.disabled{ + color: #999; +} + .ui-btn.xsmall{ padding: 1px 2px 1px 1px; } @@ -3568,12 +3573,19 @@ outline: none; } .ui-btn:hover{ - background-position: 0 0px; + background-position: 0 -15px; text-decoration: none; color: #515151; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 0 3px #FFFFFF !important; } +.ui-btn.disabled:hover{ + background-position:none; + color: #999; + text-decoration: none; + box-shadow: none !important; +} + .ui-btn.red{ color:#fff; background-color: #c43c35; diff -r 48b176df890c -r f5dd76e2a7af rhodecode/templates/files/files_add.html --- a/rhodecode/templates/files/files_add.html Sat Jan 26 23:18:51 2013 +0100 +++ b/rhodecode/templates/files/files_add.html Sun Jan 27 00:18:49 2013 +0100 @@ -75,7 +75,7 @@
${_('commit message')}
- +
${h.submit('commit',_('Commit changes'),class_="ui-btn")} diff -r 48b176df890c -r f5dd76e2a7af rhodecode/templates/files/files_edit.html --- a/rhodecode/templates/files/files_edit.html Sat Jan 26 23:18:51 2013 +0100 +++ b/rhodecode/templates/files/files_edit.html Sun Jan 27 00:18:49 2013 +0100 @@ -61,7 +61,7 @@

                 
                 
${_('commit message')}
- +
${h.submit('commit',_('Commit changes'),class_="ui-btn")} diff -r 48b176df890c -r f5dd76e2a7af rhodecode/templates/files/files_source.html --- a/rhodecode/templates/files/files_source.html Sat Jan 26 23:18:51 2013 +0100 +++ b/rhodecode/templates/files/files_source.html Sun Jan 27 00:18:49 2013 +0100 @@ -25,8 +25,10 @@ ${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")} ${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")} % if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name): - % if not c.file.is_binary: - ${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")} + % if c.on_branch_head and c.file.is_binary is False: + ${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")} + %else: + ${h.link_to(_('edit on branch:?'), '#', class_="ui-btn disabled tooltip", title=_('Editing files allowed only when on branch head revision'))} % endif % endif