Store watermark settings in a generic way
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Родитель
c52596c187
Коммит
befa1ce66e
|
@ -14,7 +14,8 @@ namespace OCA\Richdocuments;
|
|||
use OCA\Richdocuments\AppInfo\Application;
|
||||
use \OCP\IConfig;
|
||||
|
||||
class AppConfig{
|
||||
class AppConfig {
|
||||
|
||||
private $defaults = [
|
||||
'wopi_url' => 'https://localhost:9980',
|
||||
'watermark_text' => '{userId}',
|
||||
|
@ -24,6 +25,8 @@ class AppConfig{
|
|||
|
||||
];
|
||||
|
||||
const WATERMARK_APP_NAMESPACE = 'files';
|
||||
|
||||
const APP_SETTING_TYPES = [
|
||||
'watermark_allGroupsList' => 'array',
|
||||
'watermark_allTagsList' => 'array',
|
||||
|
@ -37,6 +40,13 @@ class AppConfig{
|
|||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getAppNamespace($key) {
|
||||
if (strpos($key, 'watermark_') === 0) {
|
||||
return self::WATERMARK_APP_NAMESPACE;
|
||||
}
|
||||
return Application::APPNAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value by key
|
||||
* @param string $key
|
||||
|
@ -47,7 +57,7 @@ class AppConfig{
|
|||
if (array_key_exists($key, $this->defaults)){
|
||||
$defaultValue = $this->defaults[$key];
|
||||
}
|
||||
return $this->config->getAppValue(Application::APPNAME, $key, $defaultValue);
|
||||
return $this->config->getAppValue($this->getAppNamespace($key), $key, $defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,7 +65,7 @@ class AppConfig{
|
|||
* @return array
|
||||
*/
|
||||
public function getAppValueArray($key) {
|
||||
$value = $this->config->getAppValue(Application::APPNAME, $key, []);
|
||||
$value = $this->config->getAppValue($this->getAppNamespace($key), $key, []);
|
||||
if (self::APP_SETTING_TYPES[$key] === 'array') {
|
||||
$value = $value !== '' ? explode(',', $value) : [];
|
||||
}
|
||||
|
@ -69,7 +79,7 @@ class AppConfig{
|
|||
* @return void
|
||||
*/
|
||||
public function setAppValue($key, $value) {
|
||||
$this->config->setAppValue(Application::APPNAME, $key, $value);
|
||||
$this->config->setAppValue($this->getAppNamespace($key), $key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,12 +88,21 @@ class AppConfig{
|
|||
*/
|
||||
public function getAppSettings() {
|
||||
$result = [];
|
||||
$keys = $this->config->getAppKeys('richdocuments');
|
||||
$keys = $this->config->getAppKeys(Application::APPNAME);
|
||||
foreach ($keys as $key) {
|
||||
$value = $this->getAppValueArray($key);
|
||||
$value = $value === 'yes' ? true : $value;
|
||||
$result[$key] = $value === 'no' ? false : $value;
|
||||
}
|
||||
|
||||
$keys = $this->config->getAppKeys(self::WATERMARK_APP_NAMESPACE);
|
||||
foreach ($keys as $key) {
|
||||
if (strpos($key, 'watermark_') === 0) {
|
||||
$value = $this->getAppValueArray($key);
|
||||
$value = $value === 'yes' ? true : $value;
|
||||
$result[$key] = $value === 'no' ? false : $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
@ -194,9 +194,9 @@ class WopiController extends Controller {
|
|||
'userId' => $wopi->getEditorUid(),
|
||||
'date' => (new \DateTime())->format('Y-m-d H:i:s'),
|
||||
'themingName' => \OC::$server->getThemingDefaults()->getName(),
|
||||
'themingName' => \OC::$server->getThemingDefaults()->getName(),
|
||||
|
||||
];
|
||||
$watermarkTemplate = $this->config->getAppValue('richdocuments', 'watermark_text', '{userId}');
|
||||
$watermarkTemplate = $this->appConfig->getAppValue('watermark_text');
|
||||
$response['WatermarkText'] = preg_replace_callback('/{(.+?)}/', function($matches) use ($replacements)
|
||||
{
|
||||
return $replacements[$matches[1]];
|
||||
|
@ -236,21 +236,21 @@ class WopiController extends Controller {
|
|||
}
|
||||
|
||||
private function shouldWatermark($isPublic, $userId, $fileId, Wopi $wopi) {
|
||||
if ($this->config->getAppValue('richdocuments', 'watermark_enabled', 'no') === 'no') {
|
||||
if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_enabled', 'no') === 'no') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($isPublic) {
|
||||
if ($this->config->getAppValue('richdocuments', 'watermark_linkAll', 'no') === 'yes') {
|
||||
if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_linkAll', 'no') === 'yes') {
|
||||
return true;
|
||||
}
|
||||
if ($this->config->getAppValue('richdocuments', 'watermark_linkRead', 'no') === 'yes' && !$wopi->getCanwrite()) {
|
||||
if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_linkRead', 'no') === 'yes' && !$wopi->getCanwrite()) {
|
||||
return true;
|
||||
}
|
||||
if ($this->config->getAppValue('richdocuments', 'watermark_linkSecure', 'no') === 'yes' && $wopi->getHideDownload()) {
|
||||
if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_linkSecure', 'no') === 'yes' && $wopi->getHideDownload()) {
|
||||
return true;
|
||||
}
|
||||
if ($this->config->getAppValue('richdocuments', 'watermark_linkTags', 'no') === 'yes') {
|
||||
if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_linkTags', 'no') === 'yes') {
|
||||
$tags = $this->appConfig->getAppValueArray('watermark_linkTagsList');
|
||||
$fileTags = \OC::$server->getSystemTagObjectMapper()->getTagIdsForObjects([$fileId], 'files')[$fileId];
|
||||
foreach ($fileTags as $tagId) {
|
||||
|
@ -260,14 +260,14 @@ class WopiController extends Controller {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if ($this->config->getAppValue('richdocuments', 'watermark_shareAll', 'no') === 'yes') {
|
||||
if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_shareAll', 'no') === 'yes') {
|
||||
return true;
|
||||
}
|
||||
if ($this->config->getAppValue('richdocuments', 'watermark_shareRead', 'no') === 'yes' && !$wopi->getCanwrite()) {
|
||||
if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_shareRead', 'no') === 'yes' && !$wopi->getCanwrite()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ($this->config->getAppValue('richdocuments', 'watermark_allGroups', 'no') === 'yes') {
|
||||
if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_allGroups', 'no') === 'yes') {
|
||||
$groups = $this->appConfig->getAppValueArray('watermark_allGroupsList');
|
||||
foreach ($groups as $group) {
|
||||
if (\OC::$server->getGroupManager()->isInGroup($userId, $group)) {
|
||||
|
@ -275,7 +275,7 @@ class WopiController extends Controller {
|
|||
}
|
||||
}
|
||||
}
|
||||
if ($this->config->getAppValue('richdocuments', 'watermark_allTags', 'no') === 'yes') {
|
||||
if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_allTags', 'no') === 'yes') {
|
||||
$tags = $this->appConfig->getAppValueArray('watermark_allTagsList');
|
||||
$fileTags = \OC::$server->getSystemTagObjectMapper()->getTagIdsForObjects([$fileId], 'files');
|
||||
foreach ($fileTags as $tagId) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче