1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-09 00:55:23 +02:00

[ticket/11746] Add "admin activation required" notification.

PHPBB3-11746
This commit is contained in:
Cesar G 2013-10-24 02:37:20 -07:00
parent 2adf3d7a34
commit d607f1c927
7 changed files with 211 additions and 35 deletions

View File

@ -319,6 +319,24 @@ services:
tags:
- { name: notification.type }
notification.type.admin_activate_user:
class: phpbb\notification\type\admin_activate_user
scope: prototype # scope MUST be prototype for this to work!
arguments:
- @user_loader
- @dbal.conn
- @cache.driver
- @user
- @auth
- @config
- %core.root_path%
- %core.php_ext%
- %tables.notification_types%
- %tables.notifications%
- %tables.user_notifications%
tags:
- { name: notification.type }
notification.method.email:
class: phpbb\notification\method\email
scope: prototype # scope MUST be prototype for this to work!

View File

@ -396,6 +396,9 @@ class acp_users
{
if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
{
$phpbb_notifications = $phpbb_container->get('notification_manager');
$phpbb_notifications->mark_notifications_read('admin_activate_user', $user_row['user_id'], false);
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
$messenger = new messenger(false);

View File

@ -27,7 +27,7 @@ class ucp_activate
function main($id, $mode)
{
global $config, $phpbb_root_path, $phpEx;
global $db, $user, $auth, $template;
global $db, $user, $auth, $template, $phpbb_container;
$user_id = request_var('u', 0);
$key = request_var('k', '');
@ -108,6 +108,9 @@ class ucp_activate
if ($config['require_activation'] == USER_ACTIVATION_ADMIN && !$update_password)
{
$phpbb_notifications = $phpbb_container->get('notification_manager');
$phpbb_notifications->mark_notifications_read('admin_activate_user', $user_row['user_id'], false);
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
$messenger = new messenger(false);

View File

@ -379,41 +379,16 @@ class ucp_register
}
$messenger->send(NOTIFY_EMAIL);
}
if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
{
// Grab an array of user_id's with a_user permissions ... these users can activate a user
$admin_ary = $auth->acl_get_list(false, 'a_user', false);
$admin_ary = (!empty($admin_ary[0]['a_user'])) ? $admin_ary[0]['a_user'] : array();
// Also include founders
$where_sql = ' WHERE user_type = ' . USER_FOUNDER;
if (sizeof($admin_ary))
{
$where_sql .= ' OR ' . $db->sql_in_set('user_id', $admin_ary);
}
$sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type
FROM ' . USERS_TABLE . ' ' .
$where_sql;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$messenger->template('admin_activate', $row['user_lang']);
$messenger->set_addresses($row);
$messenger->assign_vars(array(
'USERNAME' => htmlspecialchars_decode($data['username']),
'U_USER_DETAILS' => "$server_url/memberlist.$phpEx?mode=viewprofile&u=$user_id",
'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey")
);
$messenger->send($row['user_notify_type']);
}
$db->sql_freeresult($result);
}
if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
{
$phpbb_notifications = $phpbb_container->get('notification_manager');
$phpbb_notifications->add_notifications('admin_activate_user', array(
'user_id' => $user_id,
'user_actkey' => $user_row['user_actkey'],
'user_regdate' => $user_row['user_regdate'],
));
}
// Perform account linking if necessary

View File

@ -430,6 +430,7 @@ $lang = array_merge($lang, array(
'NOTIFICATION_TOPIC_DISAPPROVED' => 'Your topic "%1$s" was disapproved for reason: "%2$s".',
'NOTIFICATION_TOPIC_IN_QUEUE' => 'A new topic titled "%2$s" was posted by %1$s and needs approval.',
'NOTIFICATION_TYPE_NOT_EXIST' => 'The notification type "%s" is missing from the file system.',
'NOTIFICATION_ADMIN_ACTIVATE_USER' => 'The user “%1$s” is newly registered and requires activation.',
'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.',
'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: <a href="mailto:%1$s">%1$s</a>',
'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.',

View File

@ -312,6 +312,7 @@ $lang = array_merge($lang, array(
'NOTIFICATIONS_MARK_ALL_READ_SUCCESS' => 'All notifications have been marked read.',
'NOTIFICATION_GROUP_MISCELLANEOUS' => 'Miscellaneous Notifications',
'NOTIFICATION_GROUP_MODERATION' => 'Moderation Notifications',
'NOTIFICATION_GROUP_ADMINISTRATION' => 'Administration Notifications',
'NOTIFICATION_GROUP_POSTING' => 'Posting Notifications',
'NOTIFICATION_METHOD_EMAIL' => 'Email',
'NOTIFICATION_METHOD_JABBER' => 'Jabber',
@ -325,6 +326,7 @@ $lang = array_merge($lang, array(
'NOTIFICATION_TYPE_QUOTE' => 'Someone quotes you in a post',
'NOTIFICATION_TYPE_REPORT' => 'Someone reports a post',
'NOTIFICATION_TYPE_TOPIC' => 'Someone creates a topic in a forum to which you are subscribed',
'NOTIFICATION_TYPE_ADMIN_ACTIVATE_USER' => 'New registered user requiring activation',
'NOTIFY_METHOD' => 'Notification method',
'NOTIFY_METHOD_BOTH' => 'Both',

View File

@ -0,0 +1,174 @@
<?php
/**
*
* @package notifications
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\notification\type;
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Admin activation notifications class
* This class handles notifications for users requiring admin activation
*
* @package notifications
*/
class admin_activate_user extends \phpbb\notification\type\base
{
/**
* {@inheritdoc}
*/
public function get_type()
{
return 'admin_activate_user';
}
/**
* {@inheritdoc}
*/
protected $language_key = 'NOTIFICATION_ADMIN_ACTIVATE_USER';
/**
* {@inheritdoc}
*/
public static $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_ADMIN_ACTIVATE_USER',
'group' => 'NOTIFICATION_GROUP_ADMINISTRATION',
);
/**
* {@inheritdoc}
*/
public function is_available()
{
return ($this->auth->acl_get('a_user') && $this->config['require_activation'] == USER_ACTIVATION_ADMIN);
}
/**
* {@inheritdoc}
*/
public static function get_item_id($user)
{
return (int) $user['user_id'];
}
/**
* {@inheritdoc}
*/
public static function get_item_parent_id($post)
{
return 0;
}
/**
* {@inheritdoc}
*/
public function find_users_for_notification($user, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
// Grab admins that have permission to administer users.
$admin_ary = $this->auth->acl_get_list(false, 'a_user', false);
$users = (!empty($admin_ary[0]['a_user'])) ? $admin_ary[0]['a_user'] : array();
// Grab founders
$sql = 'SELECT user_id
FROM ' . USERS_TABLE . '
WHERE user_type = ' . USER_FOUNDER;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($sql))
{
$users[] = (int) $row['user_id'];
}
$this->db->sql_freeresult($result);
if (empty($users))
{
return array();
}
$users = array_unique($users);
return $this->check_user_notification_options($users, $options);
}
/**
* {@inheritdoc}
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->item_id);
}
/**
* {@inheritdoc}
*/
public function get_title()
{
$username = $this->user_loader->get_username($this->item_id, 'no_profile');
return $this->user->lang($this->language_key, $username);
}
/**
* {@inheritdoc}
*/
public function get_email_template()
{
return 'admin_activate';
}
/**
* {@inheritdoc}
*/
public function get_email_template_variables()
{
$board_url = generate_board_url();
$username = $this->user_loader->get_username($this->item_id, 'no_profile');
return array(
'USERNAME' => htmlspecialchars_decode($username),
'U_USER_DETAILS' => "{$board_url}/memberlist.{$this->php_ext}?mode=viewprofile&u={$this->item_id}",
'U_ACTIVATE' => "{$board_url}/ucp.{$this->php_ext}?mode=activate&u={$this->item_id}&k={$this->get_data('user_actkey')}",
);
}
/**
* {@inheritdoc}
*/
public function get_url()
{
return append_sid($this->phpbb_root_path . 'memberlist.' . $this->php_ext, "mode=viewprofile&u={$this->item_id}");
}
/**
* {@inheritdoc}
*/
public function users_to_query()
{
return array($this->item_id);
}
/**
* {@inheritdoc}
*/
public function create_insert_array($user, $pre_create_data)
{
$this->set_data('user_actkey', $user['user_actkey']);
$this->notification_time = $user['user_regdate'];
return parent::create_insert_array($user, $pre_create_data);
}
}