Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

479 restrict standard user views #480

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def initialize(user)
can :manage, :all
when 'standard'
can :view_pdfs, ConservationRecord
can :crud, [ConservationRecord, ExternalRepairRecord, InHouseRepairRecord, ConTechRecord, StaffCode, CostReturnReport, Report, :activity]
can :crud, [ConservationRecord, ExternalRepairRecord, InHouseRepairRecord, ConTechRecord, StaffCode, CostReturnReport]
when 'read_only'
can :view_pdfs, ConservationRecord
can :read, ConservationRecord
Expand Down
12 changes: 4 additions & 8 deletions lib/tasks/export.rake
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ namespace :export do
end

# set headers for repeat fields
err_csv = []

def err_headings(ordinal)
["External Repair Record id #{ordinal + 1}",
"External Repair repair_type #{ordinal + 1}",
Expand All @@ -30,12 +28,10 @@ namespace :export do
"External Repair other_note #{ordinal + 1}"]
end

err.max.times.each do |ordinal|
err_csv.push err_headings(ordinal)
err_csv = err.max.times.map do |ordinal|
err_headings(ordinal)
end

ihrr_csv = []

def ihrr_headings(ordinal)
["In House Repair performed_by_user_id #{ordinal + 1}",
"In House Repair minutes_spent #{ordinal + 1}",
Expand All @@ -45,8 +41,8 @@ namespace :export do
"In House Repair staff_code #{ordinal + 1}"]
end

ihrr.max.times.each do |ordinal|
ihrr_csv.push ihrr_headings(ordinal)
ihrr_csv = ihrr.max.times.map do |ordinal|
ihrr_headings(ordinal)
end

staff_csv = []
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

before do
ActiveJob::Base.queue_adapter = :test
user = create(:user, role: 'standard')
user = create(:user, role: 'admin')
sign_in(user)
end

Expand Down
12 changes: 6 additions & 6 deletions spec/models/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@
it { is_expected.to be_able_to(:update, ConTechRecord.new) }
it { is_expected.to be_able_to(:destroy, ConTechRecord.new) }

it { is_expected.to be_able_to(:index, Report.new) }
it { is_expected.to be_able_to(:create, Report.new) }
it { is_expected.to be_able_to(:read, Report.new) }
it { is_expected.to be_able_to(:destroy, Report.new) }
it { is_expected.not_to be_able_to(:index, Report.new) }
it { is_expected.not_to be_able_to(:create, Report.new) }
it { is_expected.not_to be_able_to(:read, Report.new) }
it { is_expected.not_to be_able_to(:destroy, Report.new) }

it { is_expected.to be_able_to(:index, :activity) }
it { is_expected.to be_able_to(:show, :activity) }
it { is_expected.not_to be_able_to(:index, :activity) }
it { is_expected.not_to be_able_to(:show, :activity) }
end

context 'when is a read_only user' do
Expand Down
13 changes: 9 additions & 4 deletions spec/views/conservation_records/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
item_record_number: 'Item Record Number',
digitization: false
)
ids = [@conservation_record1.id, @conservation_record2.id]
relation = ConservationRecord.where(id: ids)
@pagy, @conservation_records = pagy(relation, items: 100)
end

it 'renders a list of conservation_records' do
@pagy, @conservation_records = pagy(ConservationRecord.all, items: 100)
render
assert_select 'td', text: @conservation_record1.id.to_s, count: 1
assert_select 'td', text: @conservation_record2.id.to_s, count: 1
Expand All @@ -46,14 +48,17 @@
@user = create(:user, role: 'read_only')
@request.env['devise.mapping'] = Devise.mappings[:user]
sign_in @user
@pagy, @conservation_records = pagy(ConservationRecord.all, items: 100)
render
expect(rendered).not_to have_button('New Conservation Record')
end

it 'displays a pagination widget' do
@pagy, @conservation_records = pagy(ConservationRecord.all, items: 100)
# Only 2 records, so the pagy widget should be disabled
render
expect(rendered).to have_text('<1>')
expect(rendered).to have_css('nav.pagy-bootstrap-nav')
expect(rendered).to have_css('li.page-item.prev.disabled')
expect(rendered).to have_css('li.page-item.next.disabled')
expect(rendered).to have_css('a[aria-label="Previous"]', text: '<')
expect(rendered).to have_css('a[aria-label="Next"]', text: '>')
end
end