Skip to content

Commit

Permalink
Merge branch 'master' into enh/endpoint-get-user-by-source
Browse files Browse the repository at this point in the history
  • Loading branch information
luke- authored Sep 26, 2024
2 parents 457c28b + 3aa4498 commit a791754
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 36 deletions.
2 changes: 2 additions & 0 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public static function onBeforeRequest($event)
// User: Invite Controller
['pattern' => 'user/invite', 'route' => 'rest/user/invite/index', 'verb' => 'POST'],
['pattern' => 'user/invite', 'route' => 'rest/user/invite/list', 'verb' => 'GET'],
['pattern' => 'user/invite/<id:\d+>', 'route' => 'rest/user/invite/cancel', 'verb' => 'DELETE'],
['pattern' => 'user/invite/<id:\d+>', 'route' => 'rest/user/invite/resend', 'verb' => 'PATCH'],

// User: Session Controller
['pattern' => 'user/session/all/<id:\d+>', 'route' => 'rest/user/session/delete-from-user', 'verb' => 'DELETE'],
Expand Down
29 changes: 28 additions & 1 deletion controllers/user/InviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function getAccessRules()

public function actionIndex()
{
$emails = (array)Yii::$app->request->post('emails');
$emails = (array) Yii::$app->request->post('emails');
if (!$emails) {
return $this->returnError(404, 'Please provide an array of emails in the json format');
}
Expand Down Expand Up @@ -70,6 +70,33 @@ public function actionList()
return $this->returnPagination($query, $pagination, $results);
}

public function actionResend($id)
{
$userInvite = Invite::find()->where(['id' => $id, 'source' => Invite::SOURCE_INVITE])->one();

if (!$userInvite) {
return $this->returnError(404, 'Invite not found!');
}

$userInvite->save();
$userInvite->sendInviteMail();

return $this->returnSuccess('Invite has been resent.');
}

public function actionCancel($id)
{
$userInvite = Invite::find()->where(['id' => $id, 'source' => Invite::SOURCE_INVITE])->one();

if (!$userInvite) {
return $this->returnError(404, 'Invite not found!');
}

$userInvite->delete();

return $this->returnSuccess('Invite has been canceled.');
}

protected function createInvite($email)
{
$userInvite = new Invite();
Expand Down
2 changes: 2 additions & 0 deletions definitions/InviteDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace humhub\modules\rest\definitions;

use humhub\modules\rest\models\Invite;
use yii\helpers\Url;

class InviteDefinitions
{
Expand All @@ -15,6 +16,7 @@ public static function getInvite(Invite $invite)
'lastname' => $invite->lastname,
'language' => $invite->language,
'space' => $invite->space ? SpaceDefinitions::getSpaceShort($invite->space) : null,
'invitationUrl' => Url::to(['/user/registration', 'token' => $invite->token], true),
'originator' => $invite->originator ? UserDefinitions::getUserShort($invite->originator) : null,
'createdBy' => $invite->createdBy ? UserDefinitions::getUserShort($invite->createdBy) : null,
'updatedBy' => $invite->updatedBy ? UserDefinitions::getUserShort($invite->updatedBy) : null,
Expand Down
21 changes: 17 additions & 4 deletions definitions/UserDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Changelog
=========

0.10.4 (Unreleased)
---------------------------
0.10.4 (September 9, 2024)
--------------------------
- Enh #180: Improved `user/get-by-authclient` endpoint to support additional authentication clients.
- Enh #181: Added user profile `image_url` and `banner_url`
- Enh #179: Added new `resend` and `cancel` endpoints for user invite

0.10.3 (September 13, 2024)
---------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/html/auth.html

Large diffs are not rendered by default.

27 changes: 16 additions & 11 deletions docs/html/user.html

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions docs/swagger/user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,29 @@ paths:
type: array
items:
$ref: "user.yaml#/definitions/Invite"
'/user/invite/{id}':
patch:
tags:
- Invite
summary: Resend invite
description: Resends invitation email
produces:
- application/json
- application/xml
responses:
'200':
description: Successful operation
delete:
tags:
- Invite
summary: Cancel invite
description: Cancels the invite, making the invitation URL no longer valid.
produces:
- application/json
- application/xml
responses:
'200':
description: Successful operation

#-----------------------------------------------------------------------------------------------------------------------
# Begin Session
Expand Down Expand Up @@ -720,6 +743,10 @@ definitions:
type: string
url_twitter:
type: string
image_url:
type: string
banner_url:
type: string
xml:
name: Profile

Expand Down Expand Up @@ -789,6 +816,10 @@ definitions:
space:
readOnly: true
$ref: "space.yaml#/definitions/SpaceShort"
invitationUrl:
type: string
readOnly: true
example: "http://example.com/user/registration?token=cK4FCaopFHNP"
originator:
readOnly: true
$ref: "user.yaml#/definitions/UserShort"
Expand Down
32 changes: 16 additions & 16 deletions messages/pt-BR/base.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php
return array (
'<strong>REST</strong> Configuration' => '',
'Access Tokens' => '',
'Add Access Token' => '',
'Allow Bearer Authentication' => '',
'Allow HTTP Basic Authentication' => '',
'Allow JWT Authentication' => '',
'Allow Query Param Bearer Authentication' => '',
'Bearer Access Token Successfully Revoked' => '',
'Bearer Auth' => '',
'<strong>REST</strong> Configuration' => 'Configuração <strong>REST</strong>',
'Access Tokens' => 'Tokens de acesso',
'Add Access Token' => 'Adicionar Token de Acesso',
'Allow Bearer Authentication' => 'Permitir autenticação do portador',
'Allow HTTP Basic Authentication' => 'Permitir autenticação básica HTTP',
'Allow JWT Authentication' => 'Permitir autenticação JWT',
'Allow Query Param Bearer Authentication' => 'Permitir autenticação do portador do parâmetro de consulta',
'Bearer Access Token Successfully Revoked' => 'Token de acesso ao portador revogado com sucesso',
'Bearer Auth' => 'Autorização do Portador',
'Enabled for all registered users' => 'Habilitado para todos os usuários registrados',
'Expiration' => '',
'Expiration' => 'Validade',
'General' => 'Geral',
'JWT Auth' => '',
'JWT Key' => 'JWT Chave',
'JWT Token Expiration' => '',
'No enabled modules found with additional REST API endpoints.' => '',
'Token' => '',
'User' => 'Do utilizador',
'JWT Auth' => 'Autenticação JWT',
'JWT Key' => 'Chave JWT',
'JWT Token Expiration' => 'Validade do Token JWT',
'No enabled modules found with additional REST API endpoints.' => 'Nenhum módulo habilitado encontrado com endpoints de API REST adicionais.',
'Token' => 'Token',
'User' => 'Usuário',
);

0 comments on commit a791754

Please sign in to comment.