summaryrefslogtreecommitdiff
path: root/app/contexts
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-11-05 12:21:11 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-11-05 12:21:11 +0200
commit160bd862bede180faf66de7e5b09300347c24279 (patch)
treee5b758ddd4f221938d17a4de39fb1aad6d6406b1 /app/contexts
parentf61850e6e3521073f49f1cfe429b7fe49f3b44f0 (diff)
downloadgitlab-ce-160bd862bede180faf66de7e5b09300347c24279.tar.gz
Refactoring for EditTree and NewTree controllers and contexts
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/contexts')
-rw-r--r--app/contexts/files/update_context.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/app/contexts/files/update_context.rb b/app/contexts/files/update_context.rb
new file mode 100644
index 00000000000..000d3d02f12
--- /dev/null
+++ b/app/contexts/files/update_context.rb
@@ -0,0 +1,38 @@
+module Files
+ class UpdateContext < BaseContext
+ def execute
+ allowed = if project.protected_branch?(ref)
+ can?(current_user, :push_code_to_protected_branches, project)
+ else
+ can?(current_user, :push_code, project)
+ end
+
+ unless allowed
+ return error("You are not allowed to push into this branch")
+ end
+
+ unless repository.branch_names.include?(ref)
+ return error("You can only create files if you are on top of a branch")
+ end
+
+ blob = repository.blob_at(ref, path)
+
+ unless blob
+ return error("You can only edit text files")
+ end
+
+ new_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path)
+ created_successfully = new_file_action.commit!(
+ params[:content],
+ params[:commit_message],
+ params[:last_commit]
+ )
+
+ if created_successfully
+ success
+ else
+ error("Your changes could not be commited, because the file has been changed")
+ end
+ end
+ end
+end