Commit 0b3e9fd2 authored by Valeriy Sizov's avatar Valeriy Sizov

WebEditor: Check if save is possible

parent e53b47b4
...@@ -25,9 +25,8 @@ class TreeController < ProjectResourceController ...@@ -25,9 +25,8 @@ class TreeController < ProjectResourceController
end end
def update def update
last_commit = @project.commits(@ref, @path, 1).first.sha file_editor = Gitlab::FileEditor.new(current_user, @project, @ref)
file_editor = Gitlab::FileEditor.new(current_user, @project) if file_editor.can_edit?(@path, params[:last_commit])
if file_editor.can_edit?(@path, last_commit)
file_editor.update(@path, params[:content]) file_editor.update(@path, params[:content])
redirect_to project_tree_path(@project, @id), :notice => "File has been successfully changed" redirect_to project_tree_path(@project, @id), :notice => "File has been successfully changed"
else else
......
module Gitlab module Gitlab
class FileEditor class FileEditor
attr_accessor :user, :project attr_accessor :user, :project, :ref
def initialize(user, project) def initialize(user, project, ref)
self.user = user self.user = user
self.project = project self.project = project
self.ref = ref
end end
def can_edit?(path, last_commit) def can_edit?(path, last_commit)
true current_last_commit = @project.commits(ref, path, 1).first.sha
last_commit == current_last_commit
end end
def update(path, content) def update(path, content)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment