Merge pull request #1226 from trheyi/main
Update team invitation handling and user invitation acceptance logic
This commit is contained in:
commit
93b48f474c
2 changed files with 15 additions and 11 deletions
|
|
@ -278,7 +278,8 @@ func (u *DefaultUser) AcceptInvitation(ctx context.Context, invitationID string,
|
||||||
updateData := maps.MapStrAny{
|
updateData := maps.MapStrAny{
|
||||||
"status": "active",
|
"status": "active",
|
||||||
"joined_at": time.Now(),
|
"joined_at": time.Now(),
|
||||||
"invitation_token": nil, // Clear the token
|
"invitation_token": nil, // Clear the token
|
||||||
|
"__yao_updated_by": userID, // Set the updated by user ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// If invitation doesn't have a user_id (unregistered user invitation), update it with provided userID
|
// If invitation doesn't have a user_id (unregistered user invitation), update it with provided userID
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"github.com/yaoapp/yao/messenger"
|
"github.com/yaoapp/yao/messenger"
|
||||||
messengertypes "github.com/yaoapp/yao/messenger/types"
|
messengertypes "github.com/yaoapp/yao/messenger/types"
|
||||||
"github.com/yaoapp/yao/openapi/oauth"
|
"github.com/yaoapp/yao/openapi/oauth"
|
||||||
|
"github.com/yaoapp/yao/openapi/oauth/authorized"
|
||||||
"github.com/yaoapp/yao/openapi/response"
|
"github.com/yaoapp/yao/openapi/response"
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
)
|
)
|
||||||
|
|
@ -216,14 +217,16 @@ func GinTeamInvitationGet(c *gin.Context) {
|
||||||
// GinTeamInvitationCreate handles POST /teams/:team_id/invitations - Send team invitation
|
// GinTeamInvitationCreate handles POST /teams/:team_id/invitations - Send team invitation
|
||||||
func GinTeamInvitationCreate(c *gin.Context) {
|
func GinTeamInvitationCreate(c *gin.Context) {
|
||||||
// Get authorized user info
|
// Get authorized user info
|
||||||
authInfo := oauth.GetAuthorizedInfo(c)
|
authInfo := authorized.GetInfo(c)
|
||||||
if authInfo == nil || authInfo.UserID == "" {
|
if authInfo.Constraints.OwnerOnly || authInfo.Constraints.TeamOnly {
|
||||||
errorResp := &response.ErrorResponse{
|
if authInfo == nil || authInfo.UserID == "" {
|
||||||
Code: response.ErrInvalidClient.Code,
|
errorResp := &response.ErrorResponse{
|
||||||
ErrorDescription: "User not authenticated",
|
Code: response.ErrInvalidClient.Code,
|
||||||
|
ErrorDescription: "User not authenticated",
|
||||||
|
}
|
||||||
|
response.RespondWithError(c, response.StatusUnauthorized, errorResp)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
response.RespondWithError(c, response.StatusUnauthorized, errorResp)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
teamID := c.Param("id")
|
teamID := c.Param("id")
|
||||||
|
|
@ -251,7 +254,7 @@ func GinTeamInvitationCreate(c *gin.Context) {
|
||||||
requestBaseURL := getRequestBaseURL(c)
|
requestBaseURL := getRequestBaseURL(c)
|
||||||
|
|
||||||
// Prepare invitation data
|
// Prepare invitation data
|
||||||
invitationData := maps.MapStrAny{
|
invitationData := authInfo.WithCreateScope(maps.MapStrAny{
|
||||||
"user_id": req.UserID,
|
"user_id": req.UserID,
|
||||||
"email": req.Email,
|
"email": req.Email,
|
||||||
"member_type": req.MemberType,
|
"member_type": req.MemberType,
|
||||||
|
|
@ -259,7 +262,7 @@ func GinTeamInvitationCreate(c *gin.Context) {
|
||||||
"message": req.Message,
|
"message": req.Message,
|
||||||
"expiry": req.Expiry,
|
"expiry": req.Expiry,
|
||||||
"request_base_url": requestBaseURL,
|
"request_base_url": requestBaseURL,
|
||||||
}
|
})
|
||||||
|
|
||||||
// Prepare settings
|
// Prepare settings
|
||||||
settings := &InvitationSettings{}
|
settings := &InvitationSettings{}
|
||||||
|
|
@ -454,7 +457,7 @@ func GinTeamInvitationDelete(c *gin.Context) {
|
||||||
// GinTeamInvitationAccept handles POST /user/teams/invitations/:invitation_id/accept - Accept invitation and login to team
|
// GinTeamInvitationAccept handles POST /user/teams/invitations/:invitation_id/accept - Accept invitation and login to team
|
||||||
func GinTeamInvitationAccept(c *gin.Context) {
|
func GinTeamInvitationAccept(c *gin.Context) {
|
||||||
// Get authorized user info
|
// Get authorized user info
|
||||||
authInfo := oauth.GetAuthorizedInfo(c)
|
authInfo := authorized.GetInfo(c)
|
||||||
if authInfo == nil || authInfo.UserID == "" {
|
if authInfo == nil || authInfo.UserID == "" {
|
||||||
errorResp := &response.ErrorResponse{
|
errorResp := &response.ErrorResponse{
|
||||||
Code: response.ErrInvalidClient.Code,
|
Code: response.ErrInvalidClient.Code,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue