Skip to content

Commit

Permalink
Merge branch 'main' into Release-1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iMattPro committed Jul 14, 2024
2 parents 22cba4d + e340b99 commit 13cbc63
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions adm/style/wpn_acp_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ <h3>{{ lang('WARNING') }}</h3>
<dl>
<dt><label>{{ lang('WEBPUSH_DROPDOWN_SUBSCRIBE') ~ lang('COLON') }}</label><br><span>{{ lang('WEBPUSH_DROPDOWN_SUBSCRIBE_EXPLAIN') }}</span></dt>
<dd><label><input type="radio" class="radio" name="config[wpn_webpush_dropdown_subscribe]" value="1" {% if S_WEBPUSH_DROPDOWN_SUBSCRIBE %}checked="checked"{% endif %}> {{ lang('YES') }}</label>
<label><input type="radio" class="radio" name="config[wpn_webpush_dropdown_subscribe]" value="0"{% if not S_WEBPUSH_DROPDOWN_SUBSCRIBE %} checked="checked"{% endif %}> {{ lang('NO') }}</label>
<label><input type="radio" class="radio" name="config[wpn_webpush_dropdown_subscribe]" value="0"{% if not S_WEBPUSH_DROPDOWN_SUBSCRIBE %} checked="checked"{% endif %}> {{ lang('NO') }}</label></dd>
</dl>
<dl>
<dt><label>{{ lang('WEBPUSH_METHOD_ENABLED') ~ lang('COLON') }}</label><br><span>{{ lang('WEBPUSH_METHOD_ENABLED_EXPLAIN') }}</span></dt>
<dd><label><input type="radio" class="radio" name="config[wpn_webpush_method_enabled]" value="1" {% if S_WEBPUSH_METHOD_ENABLED %}checked="checked"{% endif %}> {{ lang('YES') }}</label>
<label><input type="radio" class="radio" name="config[wpn_webpush_method_enabled]" value="0"{% if not S_WEBPUSH_METHOD_ENABLED %} checked="checked"{% endif %}> {{ lang('NO') }}</label>
<label><input type="radio" class="radio" name="config[wpn_webpush_method_enabled]" value="0"{% if not S_WEBPUSH_METHOD_ENABLED %} checked="checked"{% endif %}> {{ lang('NO') }}</label></dd>
</dl>
</fieldset>
<fieldset class="submit-buttons">
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"minishlink/web-push": "^7.0"
},
"require-dev": {
"phing/phing": "2.4.*"
"phing/phing": "~2.4"
},
"config": {
"allow-plugins": {
Expand Down
16 changes: 14 additions & 2 deletions notification/method/webpush.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* Web Push notification method class
* This class handles sending push messages for notifications
*/

class webpush extends messenger_base implements extended_method_interface
{
/** @var config */
Expand Down Expand Up @@ -379,7 +378,7 @@ public function get_ucp_template_data(helper $controller_helper, form_helper $fo
}

return [
'NOTIFICATIONS_WEBPUSH_ENABLE' => $this->config['wpn_webpush_dropdown_subscribe'] || stripos($this->user->page['page'], 'notification_options'),
'NOTIFICATIONS_WEBPUSH_ENABLE' => $this->allowed_user() && ($this->config['wpn_webpush_dropdown_subscribe'] || stripos($this->user->page['page'], 'notification_options')),
'U_WEBPUSH_SUBSCRIBE' => $controller_helper->route('phpbb_webpushnotifications_ucp_push_subscribe_controller'),
'U_WEBPUSH_UNSUBSCRIBE' => $controller_helper->route('phpbb_webpushnotifications_ucp_push_unsubscribe_controller'),
'VAPID_PUBLIC_KEY' => $this->config['wpn_webpush_vapid_public'],
Expand Down Expand Up @@ -553,4 +552,17 @@ protected function load_recipients_data(): array

return $notify_users;
}

/**
* User is allowed to use web push notifications
*
* @return bool
*/
protected function allowed_user()
{
return $this->user->id() !== ANONYMOUS
&& !$this->user->data['is_bot']
&& (int) $this->user->data['user_type'] !== USER_IGNORE
&& (int) $this->user->data['user_type'] !== USER_INACTIVE;
}
}
2 changes: 2 additions & 0 deletions tests/event/listener_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ protected function setUp(): void
$user = new \phpbb\user($this->language, '\phpbb\datetime');
$this->user = $user;
$this->user->data['user_form_salt'] = '';
$this->user->data['is_bot'] = false;
$this->user->data['user_type'] = USER_NORMAL;
$user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, 'phpbb_users');

$this->controller_helper = $this->getMockBuilder('\phpbb\controller\helper')
Expand Down
2 changes: 1 addition & 1 deletion ucp/controller/webpush.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ protected function check_subscribe_requests(): void
}

// Subscribe should only be available for logged-in "normal" users
if (!$this->request->is_ajax() || $this->user->id() == ANONYMOUS || $this->user->data['is_bot']
if (!$this->request->is_ajax() || $this->user->id() === ANONYMOUS || $this->user->data['is_bot']
|| $this->user->data['user_type'] == USER_IGNORE || $this->user->data['user_type'] == USER_INACTIVE)
{
throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION');
Expand Down

0 comments on commit 13cbc63

Please sign in to comment.