@@ -63,7 +63,7 @@ |
||
63 | 63 | $managerProvider = $this->managerProvider; |
64 | 64 | $manager = $managerProvider(); |
65 | 65 | $data['manager'] = $manager; |
66 | - $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/'); |
|
66 | + $mountPoint = '/'.$user->getUID().'/files/'.ltrim($data['mountpoint'], '/'); |
|
67 | 67 | $data['mountpoint'] = $mountPoint; |
68 | 68 | $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); |
69 | 69 | $data['certificateManager'] = \OC::$server->getCertificateManager(); |
@@ -16,52 +16,52 @@ |
||
16 | 16 | use OCP\Server; |
17 | 17 | |
18 | 18 | class MountProvider implements IMountProvider { |
19 | - public const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
19 | + public const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var callable |
|
23 | - */ |
|
24 | - private $managerProvider; |
|
21 | + /** |
|
22 | + * @var callable |
|
23 | + */ |
|
24 | + private $managerProvider; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param IDBConnection $connection |
|
28 | - * @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself |
|
29 | - * @param ICloudIdManager $cloudIdManager |
|
30 | - */ |
|
31 | - public function __construct( |
|
32 | - private IDBConnection $connection, |
|
33 | - callable $managerProvider, |
|
34 | - private ICloudIdManager $cloudIdManager, |
|
35 | - ) { |
|
36 | - $this->managerProvider = $managerProvider; |
|
37 | - } |
|
26 | + /** |
|
27 | + * @param IDBConnection $connection |
|
28 | + * @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself |
|
29 | + * @param ICloudIdManager $cloudIdManager |
|
30 | + */ |
|
31 | + public function __construct( |
|
32 | + private IDBConnection $connection, |
|
33 | + callable $managerProvider, |
|
34 | + private ICloudIdManager $cloudIdManager, |
|
35 | + ) { |
|
36 | + $this->managerProvider = $managerProvider; |
|
37 | + } |
|
38 | 38 | |
39 | - public function getMount(IUser $user, $data, IStorageFactory $storageFactory) { |
|
40 | - $managerProvider = $this->managerProvider; |
|
41 | - $manager = $managerProvider(); |
|
42 | - $data['manager'] = $manager; |
|
43 | - $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/'); |
|
44 | - $data['mountpoint'] = $mountPoint; |
|
45 | - $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); |
|
46 | - $data['certificateManager'] = \OC::$server->getCertificateManager(); |
|
47 | - $data['HttpClientService'] = Server::get(IClientService::class); |
|
48 | - return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory); |
|
49 | - } |
|
39 | + public function getMount(IUser $user, $data, IStorageFactory $storageFactory) { |
|
40 | + $managerProvider = $this->managerProvider; |
|
41 | + $manager = $managerProvider(); |
|
42 | + $data['manager'] = $manager; |
|
43 | + $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/'); |
|
44 | + $data['mountpoint'] = $mountPoint; |
|
45 | + $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); |
|
46 | + $data['certificateManager'] = \OC::$server->getCertificateManager(); |
|
47 | + $data['HttpClientService'] = Server::get(IClientService::class); |
|
48 | + return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory); |
|
49 | + } |
|
50 | 50 | |
51 | - public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
52 | - $qb = $this->connection->getQueryBuilder(); |
|
53 | - $qb->select('remote', 'share_token', 'password', 'mountpoint', 'owner') |
|
54 | - ->from('share_external') |
|
55 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($user->getUID()))) |
|
56 | - ->andWhere($qb->expr()->eq('accepted', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT))); |
|
57 | - $result = $qb->executeQuery(); |
|
58 | - $mounts = []; |
|
59 | - while ($row = $result->fetch()) { |
|
60 | - $row['manager'] = $this; |
|
61 | - $row['token'] = $row['share_token']; |
|
62 | - $mounts[] = $this->getMount($user, $row, $loader); |
|
63 | - } |
|
64 | - $result->closeCursor(); |
|
65 | - return $mounts; |
|
66 | - } |
|
51 | + public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
52 | + $qb = $this->connection->getQueryBuilder(); |
|
53 | + $qb->select('remote', 'share_token', 'password', 'mountpoint', 'owner') |
|
54 | + ->from('share_external') |
|
55 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($user->getUID()))) |
|
56 | + ->andWhere($qb->expr()->eq('accepted', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT))); |
|
57 | + $result = $qb->executeQuery(); |
|
58 | + $mounts = []; |
|
59 | + while ($row = $result->fetch()) { |
|
60 | + $row['manager'] = $this; |
|
61 | + $row['token'] = $row['share_token']; |
|
62 | + $mounts[] = $this->getMount($user, $row, $loader); |
|
63 | + } |
|
64 | + $result->closeCursor(); |
|
65 | + return $mounts; |
|
66 | + } |
|
67 | 67 | } |
@@ -94,7 +94,7 @@ |
||
94 | 94 | * @param bool $httpOnly |
95 | 95 | */ |
96 | 96 | public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite = 'Lax') { |
97 | - $path = $this->webRoot ? : '/'; |
|
97 | + $path = $this->webRoot ?: '/'; |
|
98 | 98 | |
99 | 99 | setcookie($name, $value, [ |
100 | 100 | 'expires' => $expire, |
@@ -13,72 +13,72 @@ |
||
13 | 13 | * Very thin wrapper class to make output testable |
14 | 14 | */ |
15 | 15 | class Output implements IOutput { |
16 | - public function __construct( |
|
17 | - private string $webRoot, |
|
18 | - ) { |
|
19 | - } |
|
16 | + public function __construct( |
|
17 | + private string $webRoot, |
|
18 | + ) { |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param string $out |
|
23 | - */ |
|
24 | - public function setOutput($out) { |
|
25 | - print($out); |
|
26 | - } |
|
21 | + /** |
|
22 | + * @param string $out |
|
23 | + */ |
|
24 | + public function setOutput($out) { |
|
25 | + print($out); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param string|resource $path or file handle |
|
30 | - * |
|
31 | - * @return bool false if an error occurred |
|
32 | - */ |
|
33 | - public function setReadfile($path) { |
|
34 | - if (is_resource($path)) { |
|
35 | - $output = fopen('php://output', 'w'); |
|
36 | - return stream_copy_to_stream($path, $output) > 0; |
|
37 | - } else { |
|
38 | - return @readfile($path); |
|
39 | - } |
|
40 | - } |
|
28 | + /** |
|
29 | + * @param string|resource $path or file handle |
|
30 | + * |
|
31 | + * @return bool false if an error occurred |
|
32 | + */ |
|
33 | + public function setReadfile($path) { |
|
34 | + if (is_resource($path)) { |
|
35 | + $output = fopen('php://output', 'w'); |
|
36 | + return stream_copy_to_stream($path, $output) > 0; |
|
37 | + } else { |
|
38 | + return @readfile($path); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param string $header |
|
44 | - */ |
|
45 | - public function setHeader($header) { |
|
46 | - header($header); |
|
47 | - } |
|
42 | + /** |
|
43 | + * @param string $header |
|
44 | + */ |
|
45 | + public function setHeader($header) { |
|
46 | + header($header); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param int $code sets the http status code |
|
51 | - */ |
|
52 | - public function setHttpResponseCode($code) { |
|
53 | - http_response_code($code); |
|
54 | - } |
|
49 | + /** |
|
50 | + * @param int $code sets the http status code |
|
51 | + */ |
|
52 | + public function setHttpResponseCode($code) { |
|
53 | + http_response_code($code); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return int returns the current http response code |
|
58 | - */ |
|
59 | - public function getHttpResponseCode() { |
|
60 | - return http_response_code(); |
|
61 | - } |
|
56 | + /** |
|
57 | + * @return int returns the current http response code |
|
58 | + */ |
|
59 | + public function getHttpResponseCode() { |
|
60 | + return http_response_code(); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param string $name |
|
65 | - * @param string $value |
|
66 | - * @param int $expire |
|
67 | - * @param string $path |
|
68 | - * @param string $domain |
|
69 | - * @param bool $secure |
|
70 | - * @param bool $httpOnly |
|
71 | - */ |
|
72 | - public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite = 'Lax') { |
|
73 | - $path = $this->webRoot ? : '/'; |
|
63 | + /** |
|
64 | + * @param string $name |
|
65 | + * @param string $value |
|
66 | + * @param int $expire |
|
67 | + * @param string $path |
|
68 | + * @param string $domain |
|
69 | + * @param bool $secure |
|
70 | + * @param bool $httpOnly |
|
71 | + */ |
|
72 | + public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite = 'Lax') { |
|
73 | + $path = $this->webRoot ? : '/'; |
|
74 | 74 | |
75 | - setcookie($name, $value, [ |
|
76 | - 'expires' => $expire, |
|
77 | - 'path' => $path, |
|
78 | - 'domain' => $domain, |
|
79 | - 'secure' => $secure, |
|
80 | - 'httponly' => $httpOnly, |
|
81 | - 'samesite' => $sameSite |
|
82 | - ]); |
|
83 | - } |
|
75 | + setcookie($name, $value, [ |
|
76 | + 'expires' => $expire, |
|
77 | + 'path' => $path, |
|
78 | + 'domain' => $domain, |
|
79 | + 'secure' => $secure, |
|
80 | + 'httponly' => $httpOnly, |
|
81 | + 'samesite' => $sameSite |
|
82 | + ]); |
|
83 | + } |
|
84 | 84 | } |
@@ -34,19 +34,19 @@ |
||
34 | 34 | use OCP\Migration\SimpleMigrationStep; |
35 | 35 | |
36 | 36 | class Version14000Date20180710092004 extends SimpleMigrationStep { |
37 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
38 | - /** @var ISchemaWrapper $schema */ |
|
39 | - $schema = $schemaClosure(); |
|
37 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
38 | + /** @var ISchemaWrapper $schema */ |
|
39 | + $schema = $schemaClosure(); |
|
40 | 40 | |
41 | - $table = $schema->getTable('share'); |
|
41 | + $table = $schema->getTable('share'); |
|
42 | 42 | |
43 | - if (!$table->hasColumn('password_by_talk')) { |
|
44 | - $table->addColumn('password_by_talk', Types::BOOLEAN, [ |
|
45 | - 'default' => 0, |
|
46 | - 'notnull' => false, |
|
47 | - ]); |
|
48 | - } |
|
43 | + if (!$table->hasColumn('password_by_talk')) { |
|
44 | + $table->addColumn('password_by_talk', Types::BOOLEAN, [ |
|
45 | + 'default' => 0, |
|
46 | + 'notnull' => false, |
|
47 | + ]); |
|
48 | + } |
|
49 | 49 | |
50 | - return $schema; |
|
51 | - } |
|
50 | + return $schema; |
|
51 | + } |
|
52 | 52 | } |
@@ -32,30 +32,30 @@ |
||
32 | 32 | use OCP\Migration\SimpleMigrationStep; |
33 | 33 | |
34 | 34 | class Version1016Date20201109085907 extends SimpleMigrationStep { |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
44 | - |
|
45 | - $result = $this->ensureColumnIsNullable($schema, 'calendar_reminders', 'is_recurring'); |
|
46 | - |
|
47 | - return $result ? $schema : null; |
|
48 | - } |
|
49 | - |
|
50 | - protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool { |
|
51 | - $table = $schema->getTable($tableName); |
|
52 | - $column = $table->getColumn($columnName); |
|
53 | - |
|
54 | - if ($column->getNotnull()) { |
|
55 | - $column->setNotnull(false); |
|
56 | - return true; |
|
57 | - } |
|
58 | - |
|
59 | - return false; |
|
60 | - } |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | + |
|
45 | + $result = $this->ensureColumnIsNullable($schema, 'calendar_reminders', 'is_recurring'); |
|
46 | + |
|
47 | + return $result ? $schema : null; |
|
48 | + } |
|
49 | + |
|
50 | + protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool { |
|
51 | + $table = $schema->getTable($tableName); |
|
52 | + $column = $table->getColumn($columnName); |
|
53 | + |
|
54 | + if ($column->getNotnull()) { |
|
55 | + $column->setNotnull(false); |
|
56 | + return true; |
|
57 | + } |
|
58 | + |
|
59 | + return false; |
|
60 | + } |
|
61 | 61 | } |
@@ -32,30 +32,30 @@ |
||
32 | 32 | use OCP\Migration\SimpleMigrationStep; |
33 | 33 | |
34 | 34 | class Version20000Date20201111081915 extends SimpleMigrationStep { |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
44 | - |
|
45 | - $result = $this->ensureColumnIsNullable($schema, 'direct_edit', 'accessed'); |
|
46 | - |
|
47 | - return $result ? $schema : null; |
|
48 | - } |
|
49 | - |
|
50 | - protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool { |
|
51 | - $table = $schema->getTable($tableName); |
|
52 | - $column = $table->getColumn($columnName); |
|
53 | - |
|
54 | - if ($column->getNotnull()) { |
|
55 | - $column->setNotnull(false); |
|
56 | - return true; |
|
57 | - } |
|
58 | - |
|
59 | - return false; |
|
60 | - } |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | + |
|
45 | + $result = $this->ensureColumnIsNullable($schema, 'direct_edit', 'accessed'); |
|
46 | + |
|
47 | + return $result ? $schema : null; |
|
48 | + } |
|
49 | + |
|
50 | + protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool { |
|
51 | + $table = $schema->getTable($tableName); |
|
52 | + $column = $table->getColumn($columnName); |
|
53 | + |
|
54 | + if ($column->getNotnull()) { |
|
55 | + $column->setNotnull(false); |
|
56 | + return true; |
|
57 | + } |
|
58 | + |
|
59 | + return false; |
|
60 | + } |
|
61 | 61 | } |
@@ -37,61 +37,61 @@ |
||
37 | 37 | */ |
38 | 38 | class Version0001Date20200602134824 extends SimpleMigrationStep { |
39 | 39 | |
40 | - /** |
|
41 | - * @param IOutput $output |
|
42 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
43 | - * @param array $options |
|
44 | - * @return null|ISchemaWrapper |
|
45 | - * @since 20.0.0 |
|
46 | - */ |
|
47 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
48 | - /** @var ISchemaWrapper $schema */ |
|
49 | - $schema = $schemaClosure(); |
|
40 | + /** |
|
41 | + * @param IOutput $output |
|
42 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
43 | + * @param array $options |
|
44 | + * @return null|ISchemaWrapper |
|
45 | + * @since 20.0.0 |
|
46 | + */ |
|
47 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
48 | + /** @var ISchemaWrapper $schema */ |
|
49 | + $schema = $schemaClosure(); |
|
50 | 50 | |
51 | - $statusTable = $schema->createTable('user_status'); |
|
52 | - $statusTable->addColumn('id', Types::BIGINT, [ |
|
53 | - 'autoincrement' => true, |
|
54 | - 'notnull' => true, |
|
55 | - 'length' => 20, |
|
56 | - 'unsigned' => true, |
|
57 | - ]); |
|
58 | - $statusTable->addColumn('user_id', Types::STRING, [ |
|
59 | - 'notnull' => true, |
|
60 | - 'length' => 255, |
|
61 | - ]); |
|
62 | - $statusTable->addColumn('status', Types::STRING, [ |
|
63 | - 'notnull' => true, |
|
64 | - 'length' => 255, |
|
65 | - ]); |
|
66 | - $statusTable->addColumn('status_timestamp', Types::INTEGER, [ |
|
67 | - 'notnull' => true, |
|
68 | - 'length' => 11, |
|
69 | - 'unsigned' => true, |
|
70 | - ]); |
|
71 | - $statusTable->addColumn('is_user_defined', Types::BOOLEAN, [ |
|
72 | - 'notnull' => false, |
|
73 | - ]); |
|
74 | - $statusTable->addColumn('message_id', Types::STRING, [ |
|
75 | - 'notnull' => false, |
|
76 | - 'length' => 255, |
|
77 | - ]); |
|
78 | - $statusTable->addColumn('custom_icon', Types::STRING, [ |
|
79 | - 'notnull' => false, |
|
80 | - 'length' => 255, |
|
81 | - ]); |
|
82 | - $statusTable->addColumn('custom_message', Types::TEXT, [ |
|
83 | - 'notnull' => false, |
|
84 | - ]); |
|
85 | - $statusTable->addColumn('clear_at', Types::INTEGER, [ |
|
86 | - 'notnull' => false, |
|
87 | - 'length' => 11, |
|
88 | - 'unsigned' => true, |
|
89 | - ]); |
|
51 | + $statusTable = $schema->createTable('user_status'); |
|
52 | + $statusTable->addColumn('id', Types::BIGINT, [ |
|
53 | + 'autoincrement' => true, |
|
54 | + 'notnull' => true, |
|
55 | + 'length' => 20, |
|
56 | + 'unsigned' => true, |
|
57 | + ]); |
|
58 | + $statusTable->addColumn('user_id', Types::STRING, [ |
|
59 | + 'notnull' => true, |
|
60 | + 'length' => 255, |
|
61 | + ]); |
|
62 | + $statusTable->addColumn('status', Types::STRING, [ |
|
63 | + 'notnull' => true, |
|
64 | + 'length' => 255, |
|
65 | + ]); |
|
66 | + $statusTable->addColumn('status_timestamp', Types::INTEGER, [ |
|
67 | + 'notnull' => true, |
|
68 | + 'length' => 11, |
|
69 | + 'unsigned' => true, |
|
70 | + ]); |
|
71 | + $statusTable->addColumn('is_user_defined', Types::BOOLEAN, [ |
|
72 | + 'notnull' => false, |
|
73 | + ]); |
|
74 | + $statusTable->addColumn('message_id', Types::STRING, [ |
|
75 | + 'notnull' => false, |
|
76 | + 'length' => 255, |
|
77 | + ]); |
|
78 | + $statusTable->addColumn('custom_icon', Types::STRING, [ |
|
79 | + 'notnull' => false, |
|
80 | + 'length' => 255, |
|
81 | + ]); |
|
82 | + $statusTable->addColumn('custom_message', Types::TEXT, [ |
|
83 | + 'notnull' => false, |
|
84 | + ]); |
|
85 | + $statusTable->addColumn('clear_at', Types::INTEGER, [ |
|
86 | + 'notnull' => false, |
|
87 | + 'length' => 11, |
|
88 | + 'unsigned' => true, |
|
89 | + ]); |
|
90 | 90 | |
91 | - $statusTable->setPrimaryKey(['id']); |
|
92 | - $statusTable->addUniqueIndex(['user_id'], 'user_status_uid_ix'); |
|
93 | - $statusTable->addIndex(['clear_at'], 'user_status_clr_ix'); |
|
91 | + $statusTable->setPrimaryKey(['id']); |
|
92 | + $statusTable->addUniqueIndex(['user_id'], 'user_status_uid_ix'); |
|
93 | + $statusTable->addIndex(['clear_at'], 'user_status_clr_ix'); |
|
94 | 94 | |
95 | - return $schema; |
|
96 | - } |
|
95 | + return $schema; |
|
96 | + } |
|
97 | 97 | } |
@@ -33,30 +33,30 @@ |
||
33 | 33 | |
34 | 34 | class Version1000Date20201111130204 extends SimpleMigrationStep { |
35 | 35 | |
36 | - /** |
|
37 | - * @param IOutput $output |
|
38 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
39 | - * @param array $options |
|
40 | - * @return null|ISchemaWrapper |
|
41 | - */ |
|
42 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
43 | - /** @var ISchemaWrapper $schema */ |
|
44 | - $schema = $schemaClosure(); |
|
45 | - |
|
46 | - $result = $this->ensureColumnIsNullable($schema, 'user_status', 'is_user_defined'); |
|
47 | - |
|
48 | - return $result ? $schema : null; |
|
49 | - } |
|
50 | - |
|
51 | - protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool { |
|
52 | - $table = $schema->getTable($tableName); |
|
53 | - $column = $table->getColumn($columnName); |
|
54 | - |
|
55 | - if ($column->getNotnull()) { |
|
56 | - $column->setNotnull(false); |
|
57 | - return true; |
|
58 | - } |
|
59 | - |
|
60 | - return false; |
|
61 | - } |
|
36 | + /** |
|
37 | + * @param IOutput $output |
|
38 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
39 | + * @param array $options |
|
40 | + * @return null|ISchemaWrapper |
|
41 | + */ |
|
42 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
43 | + /** @var ISchemaWrapper $schema */ |
|
44 | + $schema = $schemaClosure(); |
|
45 | + |
|
46 | + $result = $this->ensureColumnIsNullable($schema, 'user_status', 'is_user_defined'); |
|
47 | + |
|
48 | + return $result ? $schema : null; |
|
49 | + } |
|
50 | + |
|
51 | + protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool { |
|
52 | + $table = $schema->getTable($tableName); |
|
53 | + $column = $table->getColumn($columnName); |
|
54 | + |
|
55 | + if ($column->getNotnull()) { |
|
56 | + $column->setNotnull(false); |
|
57 | + return true; |
|
58 | + } |
|
59 | + |
|
60 | + return false; |
|
61 | + } |
|
62 | 62 | } |
@@ -152,7 +152,7 @@ |
||
152 | 152 | |
153 | 153 | public function copyObject($from, $to) { |
154 | 154 | $this->getContainer()->getObject($from)->copy([ |
155 | - 'destination' => $this->getContainer()->name . '/' . $to |
|
155 | + 'destination' => $this->getContainer()->name.'/'.$to |
|
156 | 156 | ]); |
157 | 157 | } |
158 | 158 | } |
@@ -19,119 +19,119 @@ |
||
19 | 19 | const SWIFT_SEGMENT_SIZE = 1073741824; // 1GB |
20 | 20 | |
21 | 21 | class Swift implements IObjectStore { |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - private $params; |
|
26 | - |
|
27 | - /** @var SwiftFactory */ |
|
28 | - private $swiftFactory; |
|
29 | - |
|
30 | - public function __construct($params, ?SwiftFactory $connectionFactory = null) { |
|
31 | - $this->swiftFactory = $connectionFactory ?: new SwiftFactory( |
|
32 | - \OC::$server->getMemCacheFactory()->createDistributed('swift::'), |
|
33 | - $params, |
|
34 | - \OC::$server->get(LoggerInterface::class) |
|
35 | - ); |
|
36 | - $this->params = $params; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * @return \OpenStack\ObjectStore\v1\Models\Container |
|
41 | - * @throws StorageAuthException |
|
42 | - * @throws \OCP\Files\StorageNotAvailableException |
|
43 | - */ |
|
44 | - private function getContainer() { |
|
45 | - return $this->swiftFactory->getContainer(); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @return string the container name where objects are stored |
|
50 | - */ |
|
51 | - public function getStorageId() { |
|
52 | - if (isset($this->params['bucket'])) { |
|
53 | - return $this->params['bucket']; |
|
54 | - } |
|
55 | - |
|
56 | - return $this->params['container']; |
|
57 | - } |
|
58 | - |
|
59 | - public function writeObject($urn, $stream, ?string $mimetype = null) { |
|
60 | - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('swiftwrite'); |
|
61 | - file_put_contents($tmpFile, $stream); |
|
62 | - $handle = fopen($tmpFile, 'rb'); |
|
63 | - |
|
64 | - if (filesize($tmpFile) < SWIFT_SEGMENT_SIZE) { |
|
65 | - $this->getContainer()->createObject([ |
|
66 | - 'name' => $urn, |
|
67 | - 'stream' => Utils::streamFor($handle), |
|
68 | - 'contentType' => $mimetype, |
|
69 | - ]); |
|
70 | - } else { |
|
71 | - $this->getContainer()->createLargeObject([ |
|
72 | - 'name' => $urn, |
|
73 | - 'stream' => Utils::streamFor($handle), |
|
74 | - 'segmentSize' => SWIFT_SEGMENT_SIZE, |
|
75 | - 'contentType' => $mimetype, |
|
76 | - ]); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @param string $urn the unified resource name used to identify the object |
|
82 | - * @return resource stream with the read data |
|
83 | - * @throws \Exception from openstack or GuzzleHttp libs when something goes wrong |
|
84 | - * @throws NotFoundException if file does not exist |
|
85 | - */ |
|
86 | - public function readObject($urn) { |
|
87 | - try { |
|
88 | - $publicUri = $this->getContainer()->getObject($urn)->getPublicUri(); |
|
89 | - $tokenId = $this->swiftFactory->getCachedTokenId(); |
|
90 | - |
|
91 | - $response = (new Client())->request('GET', $publicUri, |
|
92 | - [ |
|
93 | - 'stream' => true, |
|
94 | - 'headers' => [ |
|
95 | - 'X-Auth-Token' => $tokenId, |
|
96 | - 'Cache-Control' => 'no-cache', |
|
97 | - ], |
|
98 | - ] |
|
99 | - ); |
|
100 | - } catch (BadResponseException $e) { |
|
101 | - if ($e->getResponse() && $e->getResponse()->getStatusCode() === 404) { |
|
102 | - throw new NotFoundException("object $urn not found in object store"); |
|
103 | - } else { |
|
104 | - throw $e; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - return RetryWrapper::wrap($response->getBody()->detach()); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @param string $urn Unified Resource Name |
|
113 | - * @return void |
|
114 | - * @throws \Exception from openstack lib when something goes wrong |
|
115 | - */ |
|
116 | - public function deleteObject($urn) { |
|
117 | - $this->getContainer()->getObject($urn)->delete(); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return void |
|
122 | - * @throws \Exception from openstack lib when something goes wrong |
|
123 | - */ |
|
124 | - public function deleteContainer() { |
|
125 | - $this->getContainer()->delete(); |
|
126 | - } |
|
127 | - |
|
128 | - public function objectExists($urn) { |
|
129 | - return $this->getContainer()->objectExists($urn); |
|
130 | - } |
|
131 | - |
|
132 | - public function copyObject($from, $to) { |
|
133 | - $this->getContainer()->getObject($from)->copy([ |
|
134 | - 'destination' => $this->getContainer()->name . '/' . $to |
|
135 | - ]); |
|
136 | - } |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + private $params; |
|
26 | + |
|
27 | + /** @var SwiftFactory */ |
|
28 | + private $swiftFactory; |
|
29 | + |
|
30 | + public function __construct($params, ?SwiftFactory $connectionFactory = null) { |
|
31 | + $this->swiftFactory = $connectionFactory ?: new SwiftFactory( |
|
32 | + \OC::$server->getMemCacheFactory()->createDistributed('swift::'), |
|
33 | + $params, |
|
34 | + \OC::$server->get(LoggerInterface::class) |
|
35 | + ); |
|
36 | + $this->params = $params; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * @return \OpenStack\ObjectStore\v1\Models\Container |
|
41 | + * @throws StorageAuthException |
|
42 | + * @throws \OCP\Files\StorageNotAvailableException |
|
43 | + */ |
|
44 | + private function getContainer() { |
|
45 | + return $this->swiftFactory->getContainer(); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @return string the container name where objects are stored |
|
50 | + */ |
|
51 | + public function getStorageId() { |
|
52 | + if (isset($this->params['bucket'])) { |
|
53 | + return $this->params['bucket']; |
|
54 | + } |
|
55 | + |
|
56 | + return $this->params['container']; |
|
57 | + } |
|
58 | + |
|
59 | + public function writeObject($urn, $stream, ?string $mimetype = null) { |
|
60 | + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('swiftwrite'); |
|
61 | + file_put_contents($tmpFile, $stream); |
|
62 | + $handle = fopen($tmpFile, 'rb'); |
|
63 | + |
|
64 | + if (filesize($tmpFile) < SWIFT_SEGMENT_SIZE) { |
|
65 | + $this->getContainer()->createObject([ |
|
66 | + 'name' => $urn, |
|
67 | + 'stream' => Utils::streamFor($handle), |
|
68 | + 'contentType' => $mimetype, |
|
69 | + ]); |
|
70 | + } else { |
|
71 | + $this->getContainer()->createLargeObject([ |
|
72 | + 'name' => $urn, |
|
73 | + 'stream' => Utils::streamFor($handle), |
|
74 | + 'segmentSize' => SWIFT_SEGMENT_SIZE, |
|
75 | + 'contentType' => $mimetype, |
|
76 | + ]); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @param string $urn the unified resource name used to identify the object |
|
82 | + * @return resource stream with the read data |
|
83 | + * @throws \Exception from openstack or GuzzleHttp libs when something goes wrong |
|
84 | + * @throws NotFoundException if file does not exist |
|
85 | + */ |
|
86 | + public function readObject($urn) { |
|
87 | + try { |
|
88 | + $publicUri = $this->getContainer()->getObject($urn)->getPublicUri(); |
|
89 | + $tokenId = $this->swiftFactory->getCachedTokenId(); |
|
90 | + |
|
91 | + $response = (new Client())->request('GET', $publicUri, |
|
92 | + [ |
|
93 | + 'stream' => true, |
|
94 | + 'headers' => [ |
|
95 | + 'X-Auth-Token' => $tokenId, |
|
96 | + 'Cache-Control' => 'no-cache', |
|
97 | + ], |
|
98 | + ] |
|
99 | + ); |
|
100 | + } catch (BadResponseException $e) { |
|
101 | + if ($e->getResponse() && $e->getResponse()->getStatusCode() === 404) { |
|
102 | + throw new NotFoundException("object $urn not found in object store"); |
|
103 | + } else { |
|
104 | + throw $e; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + return RetryWrapper::wrap($response->getBody()->detach()); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @param string $urn Unified Resource Name |
|
113 | + * @return void |
|
114 | + * @throws \Exception from openstack lib when something goes wrong |
|
115 | + */ |
|
116 | + public function deleteObject($urn) { |
|
117 | + $this->getContainer()->getObject($urn)->delete(); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return void |
|
122 | + * @throws \Exception from openstack lib when something goes wrong |
|
123 | + */ |
|
124 | + public function deleteContainer() { |
|
125 | + $this->getContainer()->delete(); |
|
126 | + } |
|
127 | + |
|
128 | + public function objectExists($urn) { |
|
129 | + return $this->getContainer()->objectExists($urn); |
|
130 | + } |
|
131 | + |
|
132 | + public function copyObject($from, $to) { |
|
133 | + $this->getContainer()->getObject($from)->copy([ |
|
134 | + 'destination' => $this->getContainer()->name . '/' . $to |
|
135 | + ]); |
|
136 | + } |
|
137 | 137 | } |
@@ -46,7 +46,7 @@ |
||
46 | 46 | if ($defaultExpireDate === 'yes') { |
47 | 47 | $enforceExpireDate = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
48 | 48 | $defaultExpireSettings['defaultExpireDateSet'] = true; |
49 | - $defaultExpireSettings['expireAfterDays'] = (int)$config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
49 | + $defaultExpireSettings['expireAfterDays'] = (int) $config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
50 | 50 | $defaultExpireSettings['enforceExpireDate'] = $enforceExpireDate === 'yes'; |
51 | 51 | } |
52 | 52 |
@@ -8,131 +8,131 @@ |
||
8 | 8 | namespace OC\Share; |
9 | 9 | |
10 | 10 | class Helper extends \OC\Share\Constants { |
11 | - /** |
|
12 | - * get default expire settings defined by the admin |
|
13 | - * @return array contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays' |
|
14 | - */ |
|
15 | - public static function getDefaultExpireSetting() { |
|
16 | - $config = \OC::$server->getConfig(); |
|
17 | - |
|
18 | - $defaultExpireSettings = ['defaultExpireDateSet' => false]; |
|
19 | - |
|
20 | - // get default expire settings |
|
21 | - $defaultExpireDate = $config->getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
22 | - if ($defaultExpireDate === 'yes') { |
|
23 | - $enforceExpireDate = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
24 | - $defaultExpireSettings['defaultExpireDateSet'] = true; |
|
25 | - $defaultExpireSettings['expireAfterDays'] = (int)$config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
26 | - $defaultExpireSettings['enforceExpireDate'] = $enforceExpireDate === 'yes'; |
|
27 | - } |
|
28 | - |
|
29 | - return $defaultExpireSettings; |
|
30 | - } |
|
31 | - |
|
32 | - public static function calcExpireDate() { |
|
33 | - $expireAfter = \OC\Share\Share::getExpireInterval() * 24 * 60 * 60; |
|
34 | - $expireAt = time() + $expireAfter; |
|
35 | - $date = new \DateTime(); |
|
36 | - $date->setTimestamp($expireAt); |
|
37 | - $date->setTime(0, 0, 0); |
|
38 | - //$dateString = $date->format('Y-m-d') . ' 00:00:00'; |
|
39 | - |
|
40 | - return $date; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * calculate expire date |
|
45 | - * @param array $defaultExpireSettings contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays' |
|
46 | - * @param int $creationTime timestamp when the share was created |
|
47 | - * @param int $userExpireDate expire timestamp set by the user |
|
48 | - * @return mixed integer timestamp or False |
|
49 | - */ |
|
50 | - public static function calculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate = null) { |
|
51 | - $expires = false; |
|
52 | - $defaultExpires = null; |
|
53 | - |
|
54 | - if (!empty($defaultExpireSettings['defaultExpireDateSet'])) { |
|
55 | - $defaultExpires = $creationTime + $defaultExpireSettings['expireAfterDays'] * 86400; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - if (isset($userExpireDate)) { |
|
60 | - // if the admin decided to enforce the default expire date then we only take |
|
61 | - // the user defined expire date of it is before the default expire date |
|
62 | - if ($defaultExpires && !empty($defaultExpireSettings['enforceExpireDate'])) { |
|
63 | - $expires = min($userExpireDate, $defaultExpires); |
|
64 | - } else { |
|
65 | - $expires = $userExpireDate; |
|
66 | - } |
|
67 | - } elseif ($defaultExpires && !empty($defaultExpireSettings['enforceExpireDate'])) { |
|
68 | - $expires = $defaultExpires; |
|
69 | - } |
|
70 | - |
|
71 | - return $expires; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Strips away a potential file names and trailing slashes: |
|
76 | - * - http://localhost |
|
77 | - * - http://localhost/ |
|
78 | - * - http://localhost/index.php |
|
79 | - * - http://localhost/index.php/s/{shareToken} |
|
80 | - * |
|
81 | - * all return: http://localhost |
|
82 | - * |
|
83 | - * @param string $remote |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - protected static function fixRemoteURL($remote) { |
|
87 | - $remote = str_replace('\\', '/', $remote); |
|
88 | - if ($fileNamePosition = strpos($remote, '/index.php')) { |
|
89 | - $remote = substr($remote, 0, $fileNamePosition); |
|
90 | - } |
|
91 | - $remote = rtrim($remote, '/'); |
|
92 | - |
|
93 | - return $remote; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * check if two federated cloud IDs refer to the same user |
|
98 | - * |
|
99 | - * @param string $user1 |
|
100 | - * @param string $server1 |
|
101 | - * @param string $user2 |
|
102 | - * @param string $server2 |
|
103 | - * @return bool true if both users and servers are the same |
|
104 | - */ |
|
105 | - public static function isSameUserOnSameServer($user1, $server1, $user2, $server2) { |
|
106 | - $normalizedServer1 = strtolower(\OC\Share\Share::removeProtocolFromUrl($server1)); |
|
107 | - $normalizedServer2 = strtolower(\OC\Share\Share::removeProtocolFromUrl($server2)); |
|
108 | - |
|
109 | - if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) { |
|
110 | - // FIXME this should be a method in the user management instead |
|
111 | - \OCP\Util::emitHook( |
|
112 | - '\OCA\Files_Sharing\API\Server2Server', |
|
113 | - 'preLoginNameUsedAsUserName', |
|
114 | - ['uid' => &$user1] |
|
115 | - ); |
|
116 | - \OCP\Util::emitHook( |
|
117 | - '\OCA\Files_Sharing\API\Server2Server', |
|
118 | - 'preLoginNameUsedAsUserName', |
|
119 | - ['uid' => &$user2] |
|
120 | - ); |
|
121 | - |
|
122 | - if ($user1 === $user2) { |
|
123 | - return true; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - return false; |
|
128 | - } |
|
129 | - |
|
130 | - public static function getTokenLength(): int { |
|
131 | - $config = \OCP\Server::get(\OCP\IAppConfig::class); |
|
132 | - $tokenLength = $config->getValueInt('core', 'shareapi_token_length', self::DEFAULT_TOKEN_LENGTH); |
|
133 | - $tokenLength = $tokenLength ?: self::DEFAULT_TOKEN_LENGTH; |
|
134 | - |
|
135 | - // Token length should be within the defined min and max limits |
|
136 | - return max(self::MIN_TOKEN_LENGTH, min($tokenLength, self::MAX_TOKEN_LENGTH)); |
|
137 | - } |
|
11 | + /** |
|
12 | + * get default expire settings defined by the admin |
|
13 | + * @return array contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays' |
|
14 | + */ |
|
15 | + public static function getDefaultExpireSetting() { |
|
16 | + $config = \OC::$server->getConfig(); |
|
17 | + |
|
18 | + $defaultExpireSettings = ['defaultExpireDateSet' => false]; |
|
19 | + |
|
20 | + // get default expire settings |
|
21 | + $defaultExpireDate = $config->getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
22 | + if ($defaultExpireDate === 'yes') { |
|
23 | + $enforceExpireDate = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
24 | + $defaultExpireSettings['defaultExpireDateSet'] = true; |
|
25 | + $defaultExpireSettings['expireAfterDays'] = (int)$config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
26 | + $defaultExpireSettings['enforceExpireDate'] = $enforceExpireDate === 'yes'; |
|
27 | + } |
|
28 | + |
|
29 | + return $defaultExpireSettings; |
|
30 | + } |
|
31 | + |
|
32 | + public static function calcExpireDate() { |
|
33 | + $expireAfter = \OC\Share\Share::getExpireInterval() * 24 * 60 * 60; |
|
34 | + $expireAt = time() + $expireAfter; |
|
35 | + $date = new \DateTime(); |
|
36 | + $date->setTimestamp($expireAt); |
|
37 | + $date->setTime(0, 0, 0); |
|
38 | + //$dateString = $date->format('Y-m-d') . ' 00:00:00'; |
|
39 | + |
|
40 | + return $date; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * calculate expire date |
|
45 | + * @param array $defaultExpireSettings contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays' |
|
46 | + * @param int $creationTime timestamp when the share was created |
|
47 | + * @param int $userExpireDate expire timestamp set by the user |
|
48 | + * @return mixed integer timestamp or False |
|
49 | + */ |
|
50 | + public static function calculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate = null) { |
|
51 | + $expires = false; |
|
52 | + $defaultExpires = null; |
|
53 | + |
|
54 | + if (!empty($defaultExpireSettings['defaultExpireDateSet'])) { |
|
55 | + $defaultExpires = $creationTime + $defaultExpireSettings['expireAfterDays'] * 86400; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + if (isset($userExpireDate)) { |
|
60 | + // if the admin decided to enforce the default expire date then we only take |
|
61 | + // the user defined expire date of it is before the default expire date |
|
62 | + if ($defaultExpires && !empty($defaultExpireSettings['enforceExpireDate'])) { |
|
63 | + $expires = min($userExpireDate, $defaultExpires); |
|
64 | + } else { |
|
65 | + $expires = $userExpireDate; |
|
66 | + } |
|
67 | + } elseif ($defaultExpires && !empty($defaultExpireSettings['enforceExpireDate'])) { |
|
68 | + $expires = $defaultExpires; |
|
69 | + } |
|
70 | + |
|
71 | + return $expires; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Strips away a potential file names and trailing slashes: |
|
76 | + * - http://localhost |
|
77 | + * - http://localhost/ |
|
78 | + * - http://localhost/index.php |
|
79 | + * - http://localhost/index.php/s/{shareToken} |
|
80 | + * |
|
81 | + * all return: http://localhost |
|
82 | + * |
|
83 | + * @param string $remote |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + protected static function fixRemoteURL($remote) { |
|
87 | + $remote = str_replace('\\', '/', $remote); |
|
88 | + if ($fileNamePosition = strpos($remote, '/index.php')) { |
|
89 | + $remote = substr($remote, 0, $fileNamePosition); |
|
90 | + } |
|
91 | + $remote = rtrim($remote, '/'); |
|
92 | + |
|
93 | + return $remote; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * check if two federated cloud IDs refer to the same user |
|
98 | + * |
|
99 | + * @param string $user1 |
|
100 | + * @param string $server1 |
|
101 | + * @param string $user2 |
|
102 | + * @param string $server2 |
|
103 | + * @return bool true if both users and servers are the same |
|
104 | + */ |
|
105 | + public static function isSameUserOnSameServer($user1, $server1, $user2, $server2) { |
|
106 | + $normalizedServer1 = strtolower(\OC\Share\Share::removeProtocolFromUrl($server1)); |
|
107 | + $normalizedServer2 = strtolower(\OC\Share\Share::removeProtocolFromUrl($server2)); |
|
108 | + |
|
109 | + if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) { |
|
110 | + // FIXME this should be a method in the user management instead |
|
111 | + \OCP\Util::emitHook( |
|
112 | + '\OCA\Files_Sharing\API\Server2Server', |
|
113 | + 'preLoginNameUsedAsUserName', |
|
114 | + ['uid' => &$user1] |
|
115 | + ); |
|
116 | + \OCP\Util::emitHook( |
|
117 | + '\OCA\Files_Sharing\API\Server2Server', |
|
118 | + 'preLoginNameUsedAsUserName', |
|
119 | + ['uid' => &$user2] |
|
120 | + ); |
|
121 | + |
|
122 | + if ($user1 === $user2) { |
|
123 | + return true; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + return false; |
|
128 | + } |
|
129 | + |
|
130 | + public static function getTokenLength(): int { |
|
131 | + $config = \OCP\Server::get(\OCP\IAppConfig::class); |
|
132 | + $tokenLength = $config->getValueInt('core', 'shareapi_token_length', self::DEFAULT_TOKEN_LENGTH); |
|
133 | + $tokenLength = $tokenLength ?: self::DEFAULT_TOKEN_LENGTH; |
|
134 | + |
|
135 | + // Token length should be within the defined min and max limits |
|
136 | + return max(self::MIN_TOKEN_LENGTH, min($tokenLength, self::MAX_TOKEN_LENGTH)); |
|
137 | + } |
|
138 | 138 | } |