The query condition for active users are unified

This commit is contained in:
Michael 2023-09-08 15:01:51 +00:00
parent 692a633dc8
commit 7e73283949
19 changed files with 33 additions and 37 deletions

View File

@ -34,7 +34,7 @@ function lostpass_post(App $a)
DI::baseUrl()->redirect(); DI::baseUrl()->redirect();
} }
$condition = ['(`email` = ? OR `nickname` = ?) AND `verified` = 1 AND `blocked` = 0 AND `account_removed` = 0 AND `account_expired` = 0', $loginame, $loginame]; $condition = ['(`email` = ? OR `nickname` = ?) AND `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`', $loginame, $loginame];
$user = DBA::selectFirst('user', ['uid', 'username', 'nickname', 'email', 'language'], $condition); $user = DBA::selectFirst('user', ['uid', 'username', 'nickname', 'email', 'language'], $condition);
if (!DBA::isResult($user)) { if (!DBA::isResult($user)) {
DI::sysmsg()->addNotice(DI::l10n()->t('No valid account found.')); DI::sysmsg()->addNotice(DI::l10n()->t('No valid account found.'));

View File

@ -750,7 +750,7 @@ class Contact
$user = DBA::selectFirst( $user = DBA::selectFirst(
'user', 'user',
['uid', 'username', 'nickname', 'pubkey', 'prvkey'], ['uid', 'username', 'nickname', 'pubkey', 'prvkey'],
['uid' => $uid, 'account_expired' => false] ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]
); );
if (!DBA::isResult($user)) { if (!DBA::isResult($user)) {
return false; return false;
@ -822,7 +822,7 @@ class Contact
} }
$fields = ['uid', 'username', 'nickname', 'page-flags', 'account-type', 'prvkey', 'pubkey']; $fields = ['uid', 'username', 'nickname', 'page-flags', 'account-type', 'prvkey', 'pubkey'];
$user = DBA::selectFirst('user', $fields, ['uid' => $uid, 'account_expired' => false]); $user = DBA::selectFirst('user', $fields, ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
if (!DBA::isResult($user)) { if (!DBA::isResult($user)) {
return false; return false;
} }

View File

@ -940,7 +940,7 @@ class Profile
if (!empty($search)) { if (!empty($search)) {
$publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` "); $publish = (DI::config()->get('system', 'publish_all') ? '' : "AND `publish` ");
$searchTerm = '%' . $search . '%'; $searchTerm = '%' . $search . '%';
$condition = ["NOT `blocked` AND NOT `account_removed` $condition = ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`
$publish $publish
AND ((`name` LIKE ?) OR AND ((`name` LIKE ?) OR
(`nickname` LIKE ?) OR (`nickname` LIKE ?) OR
@ -953,7 +953,7 @@ class Profile
$searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
$searchTerm, $searchTerm, $searchTerm, $searchTerm]; $searchTerm, $searchTerm, $searchTerm, $searchTerm];
} else { } else {
$condition = ['blocked' => false, 'account_removed' => false]; $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
if (!DI::config()->get('system', 'publish_all')) { if (!DI::config()->get('system', 'publish_all')) {
$condition['publish'] = true; $condition['publish'] = true;
} }

View File

@ -280,8 +280,7 @@ class User
// List of possible actor names // List of possible actor names
$possible_accounts = ['friendica', 'actor', 'system', 'internal']; $possible_accounts = ['friendica', 'actor', 'system', 'internal'];
foreach ($possible_accounts as $name) { foreach ($possible_accounts as $name) {
if (!DBA::exists('user', ['nickname' => $name, 'account_removed' => false, 'account_expired' => false]) && if (!DBA::exists('user', ['nickname' => $name]) && DBA::exists('userd', ['username' => $name])) {
!DBA::exists('userd', ['username' => $name])) {
DI::config()->set('system', 'actor_name', $name); DI::config()->set('system', 'actor_name', $name);
return $name; return $name;
} }
@ -326,7 +325,7 @@ class User
public static function getByGuid(string $guid, array $fields = [], bool $active = true) public static function getByGuid(string $guid, array $fields = [], bool $active = true)
{ {
if ($active) { if ($active) {
$cond = ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]; $cond = ['guid' => $guid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
} else { } else {
$cond = ['guid' => $guid]; $cond = ['guid' => $guid];
} }
@ -702,7 +701,7 @@ class User
$fields = ['uid', 'nickname', 'password', 'legacy_password']; $fields = ['uid', 'nickname', 'password', 'legacy_password'];
$condition = [ $condition = [
"(`email` = ? OR `username` = ? OR `nickname` = ?) "(`email` = ? OR `username` = ? OR `nickname` = ?)
AND NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `verified`", AND `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`",
$user_info, $user_info, $user_info $user_info, $user_info, $user_info
]; ];
$user = DBA::selectFirst('user', $fields, $condition); $user = DBA::selectFirst('user', $fields, $condition);
@ -738,7 +737,7 @@ class User
if ($user['last-activity'] != $current_day) { if ($user['last-activity'] != $current_day) {
User::update(['last-activity' => $current_day], $uid); User::update(['last-activity' => $current_day], $uid);
// Set the last activity for all identities of the user // Set the last activity for all identities of the user
DBA::update('user', ['last-activity' => $current_day], ['parent-uid' => $uid, 'account_removed' => false]); DBA::update('user', ['last-activity' => $current_day], ['parent-uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
} }
} }
@ -1703,7 +1702,7 @@ class User
$identities = []; $identities = [];
$user = DBA::selectFirst('user', ['uid', 'nickname', 'username', 'parent-uid'], ['uid' => $uid]); $user = DBA::selectFirst('user', ['uid', 'nickname', 'username', 'parent-uid'], ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
if (!DBA::isResult($user)) { if (!DBA::isResult($user)) {
return $identities; return $identities;
} }
@ -1720,7 +1719,7 @@ class User
$r = DBA::select( $r = DBA::select(
'user', 'user',
['uid', 'username', 'nickname'], ['uid', 'username', 'nickname'],
['parent-uid' => $user['uid'], 'account_removed' => false] ['parent-uid' => $user['uid'], 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]
); );
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
$identities = array_merge($identities, DBA::toArray($r)); $identities = array_merge($identities, DBA::toArray($r));
@ -1730,7 +1729,7 @@ class User
$r = DBA::select( $r = DBA::select(
'user', 'user',
['uid', 'username', 'nickname'], ['uid', 'username', 'nickname'],
['uid' => $user['parent-uid'], 'account_removed' => false] ['uid' => $user['parent-uid'], 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]
); );
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
$identities = DBA::toArray($r); $identities = DBA::toArray($r);
@ -1740,7 +1739,7 @@ class User
$r = DBA::select( $r = DBA::select(
'user', 'user',
['uid', 'username', 'nickname'], ['uid', 'username', 'nickname'],
['parent-uid' => $user['parent-uid'], 'account_removed' => false] ['parent-uid' => $user['parent-uid'], 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]
); );
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
$identities = array_merge($identities, DBA::toArray($r)); $identities = array_merge($identities, DBA::toArray($r));
@ -1751,7 +1750,7 @@ class User
"SELECT `user`.`uid`, `user`.`username`, `user`.`nickname` "SELECT `user`.`uid`, `user`.`username`, `user`.`nickname`
FROM `manage` FROM `manage`
INNER JOIN `user` ON `manage`.`mid` = `user`.`uid` INNER JOIN `user` ON `manage`.`mid` = `user`.`uid`
WHERE `user`.`account_removed` = 0 AND `manage`.`uid` = ?", WHERE NOT `user`.`account_removed` AND `manage`.`uid` = ?",
$user['uid'] $user['uid']
); );
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
@ -1773,7 +1772,7 @@ class User
return false; return false;
} }
$user = DBA::selectFirst('user', ['parent-uid'], ['uid' => $uid, 'account_removed' => false]); $user = DBA::selectFirst('user', ['parent-uid'], ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
if (!DBA::isResult($user)) { if (!DBA::isResult($user)) {
return false; return false;
} }
@ -1782,7 +1781,7 @@ class User
return true; return true;
} }
if (DBA::exists('user', ['parent-uid' => $uid, 'account_removed' => false])) { if (DBA::exists('user', ['parent-uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false])) {
return true; return true;
} }

View File

@ -59,7 +59,7 @@ abstract class BaseUsers extends BaseModeration
protected function getTabsHTML(string $selectedTab): string protected function getTabsHTML(string $selectedTab): string
{ {
$all = $this->database->count('user', ["`uid` != ?", 0]); $all = $this->database->count('user', ["`uid` != ?", 0]);
$active = $this->database->count('user', ["NOT `blocked` AND `verified` AND NOT `account_removed` AND `uid` != ?", 0]); $active = $this->database->count('user', ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `uid` != ?", 0]);
$pending = Register::getPendingCount(); $pending = Register::getPendingCount();
$blocked = $this->database->count('user', ['blocked' => true, 'verified' => true, 'account_removed' => false]); $blocked = $this->database->count('user', ['blocked' => true, 'verified' => true, 'account_removed' => false]);
$deleted = $this->database->count('user', ['account_removed' => true]); $deleted = $this->database->count('user', ['account_removed' => true]);

View File

@ -125,7 +125,7 @@ class Active extends BaseUsers
$th_users = array_map(null, [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Type')], $valid_orders); $th_users = array_map(null, [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Type')], $valid_orders);
$count = $this->database->count('user', ["NOT `blocked` AND `verified` AND NOT `account_removed` AND `uid` != ?", 0]); $count = $this->database->count('user', ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `uid` != ?", 0]);
$t = Renderer::getMarkupTemplate('moderation/users/active.tpl'); $t = Renderer::getMarkupTemplate('moderation/users/active.tpl');
return self::getTabsHTML('active') . Renderer::replaceMacros($t, [ return self::getTabsHTML('active') . Renderer::replaceMacros($t, [

View File

@ -63,7 +63,7 @@ class PubSub extends \Friendica\BaseModule
$nickname = $this->parameters['nickname'] ?? ''; $nickname = $this->parameters['nickname'] ?? '';
$contact_id = $this->parameters['cid'] ?? 0; $contact_id = $this->parameters['cid'] ?? 0;
$importer = $this->database->selectFirst('user', [], ['nickname' => $nickname, 'account_expired' => false, 'account_removed' => false]); $importer = $this->database->selectFirst('user', [], ['nickname' => $nickname, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
if (!$importer) { if (!$importer) {
throw new HTTPException\OKException(); throw new HTTPException\OKException();
} }
@ -119,7 +119,7 @@ class PubSub extends \Friendica\BaseModule
$this->logger->notice('Subscription start.', ['from' => $this->request->getRemoteAddress(), 'mode' => $hub_mode, 'nickname' => $nickname]); $this->logger->notice('Subscription start.', ['from' => $this->request->getRemoteAddress(), 'mode' => $hub_mode, 'nickname' => $nickname]);
$this->logger->debug('Data: ', ['get' => $request]); $this->logger->debug('Data: ', ['get' => $request]);
$owner = $this->database->selectFirst('user', ['uid'], ['nickname' => $nickname, 'account_expired' => false, 'account_removed' => false]); $owner = $this->database->selectFirst('user', ['uid'], ['nickname' => $nickname, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
if (!$owner) { if (!$owner) {
$this->logger->notice('Local account not found.', ['nickname' => $nickname]); $this->logger->notice('Local account not found.', ['nickname' => $nickname]);
throw new HTTPException\NotFoundException(); throw new HTTPException\NotFoundException();

View File

@ -111,7 +111,7 @@ class PubSubHubBub extends \Friendica\BaseModule
} }
// fetch user from database given the nickname // fetch user from database given the nickname
$condition = ['nickname' => $nickname, 'account_expired' => false, 'account_removed' => false]; $condition = ['nickname' => $nickname, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
$owner = $this->database->selectFirst('user', ['uid', 'nickname'], $condition); $owner = $this->database->selectFirst('user', ['uid', 'nickname'], $condition);
if (!$owner) { if (!$owner) {
$this->logger->notice('Local account not found', ['nickname' => $nickname, 'topic' => $hub_topic, 'callback' => $hub_callback]); $this->logger->notice('Local account not found', ['nickname' => $nickname, 'topic' => $hub_topic, 'callback' => $hub_callback]);

View File

@ -74,7 +74,7 @@ class Salmon extends \Friendica\BaseModule
$this->logger->debug('New Salmon', ['nickname' => $nickname, 'xml' => $xml]); $this->logger->debug('New Salmon', ['nickname' => $nickname, 'xml' => $xml]);
$importer = $this->database->selectFirst('user', [], ['nickname' => $nickname, 'account_expired' => false, 'account_removed' => false]); $importer = $this->database->selectFirst('user', [], ['nickname' => $nickname, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
if (!$this->database->isResult($importer)) { if (!$this->database->isResult($importer)) {
throw new HTTPException\InternalServerErrorException(); throw new HTTPException\InternalServerErrorException();
} }

View File

@ -81,7 +81,7 @@ class Profile extends BaseProfile
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
if (ActivityPub::isRequest()) { if (ActivityPub::isRequest()) {
$user = $this->database->selectFirst('user', ['uid'], ['nickname' => $this->parameters['nickname'] ?? '', 'account_removed' => false]); $user = $this->database->selectFirst('user', ['uid'], ['nickname' => $this->parameters['nickname'] ?? '', 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
if ($user) { if ($user) {
try { try {
$data = ActivityPub\Transmitter::getProfile($user['uid'], ActivityPub::isAcceptedRequester($user['uid'])); $data = ActivityPub\Transmitter::getProfile($user['uid'], ActivityPub::isAcceptedRequester($user['uid']));

View File

@ -60,7 +60,7 @@ class OpenID extends BaseModule
// in commit 8367cadeeffec4b6792a502847304b17ceba5882, so it might // in commit 8367cadeeffec4b6792a502847304b17ceba5882, so it might
// have left mixed records in the user table // have left mixed records in the user table
// //
$condition = ['blocked' => false, 'account_expired' => false, 'account_removed' => false, 'verified' => true, $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false,
'openid' => [$authId, Strings::normaliseOpenID($authId)]]; 'openid' => [$authId, Strings::normaliseOpenID($authId)]];
$dba = DI::dba(); $dba = DI::dba();

View File

@ -88,7 +88,7 @@ class DFRN
$contact['senderName'] = $contact['name']; $contact['senderName'] = $contact['name'];
if ($uid != 0) { if ($uid != 0) {
$condition = ['uid' => $uid, 'account_expired' => false, 'account_removed' => false]; $condition = ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
$user = DBA::selectFirst('user', [], $condition); $user = DBA::selectFirst('user', [], $condition);
if (!DBA::isResult($user)) { if (!DBA::isResult($user)) {
return []; return [];

View File

@ -3062,10 +3062,7 @@ class Diaspora
// If the item belongs to a user, we take this user id. // If the item belongs to a user, we take this user id.
if ($item['uid'] == 0) { if ($item['uid'] == 0) {
// @todo Possibly use an administrator account? // @todo Possibly use an administrator account?
$condition = [ $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false, 'account-type' => User::ACCOUNT_TYPE_PERSON];
'verified' => true, 'blocked' => false,
'account_removed' => false, 'account_expired' => false, 'account-type' => User::ACCOUNT_TYPE_PERSON
];
$first_user = DBA::selectFirst('user', ['uid'], $condition, ['order' => ['uid']]); $first_user = DBA::selectFirst('user', ['uid'], $condition, ['order' => ['uid']]);
$owner = User::getOwnerDataById($first_user['uid']); $owner = User::getOwnerDataById($first_user['uid']);
} else { } else {

View File

@ -145,7 +145,7 @@ class Cron
DBA::close($users); DBA::close($users);
// Update contact relations for our users // Update contact relations for our users
$users = DBA::select('user', ['uid'], ["NOT `account_expired` AND NOT `account_removed` AND `uid` > ?", 0]); $users = DBA::select('user', ['uid'], ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `uid` > ?", 0]);
while ($user = DBA::fetch($users)) { while ($user = DBA::fetch($users)) {
Worker::add(Worker::PRIORITY_LOW, 'ContactDiscoveryForUser', $user['uid']); Worker::add(Worker::PRIORITY_LOW, 'ContactDiscoveryForUser', $user['uid']);
} }

View File

@ -62,7 +62,7 @@ class Directory
} }
private static function updateAll() { private static function updateAll() {
$users = DBA::select('owner-view', ['url'], ['net-publish' => true, 'account_expired' => false, 'verified' => true]); $users = DBA::select('owner-view', ['url'], ['net-publish' => true, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
while ($user = DBA::fetch($users)) { while ($user = DBA::fetch($users)) {
Worker::add(Worker::PRIORITY_LOW, 'Directory', $user['url']); Worker::add(Worker::PRIORITY_LOW, 'Directory', $user['url']);
} }

View File

@ -42,7 +42,7 @@ class ExpireAndRemoveUsers
DBA::update('user', ['account_expired' => true], $condition); DBA::update('user', ['account_expired' => true], $condition);
// Ensure to never remove the user with uid=0 // Ensure to never remove the user with uid=0
DBA::update('user', ['account_expired' => false, 'account_removed' => false, DBA::update('user', ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false,
'account_expires_on' => DBA::NULL_DATETIME], ['uid' => 0]); 'account_expires_on' => DBA::NULL_DATETIME], ['uid' => 0]);
// Remove any freshly expired account // Remove any freshly expired account

View File

@ -45,10 +45,10 @@ class PollContacts
if (!empty($abandon_days)) { if (!empty($abandon_days)) {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `last-activity` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]); ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `last-activity` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]);
} else { } else {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `blocked` AND NOT `account_expired` AND NOT `account_removed`)", 0]); ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`)", 0]);
} }
$contacts = DBA::select('contact', ['id', 'nick', 'name', 'network', 'archive', 'last-update', 'priority', 'rating'], $condition); $contacts = DBA::select('contact', ['id', 'nick', 'name', 'network', 'archive', 'last-update', 'priority', 'rating'], $condition);

View File

@ -31,7 +31,7 @@ class UpdatePhotoAlbums
{ {
public static function execute() public static function execute()
{ {
$users = DBA::select('user', ['uid'], ['account_expired' => false, 'account_removed' => false]); $users = DBA::select('user', ['uid'], ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false]);
while ($user = DBA::fetch($users)) { while ($user = DBA::fetch($users)) {
Photo::clearAlbumCache($user['uid']); Photo::clearAlbumCache($user['uid']);
} }

View File

@ -35,7 +35,7 @@ class UpdateScores
{ {
Logger::notice('Start score update'); Logger::notice('Start score update');
$users = DBA::select('user', ['uid'], ["NOT `account_expired` AND NOT `account_removed` AND `uid` > ?", 0]); $users = DBA::select('user', ['uid'], ["`verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired` AND `uid` > ?", 0]);
while ($user = DBA::fetch($users)) { while ($user = DBA::fetch($users)) {
Relation::calculateInteractionScore($user['uid']); Relation::calculateInteractionScore($user['uid']);
} }