Repository navigation
feat: introduce the genric Actor entity - #65987
Conversation
9cbcae1 to
c3c02cf
Compare
provokateurin
left a comment
There was a problem hiding this comment.
Despite the amount of comments, this looks really good!
686c399 to
d9c99aa
Compare
d9c99aa to
493fbbd
Compare
bc340c7 to
0186db6
Compare
| public static function user(string $userId): self { | ||
| return new self(PrincipalType::User, $userId); | ||
| } | ||
|
|
||
| /** | ||
| * @param non-empty-string $userId - federated user id | ||
| * @param non-empty-string $remote - remote instance | ||
| * @experimental 36.0.0 | ||
| */ | ||
| public static function federatedUser(string $userId, string $remote): self { | ||
| return new self(PrincipalType::User, $userId, $remote); | ||
| } | ||
|
|
||
| /** | ||
| * @param non-empty-string $externalId - anonymous user id | ||
| * @param non-empty-string $source app-namespaced kind of external user, e.g. "spreed.email" | ||
| * @param ?non-empty-string $token - share/room token, if any | ||
| * @experimental 36.0.0 | ||
| */ | ||
| public static function anonymous(string $externalId, string $source, ?string $token = null): self { | ||
| return new self(PrincipalType::Anonymous, $externalId, $token, $source); | ||
| } | ||
|
|
||
| /** | ||
| * @param non-empty-string $botId - bot id | ||
| * @param ?non-empty-string $source - app owning the bot, e.g. "spreed" | ||
| * @experimental 36.0.0 | ||
| */ | ||
| public static function bot(string $botId, ?string $source = null): self { | ||
| return new self(PrincipalType::Bot, $botId, null, $source); | ||
| } | ||
|
|
||
| /** | ||
| * Identifies a component, e.g. "governance.retention". | ||
| * | ||
| * @param non-empty-string $component - component name | ||
| * @param ?non-empty-string $source - app owning the component, e.g. "app_api" | ||
| * @experimental 36.0.0 | ||
| */ | ||
| public static function system(string $component, ?string $source = null): self { | ||
| return new self(PrincipalType::System, $component, null, $source); | ||
| } |
There was a problem hiding this comment.
Feels a bit out of touch with the rest of Nextcloud code, where we usually rather do class extention, like:
class PrincipalActor {
private function __construct(
public PrincipalType $type,
public string $id,
public ?string $origin = null,
public ?string $source = null,
) {
...
}
public function is(PrincipalType $type): bool {
...
}
public function equals(self $other): bool {
...
}
}
class UserActor extends PrincipalActor {
private function __construct(
public string $id,
) {
...
}
}
class FederatedUser extends PrincipalActor {
private function __construct(
public string $id,
public ?string $origin = null,
) {
...
}
}
class BotActor extends PrincipalActor {
private function __construct(
public string $appId,
public string $botId,
) {
...
}
}There was a problem hiding this comment.
I won't hardly oppose this new pattern though, so fine to merge as is if you think otherwise :).
There was a problem hiding this comment.
In this case a new class does not communicate something new, this by design should not be enhanced with new attributes like "user groups" etc. The idea of this API is simply communicating the identity, data attributes can be fetched from the proper APIs if needed, out of scope of this API.
So this only needs to communicate the type and the identifier(s), so new classes seem a bit over the top for this
There was a problem hiding this comment.
So this only needs to communicate the type and the identifier(s), so new classes seem a bit over the top for this
Probably, it is just more aligned with the other APIs. I don't think we have other APIs where we use static methods to instanciate object.
0186db6 to
faf6613
Compare
1cfbdb6 to
f8cd5d8
Compare
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com> Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
209f37a to
5acadbb
Compare
Summary
Introduces an
Actordata object to pass around the information of who is performing an action / request, and include information about "privilege escalation" or delegation, so that audit or compliance apps can log a chain, and apps can take decisions losing less context and avoiding mix ups like$userId = nullequalling to "all privileges" or "no privileges" depending on the call, which are completely different answers.The
DelegationKindandPrincipalTypecould be extended in the future as "stable" cases become more prominent.Example: SystemTagManager
I took the example of the
SystemTagManager, where I stumbled on the pattern first-hand.Before
After
Checklist
3. to review, feature component)stable32)AI (if applicable)