DB migration for search_stream permission

This commit is contained in:
Mike Macgirvin 2023-01-25 20:48:19 +11:00
parent 4b9d53e44f
commit e3ed20c49e
2 changed files with 40 additions and 2 deletions

39
Code/Update/_1266.php Normal file
View file

@ -0,0 +1,39 @@
<?php
namespace Code\Update;
use Code\Lib\AbConfig;
use Code\Lib\PConfig;
class _1266
{
// This update adds the 'search_stream' permission to existing connections.
public function run()
{
$r = q("SELECT * from channel where true");
if ($r) {
foreach ($r as $rv) {
PConfig::Set($rv['channel_id'], 'perm_limits', 'search_stream', PERMS_SPECIFIC);
}
}
$r = q("SELECT * from abook where abook_self = 0");
if ($r) {
foreach ($r as $rv) {
$perms = AbConfig::Get($rv['abook_channel'], $rv['abook_xchan'], 'system', 'my_perms', [] );
$s = explode(',', $perms);
if (in_array('view_stream', $s) && (! in_array('search_stream', $s))) {
$s[] = 'search_stream';
}
AbConfig::Set($rv['abook_channel'], $rv['abook_xchan'], 'system', 'my_perms', implode(',', $s));
}
}
return UPDATE_SUCCESS;
}
public function verify()
{
return true;
}
}

View file

@ -24,9 +24,8 @@ use Code\Lib\Url;
* @brief This file defines some global constants and includes the central App class.
*/
const REPOSITORY_ID = 'streams';
const DB_UPDATE_VERSION = 1265;
const DB_UPDATE_VERSION = 1266;
const PROJECT_BASE = __DIR__;
const ACTIVITYPUB_ENABLED = true;
const NOMAD_PROTOCOL_VERSION = '11.0';