From c7ac7d6484878a3430414c5c890455d29a20e44a Mon Sep 17 00:00:00 2001 From: gevorgmansuryan Date: Sat, 21 Sep 2024 04:14:27 +0400 Subject: [PATCH 1/3] Added new endpoint to get user by source --- Events.php | 1 + controllers/user/UserController.php | 12 ++++++++++++ docs/CHANGELOG.md | 4 ++++ docs/html/user.html | 26 +++++++++++++++----------- docs/swagger/user.yaml | 26 ++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 11 deletions(-) diff --git a/Events.php b/Events.php index e7ee16a..6f8a4cb 100644 --- a/Events.php +++ b/Events.php @@ -65,6 +65,7 @@ public static function onBeforeRequest($event) ['pattern' => 'user/get-by-username', 'route' => 'rest/user/user/get-by-username', 'verb' => ['GET', 'HEAD']], ['pattern' => 'user/get-by-email', 'route' => 'rest/user/user/get-by-email', 'verb' => ['GET', 'HEAD']], ['pattern' => 'user/get-by-authclient', 'route' => 'rest/user/user/get-by-authclient', 'verb' => ['GET', 'HEAD']], + ['pattern' => 'user/get-by-source', 'route' => 'rest/user/user/get-by-source', 'verb' => ['GET', 'HEAD']], ['pattern' => 'user/', 'route' => 'rest/user/user/view', 'verb' => ['GET', 'HEAD']], ['pattern' => 'user/', 'route' => 'rest/user/user/update', 'verb' => ['PUT', 'PATCH']], ['pattern' => 'user/', 'route' => 'rest/user/user/delete', 'verb' => ['DELETE']], diff --git a/controllers/user/UserController.php b/controllers/user/UserController.php index 9c519c9..517660d 100644 --- a/controllers/user/UserController.php +++ b/controllers/user/UserController.php @@ -14,6 +14,7 @@ use humhub\modules\user\models\Password; use humhub\modules\user\models\Profile; use humhub\modules\user\models\User; +use humhub\modules\user\models\Auth as UserAuth; use Yii; use yii\web\HttpException; @@ -102,6 +103,17 @@ public function actionGetByAuthclient($name, $id) return $this->actionView($user->id); } + public function actionGetBySource($source, $id) + { + $auth = UserAuth::findOne(['source' => $source, 'source_id' => $id]); + + if (empty($auth->user)) { + return $this->returnError(404, 'User not found!'); + } + + return $this->actionView($auth->user->id); + } + public function actionView($id) { $user = User::findOne(['id' => $id]); diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2087b88..576a2f6 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +0.10.4 (Unreleased) +--------------------------- +- Enh #180: Added new `user/get-by-source` endpoint to get user by source + 0.10.3 (September 13, 2024) --------------------------- - Enh #177: Collect user data for Legal module diff --git a/docs/html/user.html b/docs/html/user.html index 40fa5a2..85ec23b 100644 --- a/docs/html/user.html +++ b/docs/html/user.html @@ -391,7 +391,7 @@ -
id
required
string

Authentication client ID

Responses

Response samples

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

Get user by user id

path Parameters
id
required
integer

The id of user

+

Response samples

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

Get user by source

query Parameters
source
required
string

Source

+
id
required
string

Source ID

+

Responses

Response samples

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

Get user by user id

path Parameters
id
required
integer

The id of user

Responses

Response samples

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

Update an existing user

path Parameters
id
required
integer

The id of user

+

Response samples

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

Update an existing user

path Parameters
id
required
integer

The id of user

Request Body schema: application/json

Updated user object

object (Account)
object (Profile)
object (Password)

Responses

Request samples

Content type
application/json
{
  • "account": {
    },
  • "profile": {
    },
  • "password": {
    }
}

Response samples

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

Soft deletes an user by id

path Parameters
id
required
integer

The id of user

+

Request samples

Content type
application/json
{
  • "account": {
    },
  • "profile": {
    },
  • "password": {
    }
}

Response samples

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

Soft deletes an user by id

path Parameters
id
required
integer

The id of user

Responses

Find all Groups

query Parameters
page
string >= 0

The number of page of the result set.

limit
string [ 1 .. 50 ]
Default: 20

The numbers of items to return per page.

Responses

Response samples

Content type
{
  • "total": 76,
  • "page": 1,
  • "results": [
    ]
}

Adds a new group

Request Body schema: application/json

The added Group object

+

Response samples

Content type
{
  • "total": 76,
  • "page": 1,
  • "results": [
    ]
}

Adds a new group

Request Body schema: application/json

The added Group object

name
string
description
string
show_at_directory
boolean
show_at_registration
boolean
sort_order
int

Responses

Request samples

Content type
application/json
{
  • "name": "Example group",
  • "description": "Users of Example",
  • "show_at_directory": false,
  • "show_at_registration": false,
  • "sort_order": 100
}

Get group by id

path Parameters
id
required
integer

The id of group

+

Request samples

Content type
application/json
{
  • "name": "Example group",
  • "description": "Users of Example",
  • "show_at_directory": false,
  • "show_at_registration": false,
  • "sort_order": 100
}

Get group by id

path Parameters
id
required
integer

The id of group

Responses

Response samples

Content type
application/json
{
  • "id": 1,
  • "name": "Example group",
  • "description": "Users of Example",
  • "show_at_directory": false,
  • "show_at_registration": false,
  • "sort_order": 100
}

List members

Lists all members of the given group id.

+

Response samples

Content type
application/json
{
  • "id": 1,
  • "name": "Example group",
  • "description": "Users of Example",
  • "show_at_directory": false,
  • "show_at_registration": false,
  • "sort_order": 100
}

List members

Lists all members of the given group id.

path Parameters
id
required
integer

The id of the group

Responses

Response samples

Content type
{}

Add a new member

Adds new member to the given group

+

Response samples

Content type
{}

Add a new member

Adds new member to the given group

path Parameters
id
required
integer

The id of group

query Parameters
userId
required
integer

The id of user

isManager
boolean
Default: false

Is group manager

@@ -470,16 +474,16 @@

Invite new users

Request Body schema: application/json

Emails of people you want to invite

emails
required
Array of any

An array of email addresses

Responses

Request samples

Content type
application/json
{
  • "emails": [
    ]
}

Pending invites

Returns list of pending invites

+

Request samples

Content type
application/json
{
  • "emails": [
    ]
}

Pending invites

Returns list of pending invites

Responses

Response samples

Content type
{
  • "total": 76,
  • "page": 1,
  • "results": [
    ]
}

Session

User sessions

+

Response samples

Content type
{
  • "total": 76,
  • "page": 1,
  • "results": [
    ]
}

Session

User sessions

Deletes all sessions for a particular user

path Parameters
id
required
integer

The id of user

Responses