-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add username label on shared photos
Fixes #955 Signed-off-by: Jo Van Bulck <[email protected]>
- Loading branch information
1 parent
f1e2669
commit 9a8b709
Showing
13 changed files
with
270 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2022 Varun Patil <[email protected]> | ||
* @author Varun Patil <[email protected]> | ||
* @license AGPL-3.0-or-later | ||
* | ||
* 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 OCA\Memories\Controller; | ||
|
||
use OCA\Memories\Util; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
|
||
class UidController extends GenericApiController | ||
{ | ||
/** | ||
* @NoAdminRequired | ||
* | ||
* @NoCSRFRequired | ||
* | ||
* @PublicPage | ||
* | ||
* Get display name for a Nextcloud user id | ||
* | ||
* @param string fileid | ||
*/ | ||
public function name( | ||
string $uid, | ||
): Http\Response { | ||
return Util::guardEx(static function () use ($uid) { | ||
$userManager = \OC::$server->get(\OCP\IUserManager::class); | ||
$user = $userManager->get($uid); | ||
|
||
return new JSONResponse([ | ||
'user_display' => $user ? $user->getDisplayName() : null, | ||
], Http::STATUS_OK); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2023 Varun Patil <[email protected]> | ||
* @author Varun Patil <[email protected]> | ||
* @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 OCA\Memories\Migration; | ||
|
||
use OCP\DB\ISchemaWrapper; | ||
use OCP\IDBConnection; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
/** | ||
* FIXME Auto-generated migration step: Please modify to your needs! | ||
*/ | ||
class Version800001Date20241026171056 extends SimpleMigrationStep | ||
{ | ||
public function __construct(private IDBConnection $dbc) {} | ||
|
||
/** | ||
* @param \Closure(): ISchemaWrapper $schemaClosure | ||
*/ | ||
public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void {} | ||
|
||
/** | ||
* @param \Closure(): ISchemaWrapper $schemaClosure | ||
*/ | ||
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options): ?ISchemaWrapper | ||
{ | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
if (!$schema->hasTable('memories')) { | ||
throw new \Exception('Memories table does not exist'); | ||
} | ||
|
||
$table = $schema->getTable('memories'); | ||
|
||
if (!$table->hasColumn('uid')) { | ||
$table->addColumn('uid', 'string', [ | ||
'notnull' => false, | ||
'length' => 64, | ||
]); | ||
} | ||
|
||
return $schema; | ||
} | ||
|
||
/** | ||
* @param \Closure(): ISchemaWrapper $schemaClosure | ||
*/ | ||
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void | ||
{ | ||
// create database triggers; this will never throw | ||
\OCA\Memories\Db\AddMissingIndices::createFilecacheTriggers($output); | ||
|
||
// migrate uid values from filecache | ||
try { | ||
$output->info('Migrating values for uid from filecache'); | ||
|
||
$platform = $this->dbc->getDatabasePlatform(); | ||
|
||
// copy existing parent values from filecache | ||
if (preg_match('/mysql|mariadb/i', $platform::class)) { | ||
$this->dbc->executeQuery( | ||
'UPDATE *PREFIX*memories AS m | ||
JOIN *PREFIX*filecache AS f ON f.fileid = m.fileid | ||
JOIN *PREFIX*storages AS s ON f.storage = s.numeric_id | ||
SET m.uid = SUBSTRING_INDEX(s.id, \'::\', -1) | ||
WHERE s.id LIKE \'home::%\' | ||
', | ||
); | ||
} elseif (preg_match('/postgres/i', $platform::class)) { | ||
$this->dbc->executeQuery( | ||
'UPDATE *PREFIX*memories AS m | ||
SET uid = split_part(s.id, \'::\', 2) | ||
FROM *PREFIX*filecache AS f | ||
JOIN *PREFIX*storages AS s ON f.storage = s.numeric_id | ||
WHERE f.fileid = m.fileid | ||
AND s.id LIKE \'home::%\' | ||
', | ||
); | ||
} elseif (preg_match('/sqlite/i', $platform::class)) { | ||
$this->dbc->executeQuery( | ||
'UPDATE memories AS m | ||
SET uid = SUBSTR(s.id, INSTR(s.id, \'::\') + 2) | ||
FROM filecache AS f | ||
JOIN storages AS s ON f.storage = s.numeric_id | ||
WHERE f.fileid = m.fileid | ||
AND s.id LIKE \'home::%\' | ||
', | ||
); | ||
} else { | ||
throw new \Exception('Unsupported '.$platform::class); | ||
} | ||
|
||
$output->info('Values for uid migrated successfully'); | ||
} catch (\Exception $e) { | ||
$output->warning('Failed to copy uid values from fileid: '.$e->getMessage()); | ||
$output->warning('Please run occ memories:index -f'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.