Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

KG - SSR 'Edit' Button Bugs #426

Merged
merged 7 commits into from
May 27, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def index
service_request = ServiceRequest.find(params[:srid])
protocol = service_request.protocol
@admin_orgs = @user.authorized_admin_organizations
@permission_to_edit = protocol.project_roles.find_by(identity_id: @user.id)
@permission_to_edit = protocol.project_roles.where(identity_id: @user.id, project_rights: ['approve', 'request']).any?
@sub_service_requests = service_request.sub_service_requests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Find roles where 'approve' or 'request' rights, then use !.nil? to for 'are there any?'. Returns boolean value now

end

Expand Down
8 changes: 4 additions & 4 deletions app/helpers/dashboard/sub_service_requests_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def ssr_actions_display(ssr, user, permission_to_edit, admin_orgs)
admin_access = (admin_orgs & ssr.org_tree).any?

ssr_view_button(ssr)+
ssr_edit_button(ssr, user, permission_to_edit, admin_access)+
ssr_edit_button(ssr, user, permission_to_edit)+
ssr_admin_button(ssr, user, permission_to_edit, admin_access)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer determined by admin access

end

Expand All @@ -205,10 +205,10 @@ def ssr_view_button(ssr)
content_tag(:button, t(:dashboard)[:service_requests][:actions][:view], class: 'view-service-request btn btn-primary btn-sm', type: 'button', data: { sub_service_request_id: ssr.id })
end

def ssr_edit_button(ssr, user, permission_to_edit, admin_access)
def ssr_edit_button(ssr, user, permission_to_edit)
# The SSR must not be locked, and the user must either be an authorized user or an authorized admin
if ssr.can_be_edited? && permission = (permission_to_edit == 'true' || admin_access)
content_tag(:button, t(:dashboard)[:service_requests][:actions][:edit], class: 'edit-service-request btn btn-warning btn-sm', type: 'button', data: { permission: permission.to_s, url: "/service_requests/#{ssr.service_request.id}/catalog?sub_service_request_id=#{ssr.id}&from_user_portal=true"})
if ssr.can_be_edited? && permission_to_edit
content_tag(:button, t(:dashboard)[:service_requests][:actions][:edit], class: 'edit-service-request btn btn-warning btn-sm', type: 'button', data: { permission: permission_to_edit.to_s, url: "/service_requests/#{ssr.service_request.id}/catalog?sub_service_request_id=#{ssr.id}&from_user_portal=true"})
else
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer determined by admin access. Simply display it if they have the correct authorized user rights

''
end
Expand Down
10 changes: 5 additions & 5 deletions app/views/dashboard/sub_service_requests/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
json.(@sub_service_requests) do |ssr|
json.srid ssr.display_id
json.organization ssr.org_tree_display
json.status AVAILABLE_STATUSES[ssr.status]
json.notifications ssr_notifications_display(ssr, @user)
json.actions ssr_actions_display(ssr, @user, @permission_to_edit, @admin_orgs)
json.srid ssr.display_id
json.organization ssr.org_tree_display
json.status AVAILABLE_STATUSES[ssr.status]
json.notifications ssr_notifications_display(ssr, @user)
json.actions ssr_actions_display(ssr, @user, @permission_to_edit, @admin_orgs)
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Them tabs were nastay

103 changes: 50 additions & 53 deletions spec/features/dashboard/service_requests/user_views_ssrs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,66 +21,63 @@
require 'rails_helper'

RSpec.describe "User views SSR table", js: true do
let_there_be_lane
let_there_be_lane
fake_login_for_each_test

def go_to_show_protocol(protocol_id)
def go_to_show_protocol(protocol_id)
page = Dashboard::Protocols::ShowPage.new
page.load(id: protocol_id)
page
end

let!(:bob) { create(:identity) }
let!(:bob) { create(:identity) }

context 'for an editable SSR' do
context 'As an Authorized User with Edit Privileges' do
let!(:protocol) { create(:unarchived_study_without_validations, primary_pi: jug2) }
let!(:service_request) { create(:service_request_without_validations, protocol: protocol, service_requester: jug2, status: 'draft') }
let!(:organization) { create(:organization,type: 'Institution', name: 'Megacorp', admin: bob, service_provider: bob) }
let!(:sub_service_request) { create(:sub_service_request, id: 9999, ssr_id: '1234', service_request: service_request, organization_id: organization.id) }

scenario 'and sees View and Edit' do
page = go_to_show_protocol(protocol.id)
wait_for_javascript_to_finish

