Merge branch 'main' into dev

pull/574/head
Michael Li 2 months ago
commit 04dbb42e5a
No known key found for this signature in database

@ -18,6 +18,7 @@ import (
"github.com/rocboss/paopao-ce/cmd" "github.com/rocboss/paopao-ce/cmd"
"github.com/rocboss/paopao-ce/internal" "github.com/rocboss/paopao-ce/internal"
"github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/dao"
"github.com/rocboss/paopao-ce/internal/service" "github.com/rocboss/paopao-ce/internal/service"
"github.com/rocboss/paopao-ce/pkg/debug" "github.com/rocboss/paopao-ce/pkg/debug"
"github.com/rocboss/paopao-ce/pkg/utils" "github.com/rocboss/paopao-ce/pkg/utils"
@ -47,6 +48,7 @@ func init() {
} }
func deferFn() { func deferFn() {
dao.CloseDsx()
if cfg.If("Sentry") { if cfg.If("Sentry") {
// Flush buffered events before the program terminates. // Flush buffered events before the program terminates.
sentry.Flush(2 * time.Second) sentry.Flush(2 * time.Second)

@ -34,6 +34,14 @@ func MustGormDB() *gorm.DB {
return _gormdb return _gormdb
} }
func CloseGormDB() {
db, err := _gormdb.DB()
if err != nil {
log.Fatalf("close gorm db failed: %s", err)
}
_ = db.Close()
}
func newGormDB() (db *gorm.DB, err error) { func newGormDB() (db *gorm.DB, err error) {
newLogger := logger.New( newLogger := logger.New(
logrus.StandardLogger(), // io writer日志输出的目标前缀和日志包含的内容 logrus.StandardLogger(), // io writer日志输出的目标前缀和日志包含的内容

@ -88,6 +88,19 @@ func initDsX() {
logrus.Infof("use %s as core.ServantA with version %s", dsaVer.Name(), dsaVer.Version()) logrus.Infof("use %s as core.ServantA with version %s", dsaVer.Name(), dsaVer.Version())
} }
func CloseDsx() {
if cfg.If("Gorm") {
jinzhu.CloseDbObject()
} else if cfg.If("Sqlx") {
sakila.CloseDbObject()
} else if cfg.If("Sqlc") && cfg.Any("Postgres", "PostgreSQL") {
slonik.CloseDbObject()
} else {
// default use gorm as orm for sql database
jinzhu.CloseDbObject()
}
}
func initOSS() { func initOSS() {
var v core.VersionInfo var v core.VersionInfo
if cfg.If("AliOSS") { if cfg.If("AliOSS") {

@ -87,6 +87,10 @@ func NewDataService() (core.DataService, core.VersionInfo) {
return cache.NewCacheDataService(ds), ds return cache.NewCacheDataService(ds), ds
} }
func CloseDbObject() {
conf.CloseGormDB()
}
func NewWebDataServantA() (core.WebDataServantA, core.VersionInfo) { func NewWebDataServantA() (core.WebDataServantA, core.VersionInfo) {
lazyInitial() lazyInitial()
db := conf.MustGormDB() db := conf.MustGormDB()

@ -26,3 +26,7 @@ func NewAuthorizationManageService() core.AuthorizationManageService {
logrus.Fatal("not support now") logrus.Fatal("not support now")
return nil return nil
} }
func CloseDbObject() {
logrus.Fatal("not support now")
}

@ -26,3 +26,7 @@ func NewAuthorizationManageService() core.AuthorizationManageService {
logrus.Fatal("not support now") logrus.Fatal("not support now")
return nil return nil
} }
func CloseDbObject() {
logrus.Fatal("not support now")
}

@ -113,6 +113,7 @@ type TopicListResp struct {
} }
type TweetDetailReq struct { type TweetDetailReq struct {
BaseInfo `form:"-" binding:"-"`
SimpleInfo `form:"-" binding:"-"` SimpleInfo `form:"-" binding:"-"`
TweetId int64 `form:"id"` TweetId int64 `form:"id"`
} }

@ -508,6 +508,11 @@ func (s *looseSrv) TweetDetail(req *web.TweetDetailReq) (*web.TweetDetailResp, m
if err != nil { if err != nil {
return nil, web.ErrGetPostFailed return nil, web.ErrGetPostFailed
} }
// check current user permission
if xerr := checkPostViewPermission(req.User, post, s.Ds); xerr != nil {
return nil, xerr
}
postContents, err := s.Ds.GetPostContentsByIDs([]int64{post.ID}) postContents, err := s.Ds.GetPostContentsByIDs([]int64{post.ID})
if err != nil { if err != nil {
return nil, web.ErrGetPostFailed return nil, web.ErrGetPostFailed

@ -207,3 +207,29 @@ func checkPermision(user *ms.User, targetUserId int64) mir.Error {
} }
return nil return nil
} }
// checkPostViewPermission 检查当前用户是否可读指定post
func checkPostViewPermission(user *ms.User, post *ms.Post, ds core.DataService) mir.Error {
if post.Visibility == core.PostVisitPublic {
return nil
}
if user == nil {
return web.ErrNoPermission
}
if user.IsAdmin || user.ID == post.UserID {
return nil
}
if post.Visibility == core.PostVisitPrivate {
return web.ErrNoPermission
}
if post.Visibility == core.PostVisitFriend {
if !ds.IsFriend(post.UserID, user.ID) && !ds.IsFriend(user.ID, post.UserID) {
return web.ErrNoPermission
}
}
return nil
}

@ -5,7 +5,7 @@
<n-list class="main-content-wrap" bordered> <n-list class="main-content-wrap" bordered>
<n-list-item> <n-list-item>
<n-spin :show="loading"> <n-spin :show="loading">
<div class="detail-wrap" v-if="post.id > 1"> <div class="detail-wrap" v-if="post.id > 0">
<post-detail :post="post" @reload="reloadPost" /> <post-detail :post="post" @reload="reloadPost" />
</div> </div>
<div class="empty-wrap" v-else> <div class="empty-wrap" v-else>

Loading…
Cancel
Save