#373: rollback changes
This commit is contained in:
parent
55e8345b66
commit
35a2be81cf
|
@ -1,14 +1,14 @@
|
||||||
class Api::V1::PlatformsController < Api::V1::BaseController
|
class Api::V1::PlatformsController < Api::V1::BaseController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
skip_before_filter :authenticate_user!, only: :allowed
|
skip_before_filter :authenticate_user!, only: :allowed
|
||||||
skip_before_filter :authenticate_user!, only: %i(show platforms_for_build members cached_chroot) if APP_CONFIG['anonymous_access']
|
skip_before_filter :authenticate_user!, only: [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access']
|
||||||
before_filter :set_token, only: %i(allowed cached_chroot)
|
load_and_authorize_resource except: :allowed
|
||||||
|
|
||||||
load_and_authorize_resource except: %i(allowed cached_chroot)
|
|
||||||
load_resource only: :cached_chroot
|
|
||||||
|
|
||||||
def allowed
|
def allowed
|
||||||
if Platform.allowed?(params[:path] || '', @token)
|
if request.authorization.present?
|
||||||
|
token, pass = *ActionController::HttpAuthentication::Basic::user_name_and_password(request)
|
||||||
|
end
|
||||||
|
if Platform.allowed?(params[:path] || '', token)
|
||||||
render nothing: true
|
render nothing: true
|
||||||
else
|
else
|
||||||
render nothing: true, status: 403
|
render nothing: true, status: 403
|
||||||
|
@ -23,14 +23,6 @@ class Api::V1::PlatformsController < Api::V1::BaseController
|
||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
|
||||||
def cached_chroot
|
|
||||||
if sha1 = @platform.cached_chroot(@token, params[:arch])
|
|
||||||
redirect_to "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
|
|
||||||
else
|
|
||||||
render nothing: true, status: 403
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def platforms_for_build
|
def platforms_for_build
|
||||||
@platforms = Platform.main.opened.paginate(paginate_params)
|
@platforms = Platform.main.opened.paginate(paginate_params)
|
||||||
render :index
|
render :index
|
||||||
|
@ -82,12 +74,4 @@ class Api::V1::PlatformsController < Api::V1::BaseController
|
||||||
destroy_subject @platform
|
destroy_subject @platform
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def set_token
|
|
||||||
if request.authorization.present?
|
|
||||||
@token, pass = *ActionController::HttpAuthentication::Basic::user_name_and_password(request)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -513,15 +513,20 @@ class BuildList < ActiveRecord::Base
|
||||||
git_project_address = project.git_project_address user
|
git_project_address = project.git_project_address user
|
||||||
# git_project_address.gsub!(/^http:\/\/(0\.0\.0\.0|localhost)\:[\d]+/, 'https://abf.rosalinux.ru') unless Rails.env.production?
|
# git_project_address.gsub!(/^http:\/\/(0\.0\.0\.0|localhost)\:[\d]+/, 'https://abf.rosalinux.ru') unless Rails.env.production?
|
||||||
|
|
||||||
|
|
||||||
cmd_params = {
|
cmd_params = {
|
||||||
'GIT_PROJECT_ADDRESS' => git_project_address,
|
'GIT_PROJECT_ADDRESS' => git_project_address,
|
||||||
'COMMIT_HASH' => commit_hash,
|
'COMMIT_HASH' => commit_hash,
|
||||||
'USE_CACHED_CHROOT' => use_cached_chroot?,
|
|
||||||
'EXTRA_CFG_OPTIONS' => extra_params['cfg_options'],
|
'EXTRA_CFG_OPTIONS' => extra_params['cfg_options'],
|
||||||
'EXTRA_CFG_URPM_OPTIONS' => extra_params['cfg_urpm_options'],
|
'EXTRA_CFG_URPM_OPTIONS' => extra_params['cfg_urpm_options'],
|
||||||
'EXTRA_BUILD_SRC_RPM_OPTIONS' => extra_params['build_src_rpm'],
|
'EXTRA_BUILD_SRC_RPM_OPTIONS' => extra_params['build_src_rpm'],
|
||||||
'EXTRA_BUILD_RPM_OPTIONS' => extra_params['build_rpm']
|
'EXTRA_BUILD_RPM_OPTIONS' => extra_params['build_rpm']
|
||||||
}.map{ |k, v| "#{k}='#{v}'" }.join(' ')
|
}
|
||||||
|
if use_cached_chroot?
|
||||||
|
sha1 = build_for_platform.cached_chroot(arch.name)
|
||||||
|
cmd_params.merge!('CACHED_CHROOT_SHA1' => sha1) if sha1.present?
|
||||||
|
end
|
||||||
|
cmd_params = cmd_params.map{ |k, v| "#{k}='#{v}'" }.join(' ')
|
||||||
|
|
||||||
{
|
{
|
||||||
id: id,
|
id: id,
|
||||||
|
|
|
@ -223,30 +223,26 @@ class Platform < ActiveRecord::Base
|
||||||
platform = Platform.find_by name: platform_name
|
platform = Platform.find_by name: platform_name
|
||||||
next false unless platform
|
next false unless platform
|
||||||
next true unless platform.hidden?
|
next true unless platform.hidden?
|
||||||
platform.has_access?(token)
|
return false if token.blank?
|
||||||
|
return true if platform.tokens.by_active.where(authentication_token: token).exists?
|
||||||
|
user = User.find_by(authentication_token: token)
|
||||||
|
current_ability = Ability.new(user)
|
||||||
|
user && current_ability.can?(:show, platform) ? true : false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def cached_chroot(token, arch)
|
def cached_chroot(arch)
|
||||||
return false if personal?
|
return false if personal?
|
||||||
Rails.cache.fetch([:cached_chroot, token, name, arch], expires_in: 10.minutes) do
|
Rails.cache.fetch([:cached_chroot, name, arch], expires_in: 10.minutes) do
|
||||||
product = products.where(name: CACHED_CHROOT_PRODUCT_NAME).first
|
product = products.where(name: CACHED_CHROOT_PRODUCT_NAME).first
|
||||||
next false unless product
|
next false unless product
|
||||||
pbl = product.product_build_lists.for_status(ProductBuildList::BUILD_COMPLETED).recent.first
|
pbl = product.product_build_lists.for_status(ProductBuildList::BUILD_COMPLETED).recent.first
|
||||||
next false unless pbl
|
next false unless pbl
|
||||||
next false if hidden? && !has_access?(token)
|
result = pbl.results.results.find{ |r| r['file_name'] =~ /-#{arch}.tar.gz$/ }
|
||||||
pbl.results.results.find{ |r| r['file_name'] =~ /^cached-chroot-#{arch}/ } || false
|
result.present? ? result['sha1'] : false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_access?(token)
|
|
||||||
return false if token.blank?
|
|
||||||
return true if tokens.by_active.where(authentication_token: token).exists?
|
|
||||||
user = User.find_by(authentication_token: token)
|
|
||||||
current_ability = Ability.new(user)
|
|
||||||
user && current_ability.can?(:show, self) ? true : false
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.autostart_metadata_regeneration(value)
|
def self.autostart_metadata_regeneration(value)
|
||||||
Platform.main.where(automatic_metadata_regeneration: value).each(&:regenerate)
|
Platform.main.where(automatic_metadata_regeneration: value).each(&:regenerate)
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,13 +34,12 @@ Rosa::Application.routes.draw do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
resources :arches, only: :index
|
resources :arches, only: :index
|
||||||
resources :platforms, only: %i(index show update destroy create), constraints: { id: Platform::NAME_PATTERN } do
|
resources :platforms, only: %i(index show update destroy create) do
|
||||||
collection {
|
collection {
|
||||||
get :platforms_for_build
|
get :platforms_for_build
|
||||||
get :allowed
|
get :allowed
|
||||||
}
|
}
|
||||||
member {
|
member {
|
||||||
get :cached_chroot
|
|
||||||
get :members
|
get :members
|
||||||
put :add_member
|
put :add_member
|
||||||
delete :remove_member
|
delete :remove_member
|
||||||
|
|
|
@ -193,12 +193,6 @@ shared_examples_for 'api platform user without reader rights for hidden platform
|
||||||
response.body.should == {"message" => "Access violation to this page!"}.to_json
|
response.body.should == {"message" => "Access violation to this page!"}.to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be able to perform cached_chroot action" do
|
|
||||||
get :cached_chroot, id: @platform.id, format: :json
|
|
||||||
response.status.should == 403
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for "api platform user with show rights" do
|
shared_examples_for "api platform user with show rights" do
|
||||||
|
@ -207,13 +201,6 @@ shared_examples_for "api platform user with show rights" do
|
||||||
response.should render_template(:show)
|
response.should render_template(:show)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform cached_chroot action' do
|
|
||||||
Rails.stub_chain(:cache, :fetch).and_return('sha1')
|
|
||||||
http_login (@admin || @user).authentication_token, '' if @platform.hidden?
|
|
||||||
get :cached_chroot, id: @platform.id, format: :json
|
|
||||||
response.should redirect_to("#{APP_CONFIG['file_store_url']}/api/v1/file_stores/sha1")
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should be able to perform platforms_for_build action' do
|
it 'should be able to perform platforms_for_build action' do
|
||||||
get :platforms_for_build, format: :json
|
get :platforms_for_build, format: :json
|
||||||
response.should render_template(:index)
|
response.should render_template(:index)
|
||||||
|
|
Loading…
Reference in New Issue