Skip to content

Commit

Permalink
fate: api, rpc QuitGroup req add userID (#1244)
Browse files Browse the repository at this point in the history
* feat: v2 to v3 data conversion

* feat: v2 to v3 data conversion

* fix: CallbackBeforeCreateGroup

* fix: NotificationUserInfoUpdate

* fix: NotificationUserInfoUpdate

* chore: update pkg github.com/OpenIMSDK/protocol v0.0.26

* chore: code format

* update pkg

* feat: QuitGroup support administrator operations

* feat: QuitGroup support administrator operations

* fix: checkMongo uri

* fix: k8s minio prefix

* fix: k8s minio prefix

* fix: k8s minio prefix

* fix: k8s minio prefix test

* fix: k8s minio prefix test
  • Loading branch information
withchao committed Oct 20, 2023
1 parent 4b23171 commit c69d4da
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 25 deletions.
20 changes: 14 additions & 6 deletions internal/rpc/group/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,32 +852,40 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbgroup.JoinGroupReq)

func (s *groupServer) QuitGroup(ctx context.Context, req *pbgroup.QuitGroupReq) (*pbgroup.QuitGroupResp, error) {
resp := &pbgroup.QuitGroupResp{}
if req.UserID == "" {
req.UserID = mcontext.GetOpUserID(ctx)
} else {
if err := authverify.CheckAccessV3(ctx, req.UserID); err != nil {
return nil, err
}
}
group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupID)
if err != nil {
return nil, err
}
if group.GroupType == constant.SuperGroup {
if err := s.GroupDatabase.DeleteSuperGroupMember(ctx, req.GroupID, []string{mcontext.GetOpUserID(ctx)}); err != nil {
if err := s.GroupDatabase.DeleteSuperGroupMember(ctx, req.GroupID, []string{req.UserID}); err != nil {
return nil, err
}
s.Notification.SuperGroupNotification(ctx, mcontext.GetOpUserID(ctx), mcontext.GetOpUserID(ctx))
_ = s.Notification.SuperGroupNotification(ctx, req.UserID, req.UserID)
} else {
info, err := s.TakeGroupMember(ctx, req.GroupID, mcontext.GetOpUserID(ctx))
info, err := s.TakeGroupMember(ctx, req.GroupID, req.UserID)
if err != nil {
return nil, err
}
if info.RoleLevel == constant.GroupOwner {
return nil, errs.ErrNoPermission.Wrap("group owner can't quit")
}
err = s.GroupDatabase.DeleteGroupMember(ctx, req.GroupID, []string{mcontext.GetOpUserID(ctx)})
err = s.GroupDatabase.DeleteGroupMember(ctx, req.GroupID, []string{req.UserID})
if err != nil {
return nil, err
}
s.Notification.MemberQuitNotification(ctx, s.groupMemberDB2PB(info, 0))
_ = s.Notification.MemberQuitNotification(ctx, s.groupMemberDB2PB(info, 0))
}
if err := s.deleteMemberAndSetConversationSeq(ctx, req.GroupID, []string{mcontext.GetOpUserID(ctx)}); err != nil {
if err := s.deleteMemberAndSetConversationSeq(ctx, req.GroupID, []string{req.UserID}); err != nil {
return nil, err
}

return resp, nil
}

Expand Down
52 changes: 33 additions & 19 deletions pkg/common/db/s3/minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,48 @@ const (
)

func NewMinio() (s3.Interface, error) {
conf := config.Config.Object.Minio
u, err := url.Parse(conf.Endpoint)
u, err := url.Parse(config.Config.Object.Minio.Endpoint)
if err != nil {
return nil, err
}
opts := &minio.Options{
Creds: credentials.NewStaticV4(conf.AccessKeyID, conf.SecretAccessKey, conf.SessionToken),
Creds: credentials.NewStaticV4(config.Config.Object.Minio.AccessKeyID, config.Config.Object.Minio.SecretAccessKey, config.Config.Object.Minio.SessionToken),
Secure: u.Scheme == "https",
}
client, err := minio.New(u.Host, opts)
if err != nil {
return nil, err
}
m := &Minio{
bucket: conf.Bucket,
bucket: config.Config.Object.Minio.Bucket,
core: &minio.Core{Client: client},
lock: &sync.Mutex{},
init: false,
}
if conf.SignEndpoint == "" || conf.SignEndpoint == conf.Endpoint {
if config.Config.Object.Minio.SignEndpoint == "" || config.Config.Object.Minio.SignEndpoint == config.Config.Object.Minio.Endpoint {
m.opts = opts
m.sign = m.core.Client
m.bucketURL = conf.Endpoint + "/" + conf.Bucket + "/"
m.prefix = u.Path
u.Path = ""
config.Config.Object.Minio.Endpoint = u.String()
m.signEndpoint = config.Config.Object.Minio.Endpoint
} else {
su, err := url.Parse(conf.SignEndpoint)
su, err := url.Parse(config.Config.Object.Minio.SignEndpoint)
if err != nil {
return nil, err
}
m.opts = &minio.Options{
Creds: credentials.NewStaticV4(conf.AccessKeyID, conf.SecretAccessKey, conf.SessionToken),
Creds: credentials.NewStaticV4(config.Config.Object.Minio.AccessKeyID, config.Config.Object.Minio.SecretAccessKey, config.Config.Object.Minio.SessionToken),
Secure: su.Scheme == "https",
}
m.sign, err = minio.New(su.Host, m.opts)
if err != nil {
return nil, err
}
m.bucketURL = conf.SignEndpoint + "/" + conf.Bucket + "/"
m.prefix = su.Path
su.Path = ""
config.Config.Object.Minio.SignEndpoint = su.String()
m.signEndpoint = config.Config.Object.Minio.SignEndpoint
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand All @@ -110,14 +115,15 @@ func NewMinio() (s3.Interface, error) {
}

type Minio struct {
bucket string
bucketURL string
location string
opts *minio.Options
core *minio.Core
sign *minio.Client
lock sync.Locker
init bool
bucket string
signEndpoint string
location string
opts *minio.Options
core *minio.Core
sign *minio.Client
lock sync.Locker
init bool
prefix string
}

func (m *Minio) initMinio(ctx context.Context) error {
Expand Down Expand Up @@ -255,7 +261,7 @@ func (m *Minio) AuthSign(ctx context.Context, uploadID string, name string, expi
return nil, err
}
result := s3.AuthSignResult{
URL: m.bucketURL + name,
URL: m.signEndpoint + "/" + m.bucket + "/" + name,
Query: url.Values{"uploadId": {uploadID}},
Parts: make([]s3.SignPart, len(partNumbers)),
}
Expand All @@ -269,11 +275,13 @@ func (m *Minio) AuthSign(ctx context.Context, uploadID string, name string, expi
request = signer.SignV4Trailer(*request, creds.AccessKeyID, creds.SecretAccessKey, creds.SessionToken, m.location, nil)
result.Parts[i] = s3.SignPart{
PartNumber: partNumber,
URL: request.URL.String(),
Query: url.Values{"partNumber": {strconv.Itoa(partNumber)}},
Header: request.Header,
}
}
if m.prefix != "" {
result.URL = m.signEndpoint + m.prefix + "/" + m.bucket + "/" + name
}
return &result, nil
}

Expand All @@ -285,6 +293,9 @@ func (m *Minio) PresignedPutObject(ctx context.Context, name string, expire time
if err != nil {
return "", err
}
if m.prefix != "" {
rawURL.Path = path.Join(m.prefix, rawURL.Path)
}
return rawURL.String(), nil
}

Expand Down Expand Up @@ -396,6 +407,9 @@ func (m *Minio) presignedGetObject(ctx context.Context, name string, expire time
if err != nil {
return "", err
}
if m.prefix != "" {
rawURL.Path = path.Join(m.prefix, rawURL.Path)
}
return rawURL.String(), nil
}

Expand Down

0 comments on commit c69d4da

Please sign in to comment.