Merge remote-tracking branch 'origin/feat/1.4.5/file' into test
This commit is contained in:
@@ -91,6 +91,9 @@ func (sc *SiteInfoController) GetSiteInfo(ctx *gin.Context) {
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
if legal, err := sc.siteInfoService.GetSiteLegal(ctx); err == nil {
|
||||
resp.Legal = &schema.SiteLegalSimpleResp{ExternalContentDisplay: legal.ExternalContentDisplay}
|
||||
}
|
||||
|
||||
handler.HandleResponse(ctx, nil, resp)
|
||||
}
|
||||
|
||||
@@ -96,14 +96,15 @@ type InitEnvironmentResp struct {
|
||||
|
||||
// InitBaseInfoReq init base info request
|
||||
type InitBaseInfoReq struct {
|
||||
Language string `validate:"required,gt=0,lte=30" json:"lang"`
|
||||
SiteName string `validate:"required,sanitizer,gt=0,lte=30" json:"site_name"`
|
||||
SiteURL string `validate:"required,gt=0,lte=512,url" json:"site_url"`
|
||||
ContactEmail string `validate:"required,email,gt=0,lte=500" json:"contact_email"`
|
||||
AdminName string `validate:"required,gt=3,lte=30" json:"name"`
|
||||
AdminPassword string `validate:"required,gte=8,lte=32" json:"password"`
|
||||
AdminEmail string `validate:"required,email,gt=0,lte=500" json:"email"`
|
||||
LoginRequired bool `json:"login_required"`
|
||||
Language string `validate:"required,gt=0,lte=30" json:"lang"`
|
||||
SiteName string `validate:"required,sanitizer,gt=0,lte=30" json:"site_name"`
|
||||
SiteURL string `validate:"required,gt=0,lte=512,url" json:"site_url"`
|
||||
ContactEmail string `validate:"required,email,gt=0,lte=500" json:"contact_email"`
|
||||
AdminName string `validate:"required,gt=3,lte=30" json:"name"`
|
||||
AdminPassword string `validate:"required,gte=8,lte=32" json:"password"`
|
||||
AdminEmail string `validate:"required,email,gt=0,lte=500" json:"email"`
|
||||
LoginRequired bool `json:"login_required"`
|
||||
ExternalContentDisplay string `validate:"required,oneof=always_display ask_before_display" json:"external_content_display"`
|
||||
}
|
||||
|
||||
func (r *InitBaseInfoReq) Check() (errFields []*validator.FormErrorField, err error) {
|
||||
|
||||
@@ -50,14 +50,15 @@ func NewMentor(ctx context.Context, engine *xorm.Engine, data *InitNeedUserInput
|
||||
}
|
||||
|
||||
type InitNeedUserInputData struct {
|
||||
Language string
|
||||
SiteName string
|
||||
SiteURL string
|
||||
ContactEmail string
|
||||
AdminName string
|
||||
AdminPassword string
|
||||
AdminEmail string
|
||||
LoginRequired bool
|
||||
Language string
|
||||
SiteName string
|
||||
SiteURL string
|
||||
ContactEmail string
|
||||
AdminName string
|
||||
AdminPassword string
|
||||
AdminEmail string
|
||||
LoginRequired bool
|
||||
ExternalContentDisplay string
|
||||
}
|
||||
|
||||
func (m *Mentor) InitDB() error {
|
||||
@@ -79,6 +80,7 @@ func (m *Mentor) InitDB() error {
|
||||
m.do("init site info user config", m.initSiteInfoUsersConfig)
|
||||
m.do("init site info privilege rank", m.initSiteInfoPrivilegeRank)
|
||||
m.do("init site info write", m.initSiteInfoWrite)
|
||||
m.do("init site info legal", m.initSiteInfoLegalConfig)
|
||||
m.do("init default content", m.initDefaultContent)
|
||||
m.do("init default badges", m.initDefaultBadges)
|
||||
return m.err
|
||||
@@ -185,7 +187,7 @@ func (m *Mentor) initSiteInfoGeneralData() {
|
||||
}
|
||||
|
||||
func (m *Mentor) initSiteInfoLoginConfig() {
|
||||
loginConfig := map[string]bool{
|
||||
loginConfig := map[string]interface{}{
|
||||
"allow_new_registrations": true,
|
||||
"allow_email_registrations": true,
|
||||
"allow_password_login": true,
|
||||
@@ -199,6 +201,18 @@ func (m *Mentor) initSiteInfoLoginConfig() {
|
||||
})
|
||||
}
|
||||
|
||||
func (m *Mentor) initSiteInfoLegalConfig() {
|
||||
legalConfig := map[string]interface{}{
|
||||
"external_content_display": m.userData.ExternalContentDisplay,
|
||||
}
|
||||
legalConfigDataBytes, _ := json.Marshal(legalConfig)
|
||||
_, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{
|
||||
Type: "legal",
|
||||
Content: string(legalConfigDataBytes),
|
||||
Status: 1,
|
||||
})
|
||||
}
|
||||
|
||||
func (m *Mentor) initSiteInfoThemeConfig() {
|
||||
themeConfig := `{"theme":"default","theme_config":{"default":{"navbar_style":"colored","primary_color":"#0033ff"}}}`
|
||||
_, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{
|
||||
|
||||
@@ -21,11 +21,45 @@ package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/apache/answer/internal/entity"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func addFileRecord(ctx context.Context, x *xorm.Engine) error {
|
||||
return x.Context(ctx).Sync(new(entity.FileRecord))
|
||||
if err := x.Context(ctx).Sync(new(entity.FileRecord)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set default external_content_display to always_display
|
||||
legalInfo := &entity.SiteInfo{Type: "legal"}
|
||||
exist, err := x.Context(ctx).Get(legalInfo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get legal config failed: %w", err)
|
||||
}
|
||||
legalConfig := make(map[string]interface{})
|
||||
if exist {
|
||||
if err := json.Unmarshal([]byte(legalInfo.Content), &legalConfig); err != nil {
|
||||
return fmt.Errorf("unmarshal legal config failed: %w", err)
|
||||
}
|
||||
}
|
||||
legalConfig["external_content_display"] = "always_display"
|
||||
legalConfigBytes, _ := json.Marshal(legalConfig)
|
||||
if exist {
|
||||
legalInfo.Content = string(legalConfigBytes)
|
||||
_, err = x.Context(ctx).ID(legalInfo.ID).Cols("content").Update(legalInfo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("update legal config failed: %w", err)
|
||||
}
|
||||
} else {
|
||||
legalInfo.Content = string(legalConfigBytes)
|
||||
legalInfo.Status = 1
|
||||
_, err = x.Context(ctx).Insert(legalInfo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("insert legal config failed: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -118,6 +118,7 @@ type SiteLegalReq struct {
|
||||
TermsOfServiceParsedText string `json:"terms_of_service_parsed_text"`
|
||||
PrivacyPolicyOriginalText string `json:"privacy_policy_original_text"`
|
||||
PrivacyPolicyParsedText string `json:"privacy_policy_parsed_text"`
|
||||
ExternalContentDisplay string `validate:"required,oneof=always_display ask_before_display" json:"external_content_display"`
|
||||
}
|
||||
|
||||
// GetSiteLegalInfoReq site site legal request
|
||||
@@ -237,6 +238,11 @@ type SiteWriteResp SiteWriteReq
|
||||
// SiteLegalResp site write response
|
||||
type SiteLegalResp SiteLegalReq
|
||||
|
||||
// SiteLegalSimpleResp site write response
|
||||
type SiteLegalSimpleResp struct {
|
||||
ExternalContentDisplay string `validate:"required,oneof=always_display ask_before_display" json:"external_content_display"`
|
||||
}
|
||||
|
||||
// SiteSeoResp site write response
|
||||
type SiteSeoResp SiteSeoReq
|
||||
|
||||
@@ -251,6 +257,7 @@ type SiteInfoResp struct {
|
||||
SiteSeo *SiteSeoResp `json:"site_seo"`
|
||||
SiteUsers *SiteUsersResp `json:"site_users"`
|
||||
Write *SiteWriteResp `json:"site_write"`
|
||||
Legal *SiteLegalSimpleResp `json:"site_legal"`
|
||||
Version string `json:"version"`
|
||||
Revision string `json:"revision"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user