From 07e79a3c00b07f8102fb6d9139c6d192bb5ffeae Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Mon, 16 Nov 2026 12:45:57 -0500 Subject: [PATCH] View tech bonuses permission, for the Foreman A global "View tech bonuses" permission shows the weeks run and each week's hours, tiers and bonuses, read-only: no attendance boxes, run button or Email again, and no customer accounts, emailed-to addresses, or QuickBooks/PDF links. "Run tech bonuses" is unchanged. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 ++- app/controllers/tech_bonuses_controller.rb | 1 + app/views/tech_bonuses/show.html.erb | 19 ++++++++----- config/locales/en.yml | 1 + init.rb | 4 ++- lib/redmine_qbo_bonus.rb | 6 ++++ test/integration/tech_bonuses_test.rb | 32 ++++++++++++++++++++++ 7 files changed, 58 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index aac4c2b..cea0e33 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,9 @@ Restart Redmine, then: * Check the target and amounts. * Pick the product/service. 3. **Administration » Bonus technicians**: add each technician and the Foreman. Give each one their role, the QuickBooks customer account their bonus is credited to, and the last day of their probation if they're in it. -4. **Administration » Roles and permissions**: give **Run tech bonuses** to the roles that run the bonus. It's a global permission, so it applies to any role the user has in any project. +4. **Administration » Roles and permissions**: give **Run tech bonuses** to the roles that run the bonus, and **View tech bonuses** to those who only see it (e.g. the Foreman). They're global permissions, so they apply to any role the user has in any project. + +**View tech bonuses** shows the weeks and each week's hours, tiers and bonuses, read-only. It doesn't show the technicians' customer accounts, the attendance boxes, or the credit memos' QuickBooks and PDF links, and it can't run a week or email a credit memo. ## Tests diff --git a/app/controllers/tech_bonuses_controller.rb b/app/controllers/tech_bonuses_controller.rb index 13d181c..5ebb319 100644 --- a/app/controllers/tech_bonuses_controller.rb +++ b/app/controllers/tech_bonuses_controller.rb @@ -34,6 +34,7 @@ class TechBonusesController < ApplicationController @report = RedmineQboBonus::WeekReport.new(@week) @bonus_week = TechBonusWeek.for(@week) @credits = @bonus_week ? @bonus_week.credits.index_by(&:user_id) : {} + @can_run = RedmineQboBonus.allowed? end def create diff --git a/app/views/tech_bonuses/show.html.erb b/app/views/tech_bonuses/show.html.erb index 09faac4..cec9cb8 100644 --- a/app/views/tech_bonuses/show.html.erb +++ b/app/views/tech_bonuses/show.html.erb @@ -69,13 +69,16 @@ <% credit = @credits[tech.user_id] %> <% credited = credit&.credited? %> - <%= link_to_user tech.user %>
<%= tech.customer&.name || l(:text_tech_bonus_no_customer) %> + + <%= link_to_user tech.user %> + <% if @can_run %>
<%= tech.customer&.name || l(:text_tech_bonus_no_customer) %><% end %> + <%= tech.role_name %> <%= bonus_hours(line.hours) %> <% if credited %> <%= sprite_icon('checked', l(:general_text_Yes)) %> - <% elsif line.eligible? %> + <% elsif @can_run && line.eligible? %> <%= check_box_tag 'attended[]', tech.user_id, credit.nil? || credit.message != l(:text_tech_bonus_missed_shift), id: "attended_#{tech.user_id}", disabled: !report.goal_met? %> <% end %> @@ -89,15 +92,15 @@ <%= bonus_money(line.tier_amount) %> <%= bonus_money(line.amount) %> <% end %> - <%= credit_memo_link(credit) %> + <%= @can_run ? credit_memo_link(credit) : (credit&.doc_number.presence && "##{credit.doc_number}") %> <%= bonus_status_tag(credit) %> <% message = credit&.message.presence || line.ineligible_reason %> - <% if credit&.emailed_to.present? %>
<%= credit.emailed_to %><% end %> + <% if @can_run && credit&.emailed_to.present? %>
<%= credit.emailed_to %><% end %> <% if message %>
<%= message %><% end %> - <% if credited %> + <% if credited && @can_run %> <%= link_to sprite_icon('email', l(:button_tech_bonus_resend)), resend_tech_bonus_credit_path(credit), method: :post, class: 'icon icon-email', data: { confirm: l(:text_tech_bonus_resend_confirm) } %> @@ -108,9 +111,11 @@ -

<%= l(:text_tech_bonus_attendance) %>

