2626
2727namespace OC \Profile ;
2828
29- use function Safe \array_flip ;
30- use function Safe \usort ;
29+ use OCP \Profile \IProfileManager ;
30+ use function array_flip ;
31+ use function usort ;
3132use OC \AppFramework \Bootstrap \Coordinator ;
3233use OC \Core \Db \ProfileConfig ;
3334use OC \Core \Db \ProfileConfigMapper ;
4950use Psr \Container \ContainerInterface ;
5051use Psr \Log \LoggerInterface ;
5152
52- class ProfileManager {
53+ class ProfileManager implements IProfileManager {
5354 /** @var ILinkAction[] */
5455 private array $ actions = [];
5556
@@ -101,15 +102,15 @@ public function __construct(
101102 /**
102103 * If no user is passed as an argument return whether profile is enabled globally in `config.php`
103104 */
104- public function isProfileEnabled (?IUser $ user = null ): ? bool {
105+ public function isProfileEnabled (?IUser $ user = null ): bool {
105106 $ profileEnabledGlobally = $ this ->config ->getSystemValueBool ('profile.enabled ' , true );
106107
107108 if (empty ($ user ) || !$ profileEnabledGlobally ) {
108109 return $ profileEnabledGlobally ;
109110 }
110111
111112 $ account = $ this ->accountManager ->getAccount ($ user );
112- return filter_var (
113+ return ( bool ) filter_var (
113114 $ account ->getProperty (IAccountManager::PROPERTY_PROFILE_ENABLED )->getValue (),
114115 FILTER_VALIDATE_BOOLEAN ,
115116 FILTER_NULL_ON_FAILURE ,
@@ -193,18 +194,18 @@ private function getActions(IUser $targetUser, ?IUser $visitingUser): array {
193194 * Return whether the profile parameter of the target user
194195 * is visible to the visiting user
195196 */
196- private function isParameterVisible (string $ paramId , IUser $ targetUser , ?IUser $ visitingUser ): bool {
197+ public function isProfileFieldVisible (string $ profileField , IUser $ targetUser , ?IUser $ visitingUser ): bool {
197198 try {
198199 $ account = $ this ->accountManager ->getAccount ($ targetUser );
199- $ scope = $ account ->getProperty ($ paramId )->getScope ();
200+ $ scope = $ account ->getProperty ($ profileField )->getScope ();
200201 } catch (PropertyDoesNotExistException $ e ) {
201202 // Allow the exception as not all profile parameters are account properties
202203 }
203204
204- $ visibility = $ this ->getProfileConfig ($ targetUser , $ visitingUser )[$ paramId ]['visibility ' ];
205+ $ visibility = $ this ->getProfileConfig ($ targetUser , $ visitingUser )[$ profileField ]['visibility ' ];
205206 // Handle profile visibility and account property scope
206207
207- if ($ visibility === ProfileConfig ::VISIBILITY_SHOW_USERS_ONLY ) {
208+ if ($ visibility === self ::VISIBILITY_SHOW_USERS_ONLY ) {
208209 if (empty ($ scope )) {
209210 return $ visitingUser !== null ;
210211 }
@@ -218,10 +219,10 @@ private function isParameterVisible(string $paramId, IUser $targetUser, ?IUser $
218219 };
219220 }
220221
221- if ($ visibility === ProfileConfig ::VISIBILITY_SHOW ) {
222+ if ($ visibility === self ::VISIBILITY_SHOW ) {
222223 if (empty ($ scope )) {
223224 return true ;
224- };
225+ }
225226
226227 return match ($ scope ) {
227228 IAccountManager::SCOPE_PRIVATE => $ visitingUser !== null && $ this ->knownUserService ->isKnownToUser ($ targetUser ->getUID (), $ visitingUser ->getUID ()),
@@ -238,8 +239,9 @@ private function isParameterVisible(string $paramId, IUser $targetUser, ?IUser $
238239 /**
239240 * Return the profile parameters of the target user that are visible to the visiting user
240241 * in an associative array
242+ * @return array{userId: string, address?: string|null, biography?: string|null, displayname?: string|null, headline?: string|null, isUserAvatarVisible?: bool, organisation?: string|null, role?: string|null, actions: list<array{id: string, icon: string, title: string, target: ?string}>}
241243 */
242- public function getProfileParams (IUser $ targetUser , ?IUser $ visitingUser ): array {
244+ public function getProfileFields (IUser $ targetUser , ?IUser $ visitingUser ): array {
243245 $ account = $ this ->accountManager ->getAccount ($ targetUser );
244246
245247 // Initialize associative array of profile parameters
@@ -257,14 +259,14 @@ public function getProfileParams(IUser $targetUser, ?IUser $visitingUser): array
257259 case IAccountManager::PROPERTY_ORGANISATION :
258260 case IAccountManager::PROPERTY_ROLE :
259261 $ profileParameters [$ property ] =
260- $ this ->isParameterVisible ($ property , $ targetUser , $ visitingUser )
262+ $ this ->isProfileFieldVisible ($ property , $ targetUser , $ visitingUser )
261263 // Explicitly set to null when value is empty string
262264 ? ($ account ->getProperty ($ property )->getValue () ?: null )
263265 : null ;
264266 break ;
265267 case IAccountManager::PROPERTY_AVATAR :
266268 // Add avatar visibility
267- $ profileParameters ['isUserAvatarVisible ' ] = $ this ->isParameterVisible ($ property , $ targetUser , $ visitingUser );
269+ $ profileParameters ['isUserAvatarVisible ' ] = $ this ->isProfileFieldVisible ($ property , $ targetUser , $ visitingUser );
268270 break ;
269271 }
270272 }
@@ -284,7 +286,7 @@ function (ILinkAction $action) {
284286 array_filter (
285287 $ this ->getActions ($ targetUser , $ visitingUser ),
286288 function (ILinkAction $ action ) use ($ targetUser , $ visitingUser ) {
287- return $ this ->isParameterVisible ($ action ->getId (), $ targetUser , $ visitingUser );
289+ return $ this ->isProfileFieldVisible ($ action ->getId (), $ targetUser , $ visitingUser );
288290 }
289291 ),
290292 )
@@ -316,12 +318,12 @@ private function getDefaultProfileConfig(IUser $targetUser, ?IUser $visitingUser
316318 // Construct the default config for actions
317319 $ actionsConfig = [];
318320 foreach ($ this ->getActions ($ targetUser , $ visitingUser ) as $ action ) {
319- $ actionsConfig [$ action ->getId ()] = ['visibility ' => ProfileConfig ::DEFAULT_VISIBILITY ];
321+ $ actionsConfig [$ action ->getId ()] = ['visibility ' => self ::DEFAULT_VISIBILITY ];
320322 }
321323
322324 // Construct the default config for account properties
323325 $ propertiesConfig = [];
324- foreach (ProfileConfig ::DEFAULT_PROPERTY_VISIBILITY as $ property => $ visibility ) {
326+ foreach (self ::DEFAULT_PROPERTY_VISIBILITY as $ property => $ visibility ) {
325327 $ propertiesConfig [$ property ] = ['visibility ' => $ visibility ];
326328 }
327329
0 commit comments