-
-
Notifications
You must be signed in to change notification settings - Fork 30
[harmony] Bug 1983391: Add a donation banner to the home page #156
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
Open
justdave
wants to merge
13
commits into
main
Choose a base branch
from
bug-1983391-harmony
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6d81875
Bug 1983391: Add a donation banner to the home page
justdave 5c38e97
Bug 1983391: Dismiss the next-upgrade donation reminder from the Dona…
mrenvoize 690fd83
Bug 1983391: Hide internal donation settings from the generic Setting…
mrenvoize e977585
Bug 1983391: Remove the unused Donation user-setting subclass
mrenvoize 0021b98
Bug 1983391: Do not let the donation banner hide the new-release notice
mrenvoize 959aa7f
Bug 1983391: Share common banner styling between release and donation…
mrenvoize 1057bc0
Bug 1983391: Use a stateless hash token for the donation banner dismiss
mrenvoize 0690f65
Bug 1983391: Stop stretching the Buggie donation image
mrenvoize e7a1b50
Bug 1983391: Only show the reminder date input for 'specific date'
mrenvoize d4b9357
Bug 1983391: Improve donation banner contrast in dark mode
mrenvoize 189a2f5
Bug 1983391: Constrain home banners to the page content width
mrenvoize 7781ac7
Bug 1983391: Default the reminder date picker to today, not the epoch
mrenvoize 535265b
Bug 1983391: Replace donation banner placeholder image with buggie_wa…
mrenvoize File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # | ||
| # This Source Code Form is "Incompatible With Secondary Licenses", as | ||
| # defined by the Mozilla Public License, v. 2.0. | ||
|
|
||
| package Bugzilla::Config::Donation; | ||
|
|
||
| use 5.14.0; | ||
| use strict; | ||
| use warnings; | ||
|
|
||
| use Bugzilla::Config::Common; | ||
|
|
||
| our $sortkey = 175; | ||
|
|
||
| use constant get_param_list => ( | ||
| { | ||
| name => 'donation_banner_visibility', | ||
| type => 's', | ||
| choices => ['admins_only', 'end_users', 'disabled'], | ||
| default => 'admins_only', | ||
| checker => \&check_multi, | ||
| }, | ||
| ); | ||
|
|
||
| 1; | ||
|
|
||
| __END__ | ||
|
|
||
| =head1 NAME | ||
|
|
||
| Bugzilla::Config::Donation - Donation banner settings | ||
|
|
||
| =cut |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # | ||
| # This Source Code Form is "Incompatible With Secondary Licenses", as | ||
| # defined by the Mozilla Public License, v. 2.0. | ||
|
|
||
| package Bugzilla::Donation; | ||
|
|
||
| use 5.14.0; | ||
| use strict; | ||
| use warnings; | ||
|
|
||
| use Bugzilla::Constants; | ||
| use Bugzilla::Error; | ||
| use Bugzilla::Token qw(issue_hash_token); | ||
| use Bugzilla::Util qw(validate_date); | ||
|
|
||
| use DateTime; | ||
|
|
||
| use constant BANNER_URL => 'https://bugzilla.org/donate'; | ||
| use constant BANNER_MESSAGES => ( | ||
| 'Help us make Bugzilla better more often.', | ||
| 'A small donation helps keep Bugzilla moving forward.', | ||
| 'Support the people who keep Bugzilla running.', | ||
| 'Even a little funding helps Bugzilla improve more quickly.', | ||
| 'If Bugzilla helps your team, consider helping Bugzilla too.', | ||
| ); | ||
|
|
||
| sub get_banner { | ||
| my $user = Bugzilla->user; | ||
| return undef if !$user->id; | ||
|
|
||
| my $visibility = Bugzilla->params->{'donation_banner_visibility'} || 'admins_only'; | ||
| return undef if $visibility eq 'disabled'; | ||
| return undef if $visibility eq 'admins_only' && !$user->in_group('admin'); | ||
|
|
||
| my $settings = $user->settings; | ||
| my $pref = $settings->{'donate_banner_pref'}->{'value'}; | ||
| my $last_version = $settings->{'donate_banner_last_version'}->{'value'} || '0.0'; | ||
| my $next_date = $settings->{'donate_banner_reminder_date'}->{'value'} || '1970-01-01'; | ||
| my $current_version = BUGZILLA_VERSION; | ||
|
|
||
| my $show; | ||
| my $show_thanks = 0; | ||
| if ($pref eq 'next_upgrade') { | ||
| $show = ($last_version ne $current_version); | ||
| $show_thanks = $show | ||
| && $user->in_group('admin') | ||
| && $last_version ne '0' | ||
| && $last_version ne '0.0'; | ||
| } | ||
| elsif ($pref eq 'specific_date') { | ||
| my $today = DateTime->now(time_zone => Bugzilla->local_timezone)->ymd; | ||
| $show = ($next_date le $today); | ||
| } | ||
| else { | ||
| $show = 0; | ||
| } | ||
|
|
||
| return undef if !$show; | ||
|
|
||
| my @messages = BANNER_MESSAGES; | ||
| my $message = $messages[int(rand(@messages))]; | ||
|
|
||
| my $data = { | ||
| url => BANNER_URL, | ||
| message => $message, | ||
| show_thanks => $show_thanks, | ||
| visibility => $visibility, | ||
| settings_link => 'editparams.cgi?section=donation#donation_banner_visibility_desc', | ||
| token => issue_hash_token(['donation_banner']), | ||
| today => DateTime->now(time_zone => Bugzilla->local_timezone)->ymd, | ||
| }; | ||
|
|
||
| if ($visibility eq 'admins_only') { | ||
| $data->{'visibility_note'} | ||
| = 'This message is only shown to logged-in users with admin privs.'; | ||
| } | ||
| elsif ($user->in_group('admin')) { | ||
| $data->{'visibility_note'} | ||
| = 'This message is visible to all logged-in users.'; | ||
| } | ||
|
|
||
| return $data; | ||
| } | ||
|
|
||
| sub set_banner_preference { | ||
| my ($action, $date) = @_; | ||
| my $user = Bugzilla->user; | ||
| my $settings = $user->settings; | ||
|
|
||
| my $pref_setting = $settings->{'donate_banner_pref'}; | ||
| my $date_setting = $settings->{'donate_banner_reminder_date'}; | ||
| my $version_setting = $settings->{'donate_banner_last_version'}; | ||
| my $current_version = BUGZILLA_VERSION; | ||
|
|
||
| if ($action eq 'next_upgrade') { | ||
| $pref_setting->set('next_upgrade'); | ||
| $version_setting->set($current_version); | ||
| return 'index.cgi'; | ||
| } | ||
| if ($action eq 'week' || $action eq 'month') { | ||
| my $days = $action eq 'week' ? 7 : 30; | ||
| my $dt = DateTime->now(time_zone => Bugzilla->local_timezone); | ||
| $dt->add(days => $days); | ||
| $pref_setting->set('specific_date'); | ||
| $date_setting->set($dt->ymd); | ||
| $version_setting->set($current_version); | ||
| return 'index.cgi'; | ||
| } | ||
| if ($action eq 'never') { | ||
| $pref_setting->set('never'); | ||
| $version_setting->set($current_version); | ||
| return 'index.cgi'; | ||
| } | ||
| if ($action eq 'date') { | ||
| validate_date($date) | ||
| || ThrowUserError('illegal_date', {date => $date, format => 'YYYY-MM-DD'}); | ||
| $pref_setting->set('specific_date'); | ||
| $date_setting->set($date); | ||
| $version_setting->set($current_version); | ||
| return 'index.cgi'; | ||
| } | ||
|
|
||
| return 'index.cgi'; | ||
| } | ||
|
|
||
| 1; | ||
|
|
||
| __END__ | ||
|
|
||
| =head1 NAME | ||
|
|
||
| Bugzilla::Donation - Donation banner helpers | ||
|
|
||
| =cut |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look related to the banner addition to me?