migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,49 @@
<?php
/**
* @copyright Copyright (c) 2021 Carl Schwan <carl@carlschwan.eu>
*
* @author Carl Schwan <carl@carlschwan.eu>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace OC\Settings;
use OCP\AppFramework\Db\Entity;
/**
* @method setGroupId(string $groupId)
* @method setClass(string $class)
* @method getGroupId(): string
* @method getClass(): string
*/
class AuthorizedGroup extends Entity implements \JsonSerializable {
/** @var string $group_id */
protected $groupId;
/** @var string $class */
protected $class;
public function jsonSerialize(): array {
return [
'id' => $this->id,
'group_id' => $this->groupId,
'class' => $this->class
];
}
}
@@ -0,0 +1,128 @@
<?php
/**
* @copyright Copyright (c) 2021 Carl Schwan <carl@carlschwan.eu>
*
* @author Carl Schwan <carl@carlschwan.eu>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace OC\Settings;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
/**
* @template-extends QBMapper<AuthorizedGroup>
*/
class AuthorizedGroupMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'authorized_groups', AuthorizedGroup::class);
}
/**
* @throws Exception
*/
public function findAllClassesForUser(IUser $user): array {
$qb = $this->db->getQueryBuilder();
/** @var IGroupManager $groupManager */
$groupManager = \OC::$server->get(IGroupManager::class);
$groups = $groupManager->getUserGroups($user);
if (count($groups) === 0) {
return [];
}
$result = $qb->select('class')
->from($this->getTableName(), 'auth')
->where($qb->expr()->in('group_id', array_map(function (IGroup $group) use ($qb) {
return $qb->createNamedParameter($group->getGID());
}, $groups), IQueryBuilder::PARAM_STR))
->executeQuery();
$classes = [];
while ($row = $result->fetch()) {
$classes[] = $row['class'];
}
$result->closeCursor();
return $classes;
}
/**
* @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws \OCP\DB\Exception
*/
public function find(int $id): AuthorizedGroup {
$queryBuilder = $this->db->getQueryBuilder();
$queryBuilder->select('*')
->from($this->getTableName())
->where($queryBuilder->expr()->eq('id', $queryBuilder->createNamedParameter($id)));
/** @var AuthorizedGroup $authorizedGroup */
$authorizedGroup = $this->findEntity($queryBuilder);
return $authorizedGroup;
}
/**
* Get all the authorizations stored in the database.
*
* @return AuthorizedGroup[]
* @throws \OCP\DB\Exception
*/
public function findAll(): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')->from($this->getTableName());
return $this->findEntities($qb);
}
public function findByGroupIdAndClass(string $groupId, string $class) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('group_id', $qb->createNamedParameter($groupId)))
->andWhere($qb->expr()->eq('class', $qb->createNamedParameter($class)));
return $this->findEntity($qb);
}
/**
* @return Entity[]
* @throws \OCP\DB\Exception
*/
public function findExistingGroupsForClass(string $class): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('class', $qb->createNamedParameter($class)));
return $this->findEntities($qb);
}
/**
* @throws Exception
*/
public function removeGroup(string $gid) {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->getTableName())
->where($qb->expr()->eq('group_id', $qb->createNamedParameter($gid)))
->executeStatement();
}
}
@@ -0,0 +1,394 @@
<?php
/**
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Julius Härtl <jus@bitgrid.net>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author sualko <klaus@jsxc.org>
* @author Carl Schwan <carl@carlschwan.eu>
* @author Kate Döen <kate.doeen@nextcloud.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Settings;
use Closure;
use OCP\AppFramework\QueryException;
use OCP\Group\ISubAdmin;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IServerContainer;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\L10N\IFactory;
use OCP\Settings\IIconSection;
use OCP\Settings\IManager;
use OCP\Settings\ISettings;
use OCP\Settings\ISubAdminSettings;
use Psr\Log\LoggerInterface;
class Manager implements IManager {
/** @var LoggerInterface */
private $log;
/** @var IL10N */
private $l;
/** @var IFactory */
private $l10nFactory;
/** @var IURLGenerator */
private $url;
/** @var IServerContainer */
private $container;
/** @var AuthorizedGroupMapper $mapper */
private $mapper;
/** @var IGroupManager $groupManager */
private $groupManager;
/** @var ISubAdmin $subAdmin */
private $subAdmin;
public function __construct(
LoggerInterface $log,
IFactory $l10nFactory,
IURLGenerator $url,
IServerContainer $container,
AuthorizedGroupMapper $mapper,
IGroupManager $groupManager,
ISubAdmin $subAdmin
) {
$this->log = $log;
$this->l10nFactory = $l10nFactory;
$this->url = $url;
$this->container = $container;
$this->mapper = $mapper;
$this->groupManager = $groupManager;
$this->subAdmin = $subAdmin;
}
/** @var array<self::SETTINGS_*, list<class-string<IIconSection>>> */
protected $sectionClasses = [];
/** @var array<self::SETTINGS_*, array<string, IIconSection>> */
protected $sections = [];
/**
* @inheritdoc
*/
public function registerSection(string $type, string $section) {
if (!isset($this->sectionClasses[$type])) {
$this->sectionClasses[$type] = [];
}
$this->sectionClasses[$type][] = $section;
}
/**
* @psalm-param self::SETTINGS_* $type
*
* @return IIconSection[]
*/
protected function getSections(string $type): array {
if (!isset($this->sections[$type])) {
$this->sections[$type] = [];
}
if (!isset($this->sectionClasses[$type])) {
return $this->sections[$type];
}
foreach (array_unique($this->sectionClasses[$type]) as $index => $class) {
try {
/** @var IIconSection $section */
$section = $this->container->get($class);
} catch (QueryException $e) {
$this->log->info($e->getMessage(), ['exception' => $e]);
continue;
}
$sectionID = $section->getID();
if (!$this->isKnownDuplicateSectionId($sectionID) && isset($this->sections[$type][$sectionID])) {
$e = new \InvalidArgumentException('Section with the same ID already registered: ' . $sectionID . ', class: ' . $class);
$this->log->info($e->getMessage(), ['exception' => $e]);
continue;
}
$this->sections[$type][$sectionID] = $section;
unset($this->sectionClasses[$type][$index]);
}
return $this->sections[$type];
}
/**
* @inheritdoc
*/
public function getSection(string $type, string $sectionId): ?IIconSection {
if (isset($this->sections[$type]) && isset($this->sections[$type][$sectionId])) {
return $this->sections[$type][$sectionId];
}
return null;
}
protected function isKnownDuplicateSectionId(string $sectionID): bool {
return in_array($sectionID, [
'connected-accounts',
'notifications',
], true);
}
/** @var array<class-string<ISettings>, self::SETTINGS_*> */
protected $settingClasses = [];
/** @var array<self::SETTINGS_*, array<string, list<ISettings>>> */
protected $settings = [];
/**
* @inheritdoc
*/
public function registerSetting(string $type, string $setting) {
$this->settingClasses[$setting] = $type;
}
/**
* @psalm-param self::SETTINGS_* $type The type of the setting.
* @param string $section
* @param ?Closure $filter optional filter to apply on all loaded ISettings
*
* @return ISettings[]
*/
protected function getSettings(string $type, string $section, Closure $filter = null): array {
if (!isset($this->settings[$type])) {
$this->settings[$type] = [];
}
if (!isset($this->settings[$type][$section])) {
$this->settings[$type][$section] = [];
}
foreach ($this->settingClasses as $class => $settingsType) {
if ($type !== $settingsType) {
continue;
}
try {
/** @var ISettings $setting */
$setting = $this->container->get($class);
} catch (QueryException $e) {
$this->log->info($e->getMessage(), ['exception' => $e]);
continue;
}
if (!$setting instanceof ISettings) {
$e = new \InvalidArgumentException('Invalid settings setting registered (' . $class . ')');
$this->log->info($e->getMessage(), ['exception' => $e]);
continue;
}
if ($filter !== null && !$filter($setting)) {
continue;
}
if ($setting->getSection() === null) {
continue;
}
if (!isset($this->settings[$settingsType][$setting->getSection()])) {
$this->settings[$settingsType][$setting->getSection()] = [];
}
$this->settings[$settingsType][$setting->getSection()][] = $setting;
unset($this->settingClasses[$class]);
}
return $this->settings[$type][$section];
}
/**
* @inheritdoc
*/
public function getAdminSections(): array {
// built-in sections
$sections = [];
$appSections = $this->getSections('admin');
foreach ($appSections as $section) {
/** @var IIconSection $section */
if (!isset($sections[$section->getPriority()])) {
$sections[$section->getPriority()] = [];
}
$sections[$section->getPriority()][] = $section;
}
ksort($sections);
return $sections;
}
/**
* @inheritdoc
*/
public function getAdminSettings(string $section, bool $subAdminOnly = false): array {
if ($subAdminOnly) {
$subAdminSettingsFilter = function (ISettings $settings) {
return $settings instanceof ISubAdminSettings;
};
$appSettings = $this->getSettings('admin', $section, $subAdminSettingsFilter);
} else {
$appSettings = $this->getSettings('admin', $section);
}
$settings = [];
foreach ($appSettings as $setting) {
if (!isset($settings[$setting->getPriority()])) {
$settings[$setting->getPriority()] = [];
}
$settings[$setting->getPriority()][] = $setting;
}
ksort($settings);
return $settings;
}
/**
* @inheritdoc
*/
public function getPersonalSections(): array {
if ($this->l === null) {
$this->l = $this->l10nFactory->get('lib');
}
$sections = [];
$legacyForms = \OC_App::getForms('personal');
if ((!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms))
|| count($this->getPersonalSettings('additional')) > 1) {
$sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
}
$appSections = $this->getSections('personal');
foreach ($appSections as $section) {
/** @var IIconSection $section */
if (!isset($sections[$section->getPriority()])) {
$sections[$section->getPriority()] = [];
}
$sections[$section->getPriority()][] = $section;
}
ksort($sections);
return $sections;
}
/**
* @param string[] $forms
*
* @return bool
*/
private function hasLegacyPersonalSettingsToRender(array $forms): bool {
foreach ($forms as $form) {
if (trim($form) !== '') {
return true;
}
}
return false;
}
/**
* @inheritdoc
*/
public function getPersonalSettings(string $section): array {
$settings = [];
$appSettings = $this->getSettings('personal', $section);
foreach ($appSettings as $setting) {
if (!isset($settings[$setting->getPriority()])) {
$settings[$setting->getPriority()] = [];
}
$settings[$setting->getPriority()][] = $setting;
}
ksort($settings);
return $settings;
}
/**
* @inheritdoc
*/
public function getAllowedAdminSettings(string $section, IUser $user): array {
$isAdmin = $this->groupManager->isAdmin($user->getUID());
if ($isAdmin) {
$appSettings = $this->getSettings('admin', $section);
} else {
$authorizedSettingsClasses = $this->mapper->findAllClassesForUser($user);
if ($this->subAdmin->isSubAdmin($user)) {
$authorizedGroupFilter = function (ISettings $settings) use ($authorizedSettingsClasses) {
return $settings instanceof ISubAdminSettings
|| in_array(get_class($settings), $authorizedSettingsClasses) === true;
};
} else {
$authorizedGroupFilter = function (ISettings $settings) use ($authorizedSettingsClasses) {
return in_array(get_class($settings), $authorizedSettingsClasses) === true;
};
}
$appSettings = $this->getSettings('admin', $section, $authorizedGroupFilter);
}
$settings = [];
foreach ($appSettings as $setting) {
if (!isset($settings[$setting->getPriority()])) {
$settings[$setting->getPriority()] = [];
}
$settings[$setting->getPriority()][] = $setting;
}
ksort($settings);
return $settings;
}
/**
* @inheritdoc
*/
public function getAllAllowedAdminSettings(IUser $user): array {
$this->getSettings('admin', ''); // Make sure all the settings are loaded
$settings = [];
$authorizedSettingsClasses = $this->mapper->findAllClassesForUser($user);
foreach ($this->settings['admin'] as $section) {
foreach ($section as $setting) {
if (in_array(get_class($setting), $authorizedSettingsClasses) === true) {
$settings[] = $setting;
}
}
}
return $settings;
}
}
@@ -0,0 +1,88 @@
<?php
/**
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Joas Schilling <coding@schilljs.com>
* @author Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Settings;
use OCP\Settings\IIconSection;
class Section implements IIconSection {
/** @var string */
private $id;
/** @var string */
private $name;
/** @var int */
private $priority;
/** @var string */
private $icon;
/**
* @param string $id
* @param string $name
* @param int $priority
* @param string $icon
*/
public function __construct($id, $name, $priority, $icon = '') {
$this->id = $id;
$this->name = $name;
$this->priority = $priority;
$this->icon = $icon;
}
/**
* @return string The ID of the section. It is supposed to be a lower case string,
* e.g. 'ldap'
*/
public function getID() {
return $this->id;
}
/**
* @return string The translated name as it should be displayed, e.g. 'LDAP / AD
* integration'. Use the L10N service to translate it.
*/
public function getName() {
return $this->name;
}
/**
* @return int whether the form should be rather on the top or bottom of
* the settings navigation. The sections are arranged in ascending order of
* the priority values. It is required to return a value between 0 and 99.
*
* E.g.: 70
*/
public function getPriority() {
return $this->priority;
}
/**
* @return string The relative path to an 16*16 icon describing the section.
* e.g. '/core/img/places/files.svg'
*
* @since 12
*/
public function getIcon() {
return $this->icon;
}
}