Commit 3b6f8309 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'developer-can-push-wiki' into 'master'

Developer can push wiki

Fixes #1630

See merge request !1159
parents 51ed8b7e 06c91aa2
...@@ -14,13 +14,20 @@ module API ...@@ -14,13 +14,20 @@ module API
# #
post "/allowed" do post "/allowed" do
status 200 status 200
project_path = params[:project]
# Check for *.wiki repositories. # Check for *.wiki repositories.
# Strip out the .wiki from the pathname before finding the # Strip out the .wiki from the pathname before finding the
# project. This applies the correct project permissions to # project. This applies the correct project permissions to
# the wiki repository as well. # the wiki repository as well.
project_path = params[:project] access =
project_path.gsub!(/\.wiki/,'') if project_path =~ /\.wiki/ if project_path =~ /\.wiki\Z/
project_path.sub!(/\.wiki\Z/, '')
Gitlab::GitAccessWiki.new
else
Gitlab::GitAccess.new
end
project = Project.find_with_namespace(project_path) project = Project.find_with_namespace(project_path)
return false unless project return false unless project
...@@ -32,7 +39,7 @@ module API ...@@ -32,7 +39,7 @@ module API
return false unless actor return false unless actor
Gitlab::GitAccess.new.allowed?( access.allowed?(
actor, actor,
params[:action], params[:action],
project, project,
......
...@@ -49,6 +49,17 @@ module Gitlab ...@@ -49,6 +49,17 @@ module Gitlab
# Iterate over all changes to find if user allowed all of them to be applied # Iterate over all changes to find if user allowed all of them to be applied
changes.each do |change| changes.each do |change|
unless change_allowed?(user, project, change)
# If user does not have access to make at least one change - cancel all push
return false
end
end
# If user has access to make all changes
true
end
def change_allowed?(user, project, change)
oldrev, newrev, ref = change.split(' ') oldrev, newrev, ref = change.split(' ')
action = if project.protected_branch?(branch_name(ref)) action = if project.protected_branch?(branch_name(ref))
...@@ -67,14 +78,8 @@ module Gitlab ...@@ -67,14 +78,8 @@ module Gitlab
else else
:push_code :push_code
end end
unless user.can?(action, project)
# If user does not have access to make at least one change - cancel all push
return false
end
end
# If user has access to make all changes user.can?(action, project)
true
end end
def forced_push?(project, oldrev, newrev) def forced_push?(project, oldrev, newrev)
......
module Gitlab
class GitAccessWiki < GitAccess
def change_allowed?(user, project, change)
user.can?(:write_wiki, project)
end
end
end
require 'spec_helper'
describe Gitlab::GitAccessWiki do
let(:access) { Gitlab::GitAccessWiki.new }
let(:project) { create(:project) }
let(:user) { create(:user) }
describe 'push_allowed?' do
before do
create(:protected_branch, name: 'master', project: project)
project.team << [user, :developer]
end
subject { access.push_allowed?(user, project, changes) }
it { should be_true }
end
def changes
['6f6d7e7ed 570e7b2ab refs/heads/master']
end
end
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