feat: Implement public access for tenant content
- Add TenantOptionalAuth middleware to allow access to public content without requiring authentication. - Introduce ListPublicPublished and PublicDetail methods in the content service to retrieve publicly accessible content. - Create tenant_public HTTP routes for listing and showing public content, including preview and main asset retrieval. - Enhance content tests to cover scenarios for public content access and permissions. - Update specifications to reflect the new public content access features and rules.
This commit is contained in:
87
backend/app/http/tenant_join/join.go
Normal file
87
backend/app/http/tenant_join/join.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package tenant_join
|
||||
|
||||
import (
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/tenant_join/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/providers/jwt"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// join 提供“非成员加入租户”的相关接口(邀请码加入 / 申请加入)。
|
||||
//
|
||||
// @provider
|
||||
type join struct{}
|
||||
|
||||
// joinByInvite
|
||||
//
|
||||
// @Summary 通过邀请码加入租户
|
||||
// @Tags TenantJoin
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param form body dto.JoinByInviteForm true "Form"
|
||||
// @Success 200 {object} models.TenantUser
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/join/invite [post]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind claims local key(claims)
|
||||
// @Bind form body
|
||||
func (*join) joinByInvite(
|
||||
ctx fiber.Ctx,
|
||||
tenant *models.Tenant,
|
||||
claims *jwt.Claims,
|
||||
form *dto.JoinByInviteForm,
|
||||
) (*models.TenantUser, error) {
|
||||
if tenant == nil || claims == nil {
|
||||
return nil, errorx.ErrInternalError.WithMsg("context missing")
|
||||
}
|
||||
if form == nil {
|
||||
return nil, errorx.ErrInvalidParameter
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": claims.UserID,
|
||||
}).Info("tenantjoin.join_by_invite")
|
||||
|
||||
return services.Tenant.JoinByInvite(ctx.Context(), tenant.ID, claims.UserID, form.InviteCode)
|
||||
}
|
||||
|
||||
// createJoinRequest
|
||||
//
|
||||
// @Summary 提交加入租户申请
|
||||
// @Tags TenantJoin
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param form body dto.JoinRequestCreateForm true "Form"
|
||||
// @Success 200 {object} models.TenantJoinRequest
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/join/request [post]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind claims local key(claims)
|
||||
// @Bind form body
|
||||
func (*join) createJoinRequest(
|
||||
ctx fiber.Ctx,
|
||||
tenant *models.Tenant,
|
||||
claims *jwt.Claims,
|
||||
form *dto.JoinRequestCreateForm,
|
||||
) (*models.TenantJoinRequest, error) {
|
||||
if tenant == nil || claims == nil {
|
||||
return nil, errorx.ErrInternalError.WithMsg("context missing")
|
||||
}
|
||||
if form == nil {
|
||||
return nil, errorx.ErrInvalidParameter
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": claims.UserID,
|
||||
}).Info("tenant_join.create_join_request")
|
||||
|
||||
return services.Tenant.CreateJoinRequest(ctx.Context(), tenant.ID, claims.UserID, form)
|
||||
}
|
||||
Reference in New Issue
Block a user