Skip to content

Commit d5c07f1

Browse files
committed
Merge remote-tracking branch 'origin/dev' into test
2 parents 9e236f6 + a1f0b09 commit d5c07f1

File tree

7 files changed

+65
-2
lines changed

7 files changed

+65
-2
lines changed

internal/entity/user_entity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type User struct {
6060
Status int `xorm:"not null default 1 INT(11) status"`
6161
AuthorityGroup int `xorm:"not null default 1 INT(11) authority_group"`
6262
DisplayName string `xorm:"not null default '' VARCHAR(30) display_name"`
63-
Avatar string `xorm:"not null default '' VARCHAR(1024) avatar"`
63+
Avatar string `xorm:"not null default '' VARCHAR(2048) avatar"`
6464
Mobile string `xorm:"not null VARCHAR(20) mobile"`
6565
Bio string `xorm:"not null TEXT bio"`
6666
BioHTML string `xorm:"not null TEXT bio_html"`

internal/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ var migrations = []Migration{
104104
NewMigration("v1.5.1", "add plugin kv storage", addPluginKVStorage, true),
105105
NewMigration("v1.6.0", "move user config to interface", moveUserConfigToInterface, true),
106106
NewMigration("v1.7.0", "add optional tags", addOptionalTags, true),
107+
NewMigration("v1.7.2", "expand avatar column length", expandAvatarColumnLength, false),
107108
}
108109

109110
func GetMigrations() []Migration {

internal/migrations/v29.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package migrations
21+
22+
import (
23+
"context"
24+
"fmt"
25+
26+
"xorm.io/xorm"
27+
)
28+
29+
func expandAvatarColumnLength(ctx context.Context, x *xorm.Engine) error {
30+
type User struct {
31+
Avatar string `xorm:"not null default '' VARCHAR(2048) avatar"`
32+
}
33+
if err := x.Context(ctx).Sync(new(User)); err != nil {
34+
return fmt.Errorf("expand avatar column length failed: %w", err)
35+
}
36+
return nil
37+
}

internal/repo/user_external_login/user_external_login_repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (ur *userExternalLoginRepo) GetByUserID(ctx context.Context, provider, user
8787
func (ur *userExternalLoginRepo) GetUserExternalLoginList(ctx context.Context, userID string) (
8888
resp []*entity.UserExternalLogin, err error) {
8989
resp = make([]*entity.UserExternalLogin, 0)
90-
err = ur.data.DB.Context(ctx).Where("user_id = ?", userID).Find(&resp)
90+
err = ur.data.DB.Context(ctx).Where("user_id = ?", userID).OrderBy("updated_at DESC").Find(&resp)
9191
if err != nil {
9292
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
9393
}

internal/service/content/answer_service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ func (as *AnswerService) AcceptAnswer(ctx context.Context, req *schema.AcceptAns
455455
if !exist {
456456
return errors.BadRequest(reason.AnswerNotFound)
457457
}
458+
459+
// check answer belong to question
460+
if acceptedAnswerInfo.QuestionID != req.QuestionID {
461+
return errors.BadRequest(reason.AnswerNotFound)
462+
}
458463
acceptedAnswerInfo.ID = uid.DeShortID(acceptedAnswerInfo.ID)
459464
}
460465

internal/service/notification/new_question_notification.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,19 @@ func (ns *ExternalNotificationService) syncNewQuestionNotificationToPlugin(ctx c
238238
}
239239
}
240240

241+
// Get all external logins as fallback
242+
externalLogins, err := ns.userExternalLoginRepo.GetUserExternalLoginList(ctx, subscriberUserID)
243+
if err != nil {
244+
log.Errorf("get user external login list failed for user %s: %v", subscriberUserID, err)
245+
} else if len(externalLogins) > 0 {
246+
newMsg.ReceiverExternalID = externalLogins[0].ExternalID
247+
if len(externalLogins) > 1 {
248+
log.Debugf("user %s has %d SSO logins, using most recent: provider=%s",
249+
subscriberUserID, len(externalLogins), externalLogins[0].Provider)
250+
}
251+
}
252+
253+
// Try to get external login specific to this plugin (takes precedence over fallback)
241254
userInfo, exist, err := ns.userExternalLoginRepo.GetByUserID(ctx, fn.Info().SlugName, subscriberUserID)
242255
if err != nil {
243256
log.Errorf("get user external login info failed: %v", err)

internal/service/notification_common/notification.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,13 @@ func (ns *NotificationCommon) syncNotificationToPlugin(ctx context.Context, objI
423423
}
424424
}
425425

426+
externalLogins, err := ns.userExternalLoginRepo.GetUserExternalLoginList(ctx, msg.ReceiverUserID)
427+
if err != nil {
428+
log.Errorf("get user external login list failed for user %s: %v", msg.ReceiverUserID, err)
429+
} else if len(externalLogins) > 0 {
430+
pluginNotificationMsg.ReceiverExternalID = externalLogins[0].ExternalID
431+
}
432+
426433
_ = plugin.CallNotification(func(fn plugin.Notification) error {
427434
userInfo, exist, err := ns.userExternalLoginRepo.GetByUserID(ctx, fn.Info().SlugName, msg.ReceiverUserID)
428435
if err != nil {

0 commit comments

Comments
 (0)