Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.83% covered (success)
95.83%
46 / 48
95.24% covered (success)
95.24%
20 / 21
CRAP
0.00% covered (danger)
0.00%
0 / 1
FileResponseOptions
95.83% covered (success)
95.83%
46 / 48
95.24% covered (success)
95.24%
20 / 21
39
0.00% covered (danger)
0.00%
0 / 1
 showSigners
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 isShowSigners
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 showSettings
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 isShowSettings
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 showVisibleElements
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 isShowVisibleElements
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 showMessages
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 isShowMessages
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 validateFile
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 isValidateFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSignerIdentified
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 isSignerIdentified
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isViewerOfSigner
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
19
 setMe
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMe
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSignRequest
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getSignRequest
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setIdentifyMethodId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getIdentifyMethodId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHost
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getHost
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4/**
5 * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
6 * SPDX-License-Identifier: AGPL-3.0-or-later
7 */
8
9namespace OCA\Libresign\Service\File;
10
11use OCA\Libresign\Db\SignRequest;
12use OCP\IUser;
13
14class FileResponseOptions {
15    private bool $showSigners = false;
16    private bool $showSettings = false;
17    private bool $showVisibleElements = false;
18    private bool $showMessages = false;
19    private bool $validateFile = false;
20    private bool $signerIdentified = false;
21    private ?IUser $me = null;
22    private ?SignRequest $signRequest = null;
23    private ?int $identifyMethodId = null;
24    private string $host = '';
25
26    public function showSigners(bool $show = true): self {
27        $this->showSigners = $show;
28        return $this;
29    }
30
31    public function isShowSigners(): bool {
32        return $this->showSigners;
33    }
34
35    public function showSettings(bool $show = true): self {
36        $this->showSettings = $show;
37        return $this;
38    }
39
40    public function isShowSettings(): bool {
41        return $this->showSettings;
42    }
43
44    public function showVisibleElements(bool $show = true): self {
45        $this->showVisibleElements = $show;
46        return $this;
47    }
48
49    public function isShowVisibleElements(): bool {
50        return $this->showVisibleElements;
51    }
52
53    public function showMessages(bool $show = true): self {
54        $this->showMessages = $show;
55        return $this;
56    }
57
58    public function isShowMessages(): bool {
59        return $this->showMessages;
60    }
61
62    public function validateFile(bool $validate = true): self {
63        $this->validateFile = $validate;
64        return $this;
65    }
66
67    public function isValidateFile(): bool {
68        return $this->validateFile;
69    }
70
71    public function setSignerIdentified(bool $identified = true): self {
72        $this->signerIdentified = $identified;
73        return $this;
74    }
75
76    public function isSignerIdentified(): bool {
77        return $this->signerIdentified;
78    }
79
80    /**
81     * Whether the viewer this context was resolved for is the signer behind
82     * these identify methods: the identify method the signer identified with
83     * in this session, or the authenticated user's uid or e-mail.
84     *
85     * @param array<string, array<\OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod>> $identifyMethodsOfSigner
86     */
87    public function isViewerOfSigner(array $identifyMethodsOfSigner): bool {
88        if ($this->me === null && $this->identifyMethodId === null) {
89            return false;
90        }
91        $uid = $this->me?->getUID();
92        $email = $this->me?->getEMailAddress();
93        $emailLower = is_string($email) ? strtolower($email) : null;
94        foreach ($identifyMethodsOfSigner as $methods) {
95            foreach ($methods as $identifyMethod) {
96                $entity = $identifyMethod->getEntity();
97                $identifierValue = $entity->getIdentifierValue();
98                $uidMatches = $uid !== null && $uid !== '' && $uid === $identifierValue;
99                $emailMatches = $email !== null && $email !== '' && $email === $identifierValue;
100                $emailMatchesInsensitive = $emailLower !== null && $emailLower !== ''
101                    && $emailLower === strtolower($identifierValue);
102                $uniqueMatches = $uid !== null && $uid !== ''
103                    && $entity->getUniqueIdentifier() === 'account:' . $uid;
104                if ($this->identifyMethodId === $entity->getId()
105                    || $uidMatches
106                    || $emailMatches
107                    || $emailMatchesInsensitive
108                    || $uniqueMatches
109                ) {
110                    return true;
111                }
112            }
113        }
114        return false;
115    }
116
117    public function setMe(?IUser $user): self {
118        $this->me = $user;
119        return $this;
120    }
121
122    public function getMe(): ?IUser {
123        return $this->me;
124    }
125
126    public function setSignRequest(?SignRequest $signRequest): self {
127        $this->signRequest = $signRequest;
128        return $this;
129    }
130
131    public function getSignRequest(): ?SignRequest {
132        return $this->signRequest;
133    }
134
135    public function setIdentifyMethodId(?int $id): self {
136        $this->identifyMethodId = $id;
137        return $this;
138    }
139
140    public function getIdentifyMethodId(): ?int {
141        return $this->identifyMethodId;
142    }
143
144    public function setHost(string $host): self {
145        $this->host = $host;
146        return $this;
147    }
148
149    public function getHost(): string {
150        return $this->host;
151    }
152}