Merge pull request #68 from warpc/build_list_visibilities
Customize build list monitoring: * show all user public build list * show private build list only who have access for project * admin see all build list
This commit is contained in:
commit
cb91bdb858
|
@ -13,11 +13,11 @@ class BuildListsController < ApplicationController
|
|||
def all
|
||||
if params[:filter]
|
||||
@filter = BuildList::Filter.new(nil, params[:filter])
|
||||
@build_lists = @filter.find.paginate :page => params[:page]
|
||||
else
|
||||
@filter = BuildList::Filter.new(nil)
|
||||
@build_lists = BuildList.recent.paginate :page => params[:page]
|
||||
end
|
||||
@build_lists = @filter.find.accessible_by(current_ability).paginate :page => params[:page]
|
||||
|
||||
@action_url = all_build_lists_path
|
||||
|
||||
@build_server_status = begin
|
||||
|
|
|
@ -24,6 +24,7 @@ class Ability
|
|||
# Registered user rights
|
||||
else
|
||||
can [:read, :platforms], Category
|
||||
can :all, BuildList
|
||||
|
||||
can :create, AutoBuildList
|
||||
can [:index, :destroy], AutoBuildList, :project_id => user.own_project_ids
|
||||
|
@ -45,9 +46,13 @@ class Ability
|
|||
can :publish, BuildList do |build_list|
|
||||
build_list.can_published? && build_list.project.relations.exists?(:object_type => 'User', :object_id => user.id)
|
||||
end
|
||||
can :read, BuildList do |build_list|
|
||||
build_list.project.public? || build_list.project.relations.exists?(:object_type => 'User', :object_id => user.id)
|
||||
can :read, BuildList, ["build_lists.project_id IN (SELECT id FROM projects WHERE visibility = ?)", 'open'] do |build_list|
|
||||
build_list.project.public?
|
||||
end
|
||||
can :read, BuildList, build_lists_in_relations_with(:object_type => 'User', :object_id => user.id) do |build_list|
|
||||
build_list.project.relations.exists?(:object_type => 'User', :object_id => user.id)
|
||||
end
|
||||
|
||||
can [:read, :create], PrivateUser, :platform => {:owner_type => 'User', :owner_id => user.id}
|
||||
|
||||
# If rule has multiple conditions CanCan joins them by 'AND' sql operator
|
||||
|
@ -104,8 +109,8 @@ class Ability
|
|||
can :publish, BuildList do |build_list|
|
||||
build_list.can_published? && build_list.project.relations.exists?(:object_type => 'Group', :object_id => user.group_ids)
|
||||
end
|
||||
can :read, BuildList do |build_list|
|
||||
build_list.project.public? || build_list.project.relations.exists?(:object_type => 'Group', :object_id => user.group_ids)
|
||||
can :read, BuildList, build_lists_in_relations_with(:object_type => 'Group', :object_id => user.group_ids) do |build_list|
|
||||
build_list.project.relations.exists?(:object_type => 'Group', :object_id => user.group_ids)
|
||||
end
|
||||
|
||||
can :manage_collaborators, Project, projects_in_relations_with(:role => 'admin', :object_type => 'Group', :object_id => user.group_ids) do |project|
|
||||
|
@ -161,6 +166,16 @@ class Ability
|
|||
end
|
||||
end
|
||||
|
||||
def build_lists_in_relations_with(opts)
|
||||
query = "build_lists.project_id IN (SELECT target_id FROM relations WHERE relations.target_type = 'Project'"
|
||||
opts.each do |key, value|
|
||||
query = query + " AND relations.#{ key } #{ value.class == Array ? 'IN (?)' : '= ?' } "
|
||||
end
|
||||
query = query + ")"
|
||||
|
||||
return opts.values.unshift query
|
||||
end
|
||||
|
||||
## Sub query for project relations
|
||||
#def projects_in_relations_with(opts={})
|
||||
# ["projects.id IN (SELECT target_id FROM relations WHERE relations.object_id #{ opts[:object_id].class == Array ? 'IN (?)' : '= ?' } AND relations.object_type = '#{ opts[:object_type] }' AND relations.target_type = 'Platform') AND relations.role", opts[:object_id]]
|
||||
|
|
|
@ -47,4 +47,4 @@
|
|||
.group.navform.wat-cf
|
||||
%button.button{ :type => "submit" }
|
||||
= image_tag("web-app-theme/icons/tick.png", :alt => "Save")
|
||||
= t("layout.search")
|
||||
= t("layout.search")
|
||||
|
|
|
@ -37,11 +37,31 @@ describe BuildListsController do
|
|||
@user = Factory(:user)
|
||||
set_session_for(@user)
|
||||
@show_params = {:project_id => @project.id, :id => @build_list.id}
|
||||
|
||||
end
|
||||
|
||||
it 'should not be able to perform all action' do
|
||||
get :all
|
||||
response.should redirect_to(forbidden_url)
|
||||
context 'for all build lists' do
|
||||
before(:each) do
|
||||
@build_list1 = Factory(:build_list_core)
|
||||
@build_list2 = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
|
||||
@build_list3 = Factory(:build_list_core, :project => Factory(:project, :owner => @user, :visibility => 'hidden'))
|
||||
b = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
|
||||
b.project.relations.create :role => 'reader', :object_id => @user.id, :object_type => 'User'
|
||||
@build_list4 = b
|
||||
end
|
||||
|
||||
it 'should be able to perform all action' do
|
||||
get :all
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'should show only accessible build_lists' do
|
||||
get :all
|
||||
assigns(:build_lists).should include(@build_list1)
|
||||
assigns(:build_lists).should_not include(@build_list2)
|
||||
assigns(:build_lists).should include(@build_list3)
|
||||
assigns(:build_lists).should include(@build_list4)
|
||||
end
|
||||
end
|
||||
|
||||
context 'for open project' do
|
||||
|
@ -52,7 +72,7 @@ describe BuildListsController do
|
|||
it_should_behave_like 'show build list'
|
||||
end
|
||||
|
||||
context 'if user is project owner' do
|
||||
context 'if user is project member' do
|
||||
before(:each) {set_session_for(@member_user)}
|
||||
it_should_behave_like 'show build list'
|
||||
end
|
||||
|
@ -71,7 +91,89 @@ describe BuildListsController do
|
|||
it_should_behave_like 'show build list'
|
||||
end
|
||||
|
||||
context 'if user is project owner' do
|
||||
context 'if user is project member' do
|
||||
before(:each) {set_session_for(@member_user)}
|
||||
it_should_behave_like 'show build list'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'for group' do
|
||||
before(:each) do
|
||||
stub_rsync_methods
|
||||
@owner_group = Factory(:group)
|
||||
@owner_user = Factory(:user)
|
||||
@owner_group.objects.create :role => 'reader', :object_id => @owner_user.id, :object_type => 'User'
|
||||
@member_group = Factory(:group)
|
||||
@member_user = Factory(:user)
|
||||
@member_group.objects.create :role => 'reader', :object_id => @member_user.id, :object_type => 'User'
|
||||
|
||||
@group = Factory(:group)
|
||||
@user = Factory(:user)
|
||||
@group.objects.create :role => 'reader', :object_id => @user.id, :object_type => 'User'
|
||||
|
||||
@project = Factory(:project, :owner => @owner_group)
|
||||
@project.relations.create :role => 'reader', :object_id => @member_group.id, :object_type => 'Group'
|
||||
|
||||
@build_list = Factory(:build_list_core, :project => @project)
|
||||
|
||||
set_session_for(@user)
|
||||
@show_params = {:project_id => @project.id, :id => @build_list.id}
|
||||
end
|
||||
|
||||
context 'for all build lists' do
|
||||
before(:each) do
|
||||
@build_list1 = Factory(:build_list_core)
|
||||
@build_list2 = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
|
||||
@build_list3 = Factory(:build_list_core, :project => Factory(:project, :owner => @group, :visibility => 'hidden'))
|
||||
b = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
|
||||
b.project.relations.create :role => 'reader', :object_id => @group.id, :object_type => 'Group'
|
||||
@build_list4 = b
|
||||
end
|
||||
|
||||
it 'should be able to perform all action' do
|
||||
get :all
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'should show only accessible build_lists' do
|
||||
get :all
|
||||
assigns(:build_lists).should include(@build_list1)
|
||||
assigns(:build_lists).should_not include(@build_list2)
|
||||
assigns(:build_lists).should include(@build_list3)
|
||||
assigns(:build_lists).should include(@build_list4)
|
||||
end
|
||||
end
|
||||
|
||||
context 'for open project' do
|
||||
it_should_behave_like 'show build list'
|
||||
|
||||
context 'if user is group owner' do
|
||||
before(:each) {set_session_for(@owner_user)}
|
||||
it_should_behave_like 'show build list'
|
||||
end
|
||||
|
||||
context 'if user is group member' do
|
||||
before(:each) {set_session_for(@member_user)}
|
||||
it_should_behave_like 'show build list'
|
||||
end
|
||||
end
|
||||
|
||||
context 'for hidden project' do
|
||||
before(:each) do
|
||||
@project.visibility = 'hidden'
|
||||
@project.save
|
||||
end
|
||||
|
||||
it_should_behave_like 'not show build list'
|
||||
|
||||
context 'if user is group owner' do
|
||||
before(:each) {set_session_for(@owner_user)}
|
||||
it_should_behave_like 'show build list'
|
||||
end
|
||||
|
||||
context 'if user is group member' do
|
||||
before(:each) {set_session_for(@member_user)}
|
||||
it_should_behave_like 'show build list'
|
||||
end
|
||||
|
@ -100,46 +202,39 @@ describe BuildListsController do
|
|||
before(:each) do
|
||||
stub_rsync_methods
|
||||
set_session_for Factory(:admin)
|
||||
end
|
||||
|
||||
let(:build_list1) { Factory(:build_list_core) }
|
||||
let(:build_list2) { Factory(:build_list_core) }
|
||||
let(:build_list3) { Factory(:build_list_core) }
|
||||
let(:build_list4) do
|
||||
b = Factory(:build_list_core)
|
||||
b.created_at = b.created_at - 1.day
|
||||
b.project = build_list3.project
|
||||
b.pl = build_list3.pl
|
||||
b.arch = build_list3.arch
|
||||
b.save
|
||||
b
|
||||
|
||||
@build_list1 = Factory(:build_list_core)
|
||||
@build_list2 = Factory(:build_list_core)
|
||||
@build_list3 = Factory(:build_list_core)
|
||||
@build_list4 = Factory(:build_list_core, :created_at => (Time.now - 1.day),
|
||||
:project => @build_list3.project, :pl => @build_list3.pl,
|
||||
:arch => @build_list3.arch)
|
||||
end
|
||||
before(:each) { set_session_for Factory(:admin); stub_rsync_methods; }
|
||||
|
||||
it 'should filter by bs_id' do
|
||||
get :all, :filter => {:bs_id => build_list1.bs_id, :project_name => 'fdsfdf', :any_other_field => 'do not matter'}
|
||||
assigns[:build_lists].should include(build_list1)
|
||||
assigns[:build_lists].should_not include(build_list2)
|
||||
assigns[:build_lists].should_not include(build_list3)
|
||||
get :all, :filter => {:bs_id => @build_list1.bs_id, :project_name => 'fdsfdf', :any_other_field => 'do not matter'}
|
||||
assigns[:build_lists].should include(@build_list1)
|
||||
assigns[:build_lists].should_not include(@build_list2)
|
||||
assigns[:build_lists].should_not include(@build_list3)
|
||||
end
|
||||
|
||||
it 'should filter by project_name' do
|
||||
# Project.where(:id => build_list2.project.id).update_all(:name => 'project_name')
|
||||
get :all, :filter => {:project_name => build_list2.project.name}
|
||||
assigns[:build_lists].should_not include(build_list1)
|
||||
assigns[:build_lists].should include(build_list2)
|
||||
assigns[:build_lists].should_not include(build_list3)
|
||||
get :all, :filter => {:project_name => @build_list2.project.name}
|
||||
assigns[:build_lists].should_not include(@build_list1)
|
||||
assigns[:build_lists].should include(@build_list2)
|
||||
assigns[:build_lists].should_not include(@build_list3)
|
||||
end
|
||||
|
||||
it 'should filter by project_name and start_date' do
|
||||
get :all, :filter => {:project_name => build_list3.project.name,
|
||||
"created_at_start(1i)"=>build_list3.created_at.year.to_s,
|
||||
"created_at_start(2i)"=>build_list3.created_at.month.to_s,
|
||||
"created_at_start(3i)"=>build_list3.created_at.day.to_s}
|
||||
assigns[:build_lists].should_not include(build_list1)
|
||||
assigns[:build_lists].should_not include(build_list2)
|
||||
assigns[:build_lists].should include(build_list3)
|
||||
assigns[:build_lists].should_not include(build_list4)
|
||||
get :all, :filter => {:project_name => @build_list3.project.name,
|
||||
"created_at_start(1i)" => @build_list3.created_at.year.to_s,
|
||||
"created_at_start(2i)" => @build_list3.created_at.month.to_s,
|
||||
"created_at_start(3i)" => @build_list3.created_at.day.to_s}
|
||||
assigns[:build_lists].should_not include(@build_list1)
|
||||
assigns[:build_lists].should_not include(@build_list2)
|
||||
assigns[:build_lists].should include(@build_list3)
|
||||
assigns[:build_lists].should_not include(@build_list4)
|
||||
# response.should be_success
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue