Commit 0b3e9fd2189753ae4007b53c2c588fca741738ef

Authored by Valeriy Sizov
1 parent e53b47b4

WebEditor: Check if save is possible

app/controllers/tree_controller.rb
... ... @@ -25,9 +25,8 @@ class TreeController < ProjectResourceController
25 25 end
26 26  
27 27 def update
28   - last_commit = @project.commits(@ref, @path, 1).first.sha
29   - file_editor = Gitlab::FileEditor.new(current_user, @project)
30   - if file_editor.can_edit?(@path, last_commit)
  28 + file_editor = Gitlab::FileEditor.new(current_user, @project, @ref)
  29 + if file_editor.can_edit?(@path, params[:last_commit])
31 30 file_editor.update(@path, params[:content])
32 31 redirect_to project_tree_path(@project, @id), :notice => "File has been successfully changed"
33 32 else
... ...
lib/gitlab/file_editor.rb
1 1 module Gitlab
2 2 class FileEditor
3 3  
4   - attr_accessor :user, :project
  4 + attr_accessor :user, :project, :ref
5 5  
6   - def initialize(user, project)
  6 + def initialize(user, project, ref)
7 7 self.user = user
8 8 self.project = project
  9 + self.ref = ref
9 10 end
10 11  
11 12 def can_edit?(path, last_commit)
12   - true
  13 + current_last_commit = @project.commits(ref, path, 1).first.sha
  14 + last_commit == current_last_commit
13 15 end
14 16  
15 17 def update(path, content)
... ...