expect(page).to have_selector('button', text: 'View')
expect(page).to have_selector('button', text: 'Edit')
expect(page).not_to have_selector('button', text: 'Admin Edit')
end
end

context 'As an Authorized User with View Privileges' do
let!(:protocol) { create(:unarchived_study_without_validations, primary_pi: bob) }
let!(:service_request) { create(:service_request_without_validations, protocol: protocol, service_requester: bob, status: 'draft') }
let!(:organization) { create(:organization,type: 'Institution', name: 'Megacorp', admin: bob, service_provider: bob) }
let!(:sub_service_request) { create(:sub_service_request, id: 9999, ssr_id: '1234', service_request: service_request, organization_id: organization.id) }

scenario 'and sees View' do
create(:project_role, identity: jug2, protocol: protocol, project_rights: 'view', role: 'consultant')

page = go_to_show_protocol(protocol.id)
wait_for_javascript_to_finish

expect(page).to have_selector('button', text: 'View')
expect(page).not_to have_selector('button', text: 'Edit')
expect(page).not_to have_selector('button', text: 'Admin Edit')
end
end

context 'As an admin' do
let!(:protocol) { create(:unarchived_study_without_validations, primary_pi: jug2) }
let!(:service_request) { create(:service_request_without_validations, protocol: protocol, service_requester: jug2, status: 'draft') }
let!(:organization) { create(:organization,type: 'Institution', name: 'Megacorp', admin: jug2, service_provider: jug2) }
let!(:sub_service_request) { create(:sub_service_request, id: 9999, ssr_id: '1234', service_request: service_request, organization_id: organization.id) }

scenario 'and sees View, Edit, and Admin Edit' do
page = go_to_show_protocol(protocol.id)
wait_for_javascript_to_finish

expect(page).to have_selector('button', text: 'View')
expect(page).to have_selector('button', text: 'Edit')
expect(page).to have_selector('button', text: 'Admin Edit')
end
end
end
context 'As an Authorized User with Edit Privileges' do
let!(:protocol) { create(:unarchived_study_without_validations, primary_pi: jug2) }
let!(:service_request) { create(:service_request_without_validations, protocol: protocol, service_requester: jug2, status: 'draft') }
let!(:organization) { create(:organization,type: 'Institution', name: 'Megacorp', admin: bob, service_provider: bob) }
let!(:sub_service_request) { create(:sub_service_request, id: 9999, ssr_id: '1234', service_request: service_request, organization_id: organization.id) }

scenario 'and sees View and Edit' do
page = go_to_show_protocol(protocol.id)

expect(page).to have_selector('button', text: /\AView\z/)
expect(page).to have_selector('button', text: /\AEdit\z/)
expect(page).not_to have_selector('button', text: 'Admin Edit')
end
end

context 'As an Authorized User with View Privileges' do
let!(:protocol) { create(:unarchived_study_without_validations, primary_pi: bob) }
let!(:service_request) { create(:service_request_without_validations, protocol: protocol, service_requester: bob, status: 'draft') }
let!(:organization) { create(:organization,type: 'Institution', name: 'Megacorp', admin: bob, service_provider: bob) }
let!(:sub_service_request) { create(:sub_service_request, id: 9999, ssr_id: '1234', service_request: service_request, organization_id: organization.id) }

scenario 'and sees View' do
create(:project_role, identity: jug2, protocol: protocol, project_rights: 'view', role: 'consultant')

page = go_to_show_protocol(protocol.id)

expect(page).to have_selector('button', text: /\AView\z/)
expect(page).not_to have_selector('button', text: /\AEdit\z/)
expect(page).not_to have_selector('button', text: 'Admin Edit')
end
end

context 'As an admin' do
let!(:protocol) { create(:unarchived_study_without_validations, primary_pi: bob) }
let!(:service_request) { create(:service_request_without_validations, protocol: protocol, service_requester: jug2, status: 'draft') }
let!(:organization) { create(:organization,type: 'Institution', name: 'Megacorp', admin: jug2, service_provider: jug2) }
let!(:sub_service_request) { create(:sub_service_request, id: 9999, ssr_id: '1234', service_request: service_request, organization_id: organization.id) }

scenario 'and sees View, and Admin Edit, but not Edit' do
page = go_to_show_protocol(protocol.id)

expect(page).to have_selector('button', text: /\AView\z/)
expect(page).not_to have_selector('button', text: /\AEdit\z/)
expect(page).to have_selector('button', text: 'Admin Edit')
end
end
end
end