+ <% if @can_run %> +

<%= l(:text_tech_bonus_attendance) %>

+ <% end %> - <% if @week.completed? %> + <% if @can_run && @week.completed? %>

<% label = report.goal_met? ? l(:button_tech_bonus_run) : l(:button_tech_bonus_record) %> <%= submit_tag label, data: { confirm: report.goal_met? ? l(:text_tech_bonus_run_confirm) : nil } %> diff --git a/config/locales/en.yml b/config/locales/en.yml index fe7da30..ad9a078 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,5 +1,6 @@ en: permission_run_tech_bonuses: "Run tech bonuses" + permission_view_tech_bonuses: "View tech bonuses" label_tech_bonus_plural: "Tech bonuses" label_bonus_technician_plural: "Bonus technicians" diff --git a/init.rb b/init.rb index 76e8466..317b064 100644 --- a/init.rb +++ b/init.rb @@ -29,12 +29,14 @@ Redmine::Plugin.register :redmine_qbo_bonus do settings default: RedmineQboBonus::Settings::DEFAULTS.dup, partial: 'settings/qbo_bonus' + # Seeing the weeks' hours and bonuses (e.g. the Foreman), without running them or opening the credit memos + permission :view_tech_bonuses, { tech_bonuses: [:index, :show] }, global: true # Previewing a week's bonus, creating and emailing its credit memos permission :run_tech_bonuses, { tech_bonuses: [:index, :show, :create, :resend, :pdf] }, global: true menu :top_menu, :tech_bonuses, { controller: 'tech_bonuses', action: 'index' }, caption: :label_tech_bonus_plural, after: :my_page, - if: proc { User.current.allowed_to?(:run_tech_bonuses, nil, global: true) } + if: proc { RedmineQboBonus.visible? } # The technicians who earn the bonus and their QuickBooks customer accounts menu :admin_menu, :bonus_technicians, { controller: 'bonus_technicians', action: 'index' }, diff --git a/lib/redmine_qbo_bonus.rb b/lib/redmine_qbo_bonus.rb index 04547b7..643f508 100644 --- a/lib/redmine_qbo_bonus.rb +++ b/lib/redmine_qbo_bonus.rb @@ -12,10 +12,16 @@ module RedmineQboBonus def self.setup; end + # May run the bonus (create and email credit memos) def self.allowed?(user = User.current) user.allowed_to?(:run_tech_bonuses, nil, global: true) end + # May see the bonus pages (run them, or only view them) + def self.visible?(user = User.current) + allowed?(user) || user.allowed_to?(:view_tech_bonuses, nil, global: true) + end + # 95.5 => "95.5", 110.0 => "110", 87.583 => "87.58" def self.format_hours(hours) rounded = hours.to_d.round(2) diff --git a/test/integration/tech_bonuses_test.rb b/test/integration/tech_bonuses_test.rb index 162a0a3..a44b4d8 100644 --- a/test/integration/tech_bonuses_test.rb +++ b/test/integration/tech_bonuses_test.rb @@ -34,6 +34,38 @@ class TechBonusesTest < Redmine::IntegrationTest assert_select '#top-menu a.tech-bonuses' end + def test_view_only + log_user('admin', 'admin') + post '/tech_bonuses/2026-11-08', params: { attended: ['2'] } + credit = TechBonusCredit.find_by(user_id: 2) + + Role.find(1).add_permission!(:view_tech_bonuses) + reset! + log_user('jsmith', 'jsmith') + get '/tech_bonuses' + assert_response :success + assert_select '#top-menu a.tech-bonuses' + get '/tech_bonuses/2026-11-08' + assert_response :success + assert_select 'td', text: '$100.00' + assert_select 'td', text: '#1042' + assert_select 'input[name=?]', 'attended[]', count: 0 + assert_select '#tech-bonus-run input[type=submit]', count: 0 + assert_select 'a[href*="creditmemo"]', count: 0 + assert_select 'a[href*="/pdf"]', count: 0 + assert_select 'a[href*="/resend"]', count: 0 + assert_not_includes response.body, 'tech@example.com' + + assert_no_difference 'TechBonusCredit.count' do + post '/tech_bonuses/2026-11-15', params: { attended: ['2'] } + end + assert_response :forbidden + post "/tech_bonuses/credits/#{credit.id}/resend" + assert_response :forbidden + get "/tech_bonuses/credits/#{credit.id}/pdf" + assert_response :forbidden + end + def test_week_preview log_user('admin', 'admin') get '/tech_bonuses', params: { week: '2026-11-10' }