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 <noreply@anthropic.com>
This commit is contained in:
1 parent
a2ecb74c1d
commit
07e79a3c00
7 files changed
+58
-9
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -69,13 +69,16 @@
|
||||
<% credit = @credits[tech.user_id] %>
|
||||
<% credited = credit&.credited? %>
|
||||
<tr class="<%= 'ineligible' unless line.eligible? %>">
|
||||
<td class="name"><%= link_to_user tech.user %><br><small><%= tech.customer&.name || l(:text_tech_bonus_no_customer) %></small></td>
|
||||
<td class="name">
|
||||
<%= link_to_user tech.user %>
|
||||
<% if @can_run %><br><small><%= tech.customer&.name || l(:text_tech_bonus_no_customer) %></small><% end %>
|
||||
</td>
|
||||
<td><%= tech.role_name %></td>
|
||||
<td><%= bonus_hours(line.hours) %></td>
|
||||
<td>
|
||||
<% 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 @@
|
||||
<td><%= bonus_money(line.tier_amount) %></td>
|
||||
<td><%= bonus_money(line.amount) %></td>
|
||||
<% end %>
|
||||
<td><%= credit_memo_link(credit) %></td>
|
||||
<td><%= @can_run ? credit_memo_link(credit) : (credit&.doc_number.presence && "##{credit.doc_number}") %></td>
|
||||
<td class="message">
|
||||
<%= bonus_status_tag(credit) %>
|
||||
<% message = credit&.message.presence || line.ineligible_reason %>
|
||||
<% if credit&.emailed_to.present? %><br><small><%= credit.emailed_to %></small><% end %>
|
||||
<% if @can_run && credit&.emailed_to.present? %><br><small><%= credit.emailed_to %></small><% end %>
|
||||
<% if message %><br><small><%= message %></small><% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% 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 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p><em class="info"><%= l(:text_tech_bonus_attendance) %></em></p>
|
||||
<% if @can_run %>
|
||||
<p><em class="info"><%= l(:text_tech_bonus_attendance) %></em></p>
|
||||
<% end %>
|
||||
|
||||
<% if @week.completed? %>
|
||||
<% if @can_run && @week.completed? %>
|
||||
<p>
|
||||
<% 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 } %>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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' },
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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' }
|
||||
|
||||
Reference in new issue
Block a user