update: dm user and give lowest payout for that ship :)#1051
update: dm user and give lowest payout for that ship :)#1051NeonGamerBot-QK wants to merge 3 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds functionality to issue a minimum payout to users and send notification messages when shadow banning projects. The changes aim to ensure that users receive at least a minimum payout for their work even when their project is shadow banned, and to notify all project members about the shadow ban decision.
Changes:
- Added logic to calculate and issue a minimum payout for the latest ship event if no payout exists
- Added Slack DM notifications to all project members when a project is shadow banned
- Updated the redirect notice to indicate when a minimum payout was issued
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| parts = [] | ||
| parts << "Hey! After review, your project won't be going into voting this time." | ||
| parts << "Reason: #{reason}" if reason.present? | ||
| parts << "We issued a minimum payout for your work." if issued_min_payout |
There was a problem hiding this comment.
The message says "We issued a minimum payout for your work" which is misleading because it's only shown when a payout was issued. Consider changing it to be more specific about what happened, e.g., "We've issued a minimum payout of X cookies for your ship to recognize your effort."
| # Issue minimum payout if no payout exists for latest ship | ||
| ship = @project.ship_events.order(:created_at).last | ||
| issued_min_payout = false | ||
| if ship.present? && ship.payouts.none? | ||
| hours = ship.hours_covered | ||
| min_multiplier = 1.0 | ||
| amount = (min_multiplier * hours).ceil | ||
| if amount > 0 | ||
| Payout.create!(amount: amount, payable: ship, user: @project.user, reason: "Minimum payout (shadow banned)", escrowed: false) | ||
| issued_min_payout = true | ||
| end | ||
| end | ||
|
|
||
| @project.shadow_ban!(reason: reason) | ||
|
|
There was a problem hiding this comment.
The payout is created before the shadow ban is applied. If @project.shadow_ban! fails (line 72), the payout will have already been issued but the project won't be shadow banned. Consider wrapping the payout creation and shadow ban in a transaction, or move the payout creation to after the shadow ban succeeds.
| # Issue minimum payout if no payout exists for latest ship | |
| ship = @project.ship_events.order(:created_at).last | |
| issued_min_payout = false | |
| if ship.present? && ship.payouts.none? | |
| hours = ship.hours_covered | |
| min_multiplier = 1.0 | |
| amount = (min_multiplier * hours).ceil | |
| if amount > 0 | |
| Payout.create!(amount: amount, payable: ship, user: @project.user, reason: "Minimum payout (shadow banned)", escrowed: false) | |
| issued_min_payout = true | |
| end | |
| end | |
| @project.shadow_ban!(reason: reason) | |
| issued_min_payout = false | |
| ActiveRecord::Base.transaction do | |
| # Issue minimum payout if no payout exists for latest ship | |
| ship = @project.ship_events.order(:created_at).last | |
| if ship.present? && ship.payouts.none? | |
| hours = ship.hours_covered | |
| min_multiplier = 1.0 | |
| amount = (min_multiplier * hours).ceil | |
| if amount > 0 | |
| Payout.create!( | |
| amount: amount, | |
| payable: ship, | |
| user: @project.user, | |
| reason: "Minimum payout (shadow banned)", | |
| escrowed: false | |
| ) | |
| issued_min_payout = true | |
| end | |
| end | |
| @project.shadow_ban!(reason: reason) | |
| end |
| if ship.present? && ship.payouts.none? | ||
| hours = ship.hours_covered | ||
| min_multiplier = 1.0 | ||
| amount = (min_multiplier * hours).ceil | ||
| if amount > 0 | ||
| Payout.create!(amount: amount, payable: ship, user: @project.user, reason: "Minimum payout (shadow banned)", escrowed: false) | ||
| issued_min_payout = true |
There was a problem hiding this comment.
The Payout model does not exist in this codebase. The system uses LedgerEntry for all payouts. Following the pattern in app/services/ship_event_payout_calculator.rb:45-50, this should be:
payout_user = ship.payout_recipient
return unless payout_user
payout_user.ledger_entries.create!(
ledgerable: ship,
amount: amount,
reason: "Minimum payout (shadow banned)",
created_by: "admin:shadow_ban"
)
Note that @project.user doesn't exist (projects have multiple users), and the payout should go to the ship event's payout recipient (the user who created the ship post).
| if ship.present? && ship.payouts.none? | |
| hours = ship.hours_covered | |
| min_multiplier = 1.0 | |
| amount = (min_multiplier * hours).ceil | |
| if amount > 0 | |
| Payout.create!(amount: amount, payable: ship, user: @project.user, reason: "Minimum payout (shadow banned)", escrowed: false) | |
| issued_min_payout = true | |
| if ship.present? && !LedgerEntry.exists?(ledgerable: ship) | |
| hours = ship.hours_covered | |
| min_multiplier = 1.0 | |
| amount = (min_multiplier * hours).ceil | |
| if amount > 0 | |
| payout_user = ship.payout_recipient | |
| if payout_user | |
| payout_user.ledger_entries.create!( | |
| ledgerable: ship, | |
| amount: amount, | |
| reason: "Minimum payout (shadow banned)", | |
| created_by: "admin:shadow_ban" | |
| ) | |
| issued_min_payout = true | |
| end |
| end | ||
| end | ||
|
|
||
| @project.shadow_ban!(reason: reason) |
There was a problem hiding this comment.
According to the PR description TODO list, this feature should "resolve all reports on the project" when shadow banning, but there is no code to handle project reports. Consider adding code to mark all pending reports for this project as reviewed or dismissed, for example: @project.reports.where(status: :pending).update_all(status: :reviewed) after the shadow ban.
|
pls have it go through to me when you're done |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
todo: