Skip to content

Commit

Permalink
Added new endpoint to get user by source
Browse files Browse the repository at this point in the history
  • Loading branch information
gevorgmansuryan committed Sep 21, 2024
1 parent 51c1576 commit c7ac7d6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
1 change: 1 addition & 0 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/<id:\d+>', 'route' => 'rest/user/user/view', 'verb' => ['GET', 'HEAD']],
['pattern' => 'user/<id:\d+>', 'route' => 'rest/user/user/update', 'verb' => ['PUT', 'PATCH']],
['pattern' => 'user/<id:\d+>', 'route' => 'rest/user/user/delete', 'verb' => ['DELETE']],
Expand Down
12 changes: 12 additions & 0 deletions controllers/user/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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]);
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit c7ac7d6

Please sign in to comment.