Skip to content
Open
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
22 changes: 22 additions & 0 deletions apps/settings/lib/Settings/Personal/PersonalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use OCP\Notification\IManager;
use OCP\Server;
use OCP\Settings\ISettings;
use OCP\Teams\ITeamManager;
use OCP\Teams\Team;
use OCP\Util;

class PersonalInfo implements ISettings {
Expand All @@ -40,6 +42,7 @@ public function __construct(
private IConfig $config,
private IUserManager $userManager,
private IGroupManager $groupManager,
private ITeamManager $teamManager,
private IAccountManager $accountManager,
ProfileManager $profileManager,
private IAppManager $appManager,
Expand Down Expand Up @@ -87,6 +90,7 @@ public function getForm(): TemplateResponse {
'userId' => $uid,
'avatar' => $this->getProperty($account, IAccountManager::PROPERTY_AVATAR),
'groups' => $this->getGroups($user),
'teams' => $this->getTeamMemberships($user),
'quota' => $storageInfo['quota'],
'totalSpace' => $totalSpace,
'usage' => Util::humanFileSize($storageInfo['used']),
Expand Down Expand Up @@ -192,6 +196,24 @@ static function (IGroup $group) {
return $groups;
}

/**
* returns a list of the user's team memberships, sorted alphabetically
* @return list<string> team names
*/
private function getTeamMemberships(IUser $user): array {
if (!$this->appManager->isEnabledForUser('circles')) {
return [];
}

$teams = array_map(
static fn (Team $team): string => $team->getDisplayName(),
$this->teamManager->getMemberships($user->getUID())
);
sort($teams);

return $teams;
}

/**
* returns the primary email and additional emails in an
* associative array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="details__groups-info">
<p>{{ t('settings', 'You are a member of the following groups:') }}</p>
<p class="details__groups-list">
{{ groups.join(', ') }}
{{ [...groups, ...teams].join(', ') }}
</p>
</div>
</div>
Expand Down Expand Up @@ -43,7 +43,7 @@ import HeaderBar from './shared/HeaderBar.vue'
/** SYNC to be kept in sync with `lib/public/Files/FileInfo.php` */
const SPACE_UNLIMITED = -3

const { groups, quota, totalSpace, usage, usageRelative } = loadState('settings', 'personalInfoParameters', {})
const { groups, teams, quota, totalSpace, usage, usageRelative } = loadState('settings', 'personalInfoParameters', {})

export default {
name: 'DetailsSection',
Expand All @@ -58,6 +58,7 @@ export default {
data() {
return {
groups,
teams,
usageRelative,
}
},
Expand Down
4 changes: 2 additions & 2 deletions dist/settings-vue-settings-personal-info.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-vue-settings-personal-info.js.map

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions lib/private/Teams/TeamManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,20 @@ private function getTeams(array $teams, string $userId): array {
$this->circlesManager->startSession($federatedUser);
return $this->circlesManager->getCirclesByIds($teams);
}

public function getMemberships(string $userId): array {
if (!$this->hasTeamSupport()) {
return [];
}

$federatedUser = $this->circlesManager->getFederatedUser($userId, Member::TYPE_USER);
$this->circlesManager->startSession($federatedUser);
return array_map(function (Circle $team) {
return new Team(
$team->getSingleId(),
$team->getDisplayName(),
$this->urlGenerator->linkToRouteAbsolute('contacts.contacts.directcircle', ['singleId' => $team->getSingleId()]),
);
}, $this->circlesManager->getCircles());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	 * WARNING: This method is not using Cached Memberships meaning that the request can be heavy and should
	 * only be used if probeCircles() does not fit your need.
	 *
	 * Always prefer probeCircles();

According to circles code it may be better to call probeCircles here?
ping @ArtificialOwl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out! Just to let you know I've tested locally using probeCircles() instead of getCircles() and it works perfectly.

Following the docblock recommendation, since this fits our use case well, I think probeCircles() is the appropriate way of doing it.

I'll wait for @ArtificialOwl's confirmation before updating the implementation.

}
}
8 changes: 8 additions & 0 deletions lib/public/Teams/ITeamManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ public function getTeamsForResource(string $providerId, string $resourceId, stri
* @since 33.0.0
*/
public function getSharedWithList(array $teams, string $userId): array;

/**
* Returns all teams that a given user is a member of
*
* @return Team[]
* @since 33.0.0
*/
public function getMemberships(string $userId): array;
}
Loading