From 5694fb45fc474ab56697ed296b6f8408261c8fee Mon Sep 17 00:00:00 2001 From: gevorgmansuryan Date: Mon, 23 Sep 2024 14:44:52 +0400 Subject: [PATCH 1/2] Add user profile image/banner --- definitions/UserDefinitions.php | 21 +++++++++++++++++---- docs/html/auth.html | 4 ++-- docs/html/user.html | 16 ++++++++-------- docs/swagger/user.yaml | 4 ++++ 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/definitions/UserDefinitions.php b/definitions/UserDefinitions.php index e2bbe10..b08cd4c 100644 --- a/definitions/UserDefinitions.php +++ b/definitions/UserDefinitions.php @@ -16,6 +16,7 @@ use humhub\modules\user\models\Group; use humhub\modules\user\models\Session; use humhub\modules\user\models\User; +use yii\helpers\ArrayHelper; use yii\helpers\Url; /** @@ -41,14 +42,26 @@ public static function getUser(User $user) 'display_name' => $user->displayName, 'url' => Url::to(['/', 'container' => $user], true), 'account' => static::getAccount($user), - 'profile' => static::getProfile($user->profile), + 'profile' => static::getProfile($user), ]; } - public static function getProfile(Profile $profile) + public static function getProfile(User $user) { - $attributes = $profile->attributes; - unset($attributes['user_id']); + $attributes = $user->profile->attributes; + ArrayHelper::remove($attributes, 'user_id'); + + ArrayHelper::setValue( + $attributes, + 'image_url', + Url::to($user->profileImage->getUrl(), true), + ); + ArrayHelper::setValue( + $attributes, + 'banner_url', + Url::to($user->profileBannerImage->getUrl(), true), + ); + return $attributes; } diff --git a/docs/html/auth.html b/docs/html/auth.html index e89e486..0d1668c 100644 --- a/docs/html/auth.html +++ b/docs/html/auth.html @@ -387,7 +387,7 @@

Request samples

Content type
application/json
{
  • "username": "username@example.com",
  • "password": "password"
}

Response samples

Content type
{
  • "code": 200,
  • "message": "string",
  • "auth_token": "eyJ0eXAiOiJKV1QiLC .... tE_7_rLSX3vA",
  • "expired_at": "string"
}

User

Get current user

Responses

Response samples

Content type
application/json
{
  • "id": 14,
  • "guid": "cd081891-d2e2-40d5-84a4-b47309e71c80",
  • "display_name": "John Doe",
  • "account": {
    },
  • "profile": {
    }
}

Impersonate user

Request Body schema: application/json

id of user to Impersonate

+

Response samples

Content type
application/json
{
  • "id": 14,
  • "guid": "cd081891-d2e2-40d5-84a4-b47309e71c80",
  • "display_name": "John Doe",
  • "account": {
    },
  • "profile": {
    }
}

Impersonate user

Request Body schema: application/json

id of user to Impersonate

userId
required
integer

id of user to Impersonate

Responses

Request samples

Content type
application/json
{
  • "userId": 1
}

Response samples

Content type
application/json
{
  • "token": "impersonated-YvyEVcbzCvg0wLjb9yXylj1bkbotlCwkKjNKTZD9xMO86o1G-V9p-wklm5pUdXhdkSGj5dk-l",
  • "expires": 1681671865
}