Skip to content

Commit

Permalink
Merge pull request #827 from nextcloud/backport/797/22
Browse files Browse the repository at this point in the history
[stable22] backport of #797
  • Loading branch information
ArtificialOwl authored Dec 24, 2021
2 parents e594bf7 + 3fe246f commit 4125669
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
4 changes: 2 additions & 2 deletions lib/Command/CirclesReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ private function obfuscateFederatedUser(FederatedUser $federatedUser): Federated
$federatedUser->setBasedOn($this->obfuscateCircle($federatedUser->getBasedOn()));
}

if ($federatedUser->hasLink()) {
$federatedUser->setLink($this->obfuscateMembership($federatedUser->getLink()));
if ($federatedUser->hasInheritance()) {
$federatedUser->setInheritance($this->obfuscateMembership($federatedUser->getInheritance()));
}

if ($federatedUser->hasMemberships()) {
Expand Down
58 changes: 32 additions & 26 deletions lib/Model/FederatedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class FederatedUser extends ManagedModel implements
private $instance;

/** @var Membership */
private $link;
private $inheritance;

/** @var Membership[] */
private $memberships = null;
Expand Down Expand Up @@ -270,60 +270,59 @@ public function isLocal(): bool {
return $this->getManager()->isLocalInstance($this->getInstance());
}


/**
* @return bool
*/
public function hasMemberships(): bool {
return !is_null($this->memberships);
public function hasInheritance(): bool {
return !is_null($this->inheritance);
}

/**
* @param array $memberships
* @param Membership $inheritance
*
* @return self
* @return $this
*/
public function setMemberships(array $memberships): IMemberships {
$this->memberships = $memberships;
public function setInheritance(Membership $inheritance): self {
$this->inheritance = $inheritance;

return $this;
}

/**
* @return Membership[]
* @return Membership
*/
public function getMemberships(): array {
if (!$this->hasMemberships()) {
$this->getManager()->getMemberships($this);
}

return $this->memberships;
public function getInheritance(): Membership {
return $this->inheritance;
}


/**
* @return bool
*/
public function hasLink(): bool {
return !is_null($this->link);
public function hasMemberships(): bool {
return !is_null($this->memberships);
}

/**
* @param Membership $link
* @param array $memberships
*
* @return $this
* @return self
*/
public function setLink(Membership $link): self {
$this->link = $link;
public function setMemberships(array $memberships): IMemberships {
$this->memberships = $memberships;

return $this;
}

/**
* @return Membership
* @return Membership[]
*/
public function getLink(): Membership {
return $this->link;
public function getMemberships(): array {
if (!$this->hasMemberships()) {
$this->getManager()->getMemberships($this);
}

return $this->memberships;
}


Expand Down Expand Up @@ -352,6 +351,13 @@ public function import(array $data): IDeserializable {
} catch (InvalidItemException $e) {
}

try {
/** @var Membership $membership */
$membership = $this->deserialize($this->getArray('membership', $data), Membership::class);
$this->setInheritance($membership);
} catch (InvalidItemException $e) {
}

return $this;
}

Expand Down Expand Up @@ -429,8 +435,8 @@ public function jsonSerialize(): array {
$arr['basedOn'] = $this->getBasedOn();
}

if ($this->hasLink()) {
$arr['link'] = $this->getLink();
if ($this->hasInheritance()) {
$arr['inheritance'] = $this->getInheritance();
}

if (!is_null($this->memberships)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private function importIntoFederatedUser(
try {
$membership = new Membership();
$membership->importFromDatabase($data, $prefix);
$federatedUser->setLink($membership);
$federatedUser->setInheritance($membership);
} catch (MembershipNotFoundException $e) {
}
break;
Expand Down

0 comments on commit 4125669

Please sign in to comment.