Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function index(): TemplateResponse {

$this->provideSignerSignatues();
$this->initialState->provideInitialState('identify_methods', $this->identifyMethodService->getIdentifyMethodsSettings());
$this->initialState->provideInitialState('signature_flow', $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', \OCA\Libresign\Enum\SignatureFlow::PARALLEL->value));
$this->initialState->provideInitialState('signature_flow', $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', \OCA\Libresign\Enum\SignatureFlow::NONE->value));
$this->initialState->provideInitialState('legal_information', $this->appConfig->getValueString(Application::APP_ID, 'legal_information'));

Util::addScript(Application::APP_ID, 'libresign-main');
Expand Down
13 changes: 11 additions & 2 deletions lib/Controller/RequestSignatureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public function request(
* @param LibresignVisibleElement[]|null $visibleElements Visible elements on document
* @param LibresignNewFile|array<empty>|null $file File object.
* @param integer|null $status Numeric code of status * 0 - no signers * 1 - signed * 2 - pending
* @param string|null $signatureFlow Signature flow mode: 'parallel' or 'ordered_numeric'. If not provided, uses global configuration
* @return DataResponse<Http::STATUS_OK, array{message: string, data: LibresignValidateFile}, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, array{message?: string, action?: integer, errors?: list<array{message: string, title?: string}>}, array{}>
*
* 200: OK
Expand All @@ -145,15 +146,23 @@ public function request(
#[NoCSRFRequired]
#[RequireManager]
#[ApiRoute(verb: 'PATCH', url: '/api/{apiVersion}/request-signature', requirements: ['apiVersion' => '(v1)'])]
public function updateSign(?array $users = [], ?string $uuid = null, ?array $visibleElements = null, ?array $file = [], ?int $status = null): DataResponse {
public function updateSign(
?array $users = [],
?string $uuid = null,
?array $visibleElements = null,
?array $file = [],
?int $status = null,
?string $signatureFlow = null,
): DataResponse {
$user = $this->userSession->getUser();
$data = [
'uuid' => $uuid,
'file' => $file,
'users' => $users,
'userManager' => $user,
'status' => $status,
'visibleElements' => $visibleElements
'visibleElements' => $visibleElements,
'signatureFlow' => $signatureFlow,
];
try {
$this->validateHelper->validateExistingFile($data);
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class File extends Entity {
protected ?string $callback = null;
protected ?array $metadata = null;
protected int $modificationStatus = 0;
protected int $signatureFlow = SignatureFlow::NUMERIC_PARALLEL;
protected int $signatureFlow = SignatureFlow::NUMERIC_NONE;
protected int $docmdpLevel = 0;
public const STATUS_NOT_LIBRESIGN_FILE = -1;
public const STATUS_DRAFT = 0;
Expand Down
4 changes: 4 additions & 0 deletions lib/Enum/SignatureFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@
* Signature flow modes
*/
enum SignatureFlow: string {
case NONE = 'none';
case PARALLEL = 'parallel';
case ORDERED_NUMERIC = 'ordered_numeric';

public const NUMERIC_NONE = 0;
public const NUMERIC_PARALLEL = 1;
public const NUMERIC_ORDERED_NUMERIC = 2;

public function toNumeric(): int {
return match($this) {
self::NONE => self::NUMERIC_NONE,
self::PARALLEL => self::NUMERIC_PARALLEL,
self::ORDERED_NUMERIC => self::NUMERIC_ORDERED_NUMERIC,
};
}

public static function fromNumeric(int $value): self {
return match($value) {
self::NUMERIC_NONE => self::NONE,
self::NUMERIC_PARALLEL => self::PARALLEL,
self::NUMERIC_ORDERED_NUMERIC => self::ORDERED_NUMERIC,
default => throw new \ValueError("Invalid numeric value for SignatureFlow: $value"),
Expand Down
2 changes: 1 addition & 1 deletion lib/Files/TemplateLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function handle(Event $event): void {

$this->initialState->provideInitialState(
'signature_flow',
$this->appConfig->getValueString(Application::APP_ID, 'signature_flow', \OCA\Libresign\Enum\SignatureFlow::PARALLEL->value)
$this->appConfig->getValueString(Application::APP_ID, 'signature_flow', \OCA\Libresign\Enum\SignatureFlow::NONE->value)
);

try {
Expand Down
4 changes: 2 additions & 2 deletions lib/Handler/CertificateEngine/AEngineHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ private function initializePkiConfigPath(): string {
}
$pkiDirName = $this->caIdentifierService->generatePkiDirectoryName($caId);
$dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
$instanceId = $this->config->getSystemValue('instanceid');
$pkiPath = $dataDir . '/appdata_' . $instanceId . '/libresign/' . $pkiDirName;
$systemInstanceId = $this->config->getSystemValue('instanceid');
$pkiPath = $dataDir . '/appdata_' . $systemInstanceId . '/libresign/' . $pkiDirName;

if (!is_dir($pkiPath)) {
$this->createDirectoryWithCorrectOwnership($pkiPath);
Expand Down
4 changes: 2 additions & 2 deletions lib/Migration/Version15000Date20251209000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
if (!$tableFile->hasColumn('signature_flow')) {
$tableFile->addColumn('signature_flow', Types::SMALLINT, [
'notnull' => true,
'default' => SignatureFlow::NUMERIC_PARALLEL,
'comment' => 'Signature flow mode: 1=parallel, 2=ordered_numeric',
'default' => SignatureFlow::NUMERIC_NONE,
'comment' => 'Signature flow mode: 0=none (no admin enforcement), 1=parallel, 2=ordered_numeric',
]);
}
}
Expand Down
50 changes: 35 additions & 15 deletions lib/Service/RequestSignatureService.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function save(array $data): FileEntity {
public function saveFile(array $data): FileEntity {
if (!empty($data['uuid'])) {
$file = $this->fileMapper->getByUuid($data['uuid']);
$this->updateSignatureFlowIfAllowed($file, $data);
return $this->fileStatusService->updateFileStatusIfUpgrade($file, $data['status'] ?? 0);
}
$fileId = null;
Expand All @@ -90,6 +91,7 @@ public function saveFile(array $data): FileEntity {
if (!is_null($fileId)) {
try {
$file = $this->fileMapper->getByFileId($fileId);
$this->updateSignatureFlowIfAllowed($file, $data);
return $this->fileStatusService->updateFileStatusIfUpgrade($file, $data['status'] ?? 0);
} catch (\Throwable) {
}
Expand Down Expand Up @@ -118,27 +120,45 @@ public function saveFile(array $data): FileEntity {
$file->setStatus(FileEntity::STATUS_ABLE_TO_SIGN);
}

if (isset($data['signatureFlow']) && is_string($data['signatureFlow'])) {
try {
$signatureFlow = \OCA\Libresign\Enum\SignatureFlow::from($data['signatureFlow']);
$file->setSignatureFlowEnum($signatureFlow);
} catch (\ValueError) {
$this->setSignatureFlowFromGlobalConfig($file);
}
} else {
$this->setSignatureFlowFromGlobalConfig($file);
}

$this->setSignatureFlow($file, $data);
$this->setDocMdpLevelFromGlobalConfig($file);

$this->fileMapper->insert($file);
return $file;
}

private function setSignatureFlowFromGlobalConfig(FileEntity $file): void {
$globalFlowValue = $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', SignatureFlow::PARALLEL->value);
$globalFlow = SignatureFlow::from($globalFlowValue);
$file->setSignatureFlowEnum($globalFlow);
private function updateSignatureFlowIfAllowed(FileEntity $file, array $data): void {
$adminFlow = $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', SignatureFlow::NONE->value);
$adminForcedConfig = $adminFlow !== SignatureFlow::NONE->value;

if ($adminForcedConfig) {
$adminFlowEnum = SignatureFlow::from($adminFlow);
if ($file->getSignatureFlowEnum() !== $adminFlowEnum) {
$file->setSignatureFlowEnum($adminFlowEnum);
$this->fileMapper->update($file);
}
return;
}

if (isset($data['signatureFlow']) && !empty($data['signatureFlow'])) {
$newFlow = SignatureFlow::from($data['signatureFlow']);
if ($file->getSignatureFlowEnum() !== $newFlow) {
$file->setSignatureFlowEnum($newFlow);
$this->fileMapper->update($file);
}
}
}

private function setSignatureFlow(FileEntity $file, array $data): void {
$adminFlow = $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', SignatureFlow::NONE->value);

if (isset($data['signatureFlow']) && !empty($data['signatureFlow'])) {
$file->setSignatureFlowEnum(SignatureFlow::from($data['signatureFlow']));
} elseif ($adminFlow !== SignatureFlow::NONE->value) {
$file->setSignatureFlowEnum(SignatureFlow::from($adminFlow));
} else {
$file->setSignatureFlowEnum(SignatureFlow::NONE);
}
}

private function setDocMdpLevelFromGlobalConfig(FileEntity $file): void {
Expand Down
2 changes: 1 addition & 1 deletion lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getForm(): TemplateResponse {
$this->initialState->provideInitialState('tsa_username', $this->appConfig->getValueString(Application::APP_ID, 'tsa_username', ''));
$this->initialState->provideInitialState('tsa_password', $this->appConfig->getValueString(Application::APP_ID, 'tsa_password', self::PASSWORD_PLACEHOLDER));
$this->initialState->provideInitialState('docmdp_config', $this->docMdpConfigService->getConfig());
$this->initialState->provideInitialState('signature_flow', $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', ''));
$this->initialState->provideInitialState('signature_flow', $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', \OCA\Libresign\Enum\SignatureFlow::NONE->value));
return new TemplateResponse(Application::APP_ID, 'admin_settings');
}

Expand Down
5 changes: 5 additions & 0 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -6679,6 +6679,11 @@
"format": "int64",
"nullable": true,
"description": "Numeric code of status * 0 - no signers * 1 - signed * 2 - pending"
},
"signatureFlow": {
"type": "string",
"nullable": true,
"description": "Signature flow mode: 'parallel' or 'ordered_numeric'. If not provided, uses global configuration"
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6529,6 +6529,11 @@
"format": "int64",
"nullable": true,
"description": "Numeric code of status * 0 - no signers * 1 - signed * 2 - pending"
},
"signatureFlow": {
"type": "string",
"nullable": true,
"description": "Signature flow mode: 'parallel' or 'ordered_numeric'. If not provided, uses global configuration"
}
}
}
Expand Down
Loading
Loading