From 2c8a06546e993e6a8de311bee93be8060304718b Mon Sep 17 00:00:00 2001 From: yoneyan Date: Sat, 20 Mar 2021 03:57:05 +0900 Subject: [PATCH] [fix] #74 --- pkg/api/core/auth/interface.go | 5 +- pkg/api/core/auth/v0/auth.go | 44 ++++------- .../core/group/connection/v0/connection.go | 12 +-- pkg/api/core/group/info/v0/info.go | 2 +- .../group/service/jpnicAdmin/v0/jpnicAdmin.go | 2 +- .../group/service/jpnicTech/v0/jpnicTech.go | 2 +- pkg/api/core/group/service/v0/service.go | 16 ++-- pkg/api/core/group/v0/group.go | 76 +++++++++++-------- pkg/api/core/interface.go | 2 + pkg/api/core/support/chat/v0/chat.go | 2 +- pkg/api/core/support/ticket/v0/ticket.go | 18 ++--- pkg/api/core/user/v0/user.go | 4 +- pkg/api/store/token/v0/token.go | 5 +- 13 files changed, 97 insertions(+), 93 deletions(-) diff --git a/pkg/api/core/auth/interface.go b/pkg/api/core/auth/interface.go index 9e22bed5..adfcd39c 100644 --- a/pkg/api/core/auth/interface.go +++ b/pkg/api/core/auth/interface.go @@ -10,9 +10,8 @@ type UserResult struct { } type GroupResult struct { - Group core.Group - User core.User - Err error + User core.User + Err error } type AdminStruct struct { diff --git a/pkg/api/core/auth/v0/auth.go b/pkg/api/core/auth/v0/auth.go index 23026703..00f0572c 100644 --- a/pkg/api/core/auth/v0/auth.go +++ b/pkg/api/core/auth/v0/auth.go @@ -4,12 +4,8 @@ import ( "fmt" "github.com/homenoc/dsbd-backend/pkg/api/core" "github.com/homenoc/dsbd-backend/pkg/api/core/auth" - "github.com/homenoc/dsbd-backend/pkg/api/core/group" "github.com/homenoc/dsbd-backend/pkg/api/core/token" - "github.com/homenoc/dsbd-backend/pkg/api/core/user" - dbGroup "github.com/homenoc/dsbd-backend/pkg/api/store/group/v0" dbToken "github.com/homenoc/dsbd-backend/pkg/api/store/token/v0" - dbUser "github.com/homenoc/dsbd-backend/pkg/api/store/user/v0" "github.com/jinzhu/gorm" "log" "time" @@ -23,17 +19,14 @@ func UserAuthentication(data core.Token) auth.UserResult { if resultToken.Err != nil { return auth.UserResult{Err: fmt.Errorf("db error")} } - resultUser := dbUser.Get(user.ID, &core.User{Model: gorm.Model{ID: resultToken.Token[0].UserID}}) - if resultUser.Err != nil { - return auth.UserResult{Err: fmt.Errorf("db error")} - } - if 0 < *resultUser.User[0].ExpiredStatus { + + if 0 < *resultToken.Token[0].User.ExpiredStatus { return auth.UserResult{Err: fmt.Errorf("deleted this user")} } - renewProcess(resultToken.Token[0]) + go renewProcess(resultToken.Token[0]) - return auth.UserResult{User: resultUser.User[0], Err: nil} + return auth.UserResult{User: resultToken.Token[0].User, Err: nil} } // errorType 0: 未審査の場合でもエラーを返す 1: 未審査の場合エラーを返さない @@ -45,38 +38,33 @@ func GroupAuthentication(errorType uint, data core.Token) auth.GroupResult { if resultToken.Err != nil { return auth.GroupResult{Err: fmt.Errorf("error: no token")} } - resultUser := dbUser.Get(user.ID, &core.User{Model: gorm.Model{ID: resultToken.Token[0].UserID}}) - if resultUser.Err != nil { - return auth.GroupResult{Err: fmt.Errorf("db error")} - } - if 0 < *resultUser.User[0].ExpiredStatus { - return auth.GroupResult{Err: fmt.Errorf("user status error")} + + if 0 < *resultToken.Token[0].User.ExpiredStatus { + return auth.GroupResult{Err: fmt.Errorf("deleted this user")} } - if resultUser.User[0].GroupID == 0 { + + if resultToken.Token[0].User.GroupID == 0 { return auth.GroupResult{Err: fmt.Errorf("no group")} } - resultGroup := dbGroup.Get(group.ID, &core.Group{Model: gorm.Model{ID: resultUser.User[0].GroupID}}) - if resultGroup.Err != nil { - return auth.GroupResult{Err: fmt.Errorf("db error")} - } + // 未審査+errorType = 0の場合 - if !*resultGroup.Group[0].Pass && errorType == 0 { + if !*resultToken.Token[0].User.Group.Pass && errorType == 0 { return auth.GroupResult{Err: fmt.Errorf("error: unexamined")} } // アカウント失効時の動作 - if *resultGroup.Group[0].ExpiredStatus == 1 { + if *resultToken.Token[0].User.Group.ExpiredStatus == 1 { return auth.GroupResult{Err: fmt.Errorf("error: discontinued by Master Account")} } - if *resultGroup.Group[0].ExpiredStatus == 2 { + if *resultToken.Token[0].User.Group.ExpiredStatus == 2 { return auth.GroupResult{Err: fmt.Errorf("error: discontinuation by the steering committee")} } - if *resultGroup.Group[0].ExpiredStatus == 3 { + if *resultToken.Token[0].User.Group.ExpiredStatus == 3 { return auth.GroupResult{Err: fmt.Errorf("error: discontinuation due to failed review")} } - renewProcess(resultToken.Token[0]) + go renewProcess(resultToken.Token[0]) - return auth.GroupResult{User: resultUser.User[0], Group: resultGroup.Group[0], Err: nil} + return auth.GroupResult{User: resultToken.Token[0].User, Err: nil} } func renewProcess(t core.Token) { diff --git a/pkg/api/core/group/connection/v0/connection.go b/pkg/api/core/group/connection/v0/connection.go index 1462fa3d..e7a19e2f 100644 --- a/pkg/api/core/group/connection/v0/connection.go +++ b/pkg/api/core/group/connection/v0/connection.go @@ -63,12 +63,12 @@ func Add(c *gin.Context) { } // status check for group - if !*result.Group.Pass { + if !*result.User.Group.Pass { c.JSON(http.StatusForbidden, common.Error{Error: "error: Your group has not yet been reviewed."}) return } - if !(*result.Group.Status == 3 && *result.Group.ExpiredStatus == 0) { + if !(*result.User.Group.Status == 3 && *result.User.Group.ExpiredStatus == 0) { c.JSON(http.StatusUnauthorized, common.Error{Error: "error: failed group status"}) return } @@ -114,7 +114,7 @@ func Add(c *gin.Context) { } // GroupIDが一致しない場合はエラーを返す - if resultService.Service[0].GroupID != result.Group.ID { + if resultService.Service[0].GroupID != result.User.Group.ID { c.JSON(http.StatusBadRequest, common.Error{Error: "error: GroupID does not match."}) return } @@ -159,7 +159,7 @@ func Add(c *gin.Context) { attachment := slack.Attachment{} attachment.AddField(slack.Field{Title: "Title", Value: "接続情報登録"}). AddField(slack.Field{Title: "申請者", Value: strconv.Itoa(int(result.User.ID)) + ":" + result.User.Name}). - AddField(slack.Field{Title: "GroupID", Value: strconv.Itoa(int(result.Group.ID)) + ":" + result.Group.Org}). + AddField(slack.Field{Title: "GroupID", Value: strconv.Itoa(int(result.User.Group.ID)) + ":" + result.User.Group.Org}). AddField(slack.Field{Title: "サービスコード", Value: resultService.Service[0].ServiceTemplate.Type + fmt.Sprintf("%03d", resultService.Service[0].ServiceNumber)}). AddField(slack.Field{Title: "接続コード(新規発番)", Value: resultConnectionTemplate.Connections[0].Type + @@ -168,7 +168,7 @@ func Add(c *gin.Context) { notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true}) if err = dbGroup.Update(group.UpdateStatus, core.Group{ - Model: gorm.Model{ID: result.Group.ID}, + Model: gorm.Model{ID: result.User.Group.ID}, Status: &[]uint{4}[0], }); err != nil { c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) @@ -186,7 +186,7 @@ func Add(c *gin.Context) { attachment = slack.Attachment{} attachment.AddField(slack.Field{Title: "Title", Value: "ステータス変更"}). AddField(slack.Field{Title: "申請者", Value: "System"}). - AddField(slack.Field{Title: "GroupID", Value: strconv.Itoa(int(result.Group.ID)) + ":" + result.Group.Org}). + AddField(slack.Field{Title: "GroupID", Value: strconv.Itoa(int(result.User.Group.ID)) + ":" + result.User.Group.Org}). AddField(slack.Field{Title: "現在ステータス情報", Value: "開通作業中"}). AddField(slack.Field{Title: "ステータス履歴", Value: "3[接続情報記入段階(User)] =>4[開通作業中] "}) notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true}) diff --git a/pkg/api/core/group/info/v0/info.go b/pkg/api/core/group/info/v0/info.go index 4d9b71c7..faae8c83 100644 --- a/pkg/api/core/group/info/v0/info.go +++ b/pkg/api/core/group/info/v0/info.go @@ -23,7 +23,7 @@ func Get(c *gin.Context) { return } - resultService := dbService.Get(service.Open, &core.Service{GroupID: result.Group.ID}) + resultService := dbService.Get(service.Open, &core.Service{GroupID: result.User.GroupID}) if resultService.Err != nil { c.JSON(http.StatusInternalServerError, common.Error{Error: resultService.Err.Error()}) return diff --git a/pkg/api/core/group/service/jpnicAdmin/v0/jpnicAdmin.go b/pkg/api/core/group/service/jpnicAdmin/v0/jpnicAdmin.go index 4762a5d0..fd5e5583 100644 --- a/pkg/api/core/group/service/jpnicAdmin/v0/jpnicAdmin.go +++ b/pkg/api/core/group/service/jpnicAdmin/v0/jpnicAdmin.go @@ -46,7 +46,7 @@ func Add(c *gin.Context) { return } - networkResult := dbService.Get(service.GID, &core.Service{GroupID: result.Group.ID}) + networkResult := dbService.Get(service.GID, &core.Service{GroupID: result.User.GroupID}) if networkResult.Err != nil { c.JSON(http.StatusInternalServerError, common.Error{Error: networkResult.Err.Error()}) return diff --git a/pkg/api/core/group/service/jpnicTech/v0/jpnicTech.go b/pkg/api/core/group/service/jpnicTech/v0/jpnicTech.go index 0e07aaa0..1cca357a 100644 --- a/pkg/api/core/group/service/jpnicTech/v0/jpnicTech.go +++ b/pkg/api/core/group/service/jpnicTech/v0/jpnicTech.go @@ -45,7 +45,7 @@ func Add(c *gin.Context) { return } - networkResult := dbService.Get(service.GID, &core.Service{GroupID: result.Group.ID}) + networkResult := dbService.Get(service.GID, &core.Service{GroupID: result.User.GroupID}) if networkResult.Err != nil { c.JSON(http.StatusInternalServerError, common.Error{Error: networkResult.Err.Error()}) return diff --git a/pkg/api/core/group/service/v0/service.go b/pkg/api/core/group/service/v0/service.go index e3a460f4..38341621 100644 --- a/pkg/api/core/group/service/v0/service.go +++ b/pkg/api/core/group/service/v0/service.go @@ -52,7 +52,7 @@ func Add(c *gin.Context) { } // status check for group - if !(*result.Group.Status == 1 && *result.Group.ExpiredStatus == 0 && *result.Group.Pass) { + if !(*result.User.Group.Status == 1 && *result.User.Group.ExpiredStatus == 0 && *result.User.Group.Pass) { c.JSON(http.StatusUnauthorized, common.Error{Error: "error: failed group status"}) return } @@ -118,7 +118,7 @@ func Add(c *gin.Context) { return } - resultNetwork := dbService.Get(service.SearchNewNumber, &core.Service{GroupID: result.Group.ID}) + resultNetwork := dbService.Get(service.SearchNewNumber, &core.Service{GroupID: result.User.Group.ID}) if resultNetwork.Err != nil { c.JSON(http.StatusBadRequest, common.Error{Error: resultNetwork.Err.Error()}) return @@ -137,7 +137,7 @@ func Add(c *gin.Context) { // db create for network net, err := dbService.Create(&core.Service{ - GroupID: result.Group.ID, + GroupID: result.User.Group.ID, ServiceTemplateID: &input.ServiceTemplateID, ServiceComment: input.ServiceComment, ServiceNumber: number, @@ -169,14 +169,14 @@ func Add(c *gin.Context) { attachment := slack.Attachment{} attachment.AddField(slack.Field{Title: "Title", Value: "ネットワーク情報登録"}). AddField(slack.Field{Title: "申請者", Value: strconv.Itoa(int(result.User.ID)) + ":" + result.User.Name}). - AddField(slack.Field{Title: "GroupID", Value: strconv.Itoa(int(result.Group.ID)) + ":" + result.Group.Org}). + AddField(slack.Field{Title: "GroupID", Value: strconv.Itoa(int(result.User.Group.ID)) + ":" + result.User.Group.Org}). AddField(slack.Field{Title: "サービスコード(新規発番)", Value: resultServiceTemplate.Services[0].Type + fmt.Sprintf("%03d", number)}). AddField(slack.Field{Title: "サービスコード(補足情報)", Value: input.ServiceComment}) notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true}) // ---------ここまで処理が通っている場合、DBへの書き込みにすべて成功している // GroupのStatusをAfterStatusにする - if err = dbGroup.Update(group.UpdateStatus, core.Group{Model: gorm.Model{ID: result.Group.ID}, + if err = dbGroup.Update(group.UpdateStatus, core.Group{Model: gorm.Model{ID: result.User.Group.ID}, Status: &[]uint{2}[0]}); err != nil { c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) return @@ -185,7 +185,7 @@ func Add(c *gin.Context) { attachment = slack.Attachment{} attachment.AddField(slack.Field{Title: "Title", Value: "ステータス変更"}). AddField(slack.Field{Title: "申請者", Value: "System"}). - AddField(slack.Field{Title: "GroupID", Value: strconv.Itoa(int(result.Group.ID)) + ":" + result.Group.Org}). + AddField(slack.Field{Title: "GroupID", Value: strconv.Itoa(int(result.User.Group.ID)) + ":" + result.User.Group.Org}). AddField(slack.Field{Title: "現在ステータス情報", Value: "審査中"}). AddField(slack.Field{Title: "ステータス履歴", Value: "1[ネットワーク情報記入段階(User)] =>2[審査中] "}) notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true}) @@ -227,7 +227,7 @@ func Update(c *gin.Context) { c.JSON(http.StatusInternalServerError, common.Error{Error: "failed Service ID"}) return } - if resultNetwork.Service[0].GroupID != result.Group.ID { + if resultNetwork.Service[0].GroupID != result.User.Group.ID { c.JSON(http.StatusInternalServerError, common.Error{Error: "Authentication failure"}) return } @@ -256,7 +256,7 @@ func GetAddAllow(c *gin.Context) { return } - if resultService := dbService.Get(service.GIDAndAddAllow, &core.Service{GroupID: result.Group.ID}); resultService.Err != nil { + if resultService := dbService.Get(service.GIDAndAddAllow, &core.Service{GroupID: result.User.Group.ID}); resultService.Err != nil { log.Println(resultService.Err) c.JSON(http.StatusInternalServerError, common.Error{Error: resultService.Err.Error()}) } else { diff --git a/pkg/api/core/group/v0/group.go b/pkg/api/core/group/v0/group.go index a2cb8024..6696342e 100644 --- a/pkg/api/core/group/v0/group.go +++ b/pkg/api/core/group/v0/group.go @@ -125,21 +125,21 @@ func Update(c *gin.Context) { c.JSON(http.StatusUnauthorized, common.Error{Error: "error: failed user level"}) return } - if *authResult.Group.Lock { + if *authResult.User.Group.Lock { c.JSON(http.StatusUnauthorized, common.Error{Error: "error: This group is locked"}) return } - data := authResult.Group + data := authResult.User.Group if data.Org != input.Org { data.Org = input.Org } - if err = dbGroup.Update(group.UpdateInfo, data); err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: authResult.Err.Error()}) - return - } + //if err = dbGroup.Update(group.UpdateInfo, data); err != nil { + // c.JSON(http.StatusInternalServerError, common.Error{Error: authResult.Err.Error()}) + // return + //} c.JSON(http.StatusOK, common.Result{}) } @@ -154,9 +154,15 @@ func Get(c *gin.Context) { return } + resultUser := dbUser.Get(user.ID, &core.User{Model: gorm.Model{ID: result.User.ID}}) + if resultUser.Err != nil { + c.JSON(http.StatusUnauthorized, common.Error{Error: resultUser.Err.Error()}) + return + } + var responseUser []user.User if result.User.Level == 1 || result.User.Level == 2 { - for _, tmpUser := range result.Group.Users { + for _, tmpUser := range resultUser.User { responseUser = append(responseUser, user.User{ ID: tmpUser.ID, Name: tmpUser.Name, @@ -181,20 +187,20 @@ func Get(c *gin.Context) { } } - log.Println(result.Group.Users) + log.Println(result.User) c.JSON(http.StatusOK, group.Result{Group: group.Group{ - ID: result.Group.ID, - Agree: result.Group.Agree, - Question: result.Group.Question, - Org: result.Group.Org, - Status: *result.Group.Status, - Contract: result.Group.Contract, - Student: result.Group.Student, - Open: result.Group.Open, - Pass: result.Group.Pass, - Lock: result.Group.Lock, - ExpiredStatus: *result.Group.ExpiredStatus, + ID: result.User.Group.ID, + Agree: result.User.Group.Agree, + Question: result.User.Group.Question, + Org: result.User.Group.Org, + Status: *result.User.Group.Status, + Contract: result.User.Group.Contract, + Student: result.User.Group.Student, + Open: result.User.Group.Open, + Pass: result.User.Group.Pass, + Lock: result.User.Group.Lock, + ExpiredStatus: *result.User.Group.ExpiredStatus, //User: users, }}) } @@ -214,10 +220,16 @@ func GetAll(c *gin.Context) { return } + resultGroup := dbGroup.Get(group.ID, &core.Group{Model: gorm.Model{ID: result.User.GroupID}}) + if resultGroup.Err != nil { + c.JSON(http.StatusInternalServerError, common.Error{Error: result.Err.Error()}) + return + } + var users []user.User var services []service.Service - for _, tmpUser := range result.Group.Users { + for _, tmpUser := range resultGroup.Group[0].Users { users = append(users, user.User{ ID: tmpUser.ID, Name: tmpUser.Name, @@ -229,7 +241,7 @@ func GetAll(c *gin.Context) { }) } - for _, tmpService := range result.Group.Services { + for _, tmpService := range resultGroup.Group[0].Services { var tmpConnections *[]connection.Connection = nil var tmpJPNICAdmin *service.JPNIC = nil var tmpJPNICTech *[]service.JPNIC = nil @@ -338,17 +350,17 @@ func GetAll(c *gin.Context) { } c.JSON(http.StatusOK, group.Result{Group: group.Group{ - ID: result.Group.ID, - Agree: result.Group.Agree, - Question: result.Group.Question, - Org: result.Group.Org, - Status: *result.Group.Status, - Contract: result.Group.Contract, - Student: result.Group.Student, - Open: result.Group.Open, - Pass: result.Group.Pass, - Lock: result.Group.Lock, - ExpiredStatus: *result.Group.ExpiredStatus, + ID: resultGroup.Group[0].ID, + Agree: resultGroup.Group[0].Agree, + Question: resultGroup.Group[0].Question, + Org: resultGroup.Group[0].Org, + Status: *resultGroup.Group[0].Status, + Contract: resultGroup.Group[0].Contract, + Student: resultGroup.Group[0].Student, + Open: resultGroup.Group[0].Open, + Pass: resultGroup.Group[0].Pass, + Lock: resultGroup.Group[0].Lock, + ExpiredStatus: *resultGroup.Group[0].ExpiredStatus, User: users, Service: &services, }}) diff --git a/pkg/api/core/interface.go b/pkg/api/core/interface.go index e4653615..c44608cc 100644 --- a/pkg/api/core/interface.go +++ b/pkg/api/core/interface.go @@ -9,6 +9,7 @@ type User struct { gorm.Model Tokens []*Token `json:"tokens"` Notice []*Notice `json:"notice"` + Group *Group `json:"group"` GroupID uint `json:"group_id"` Name string `json:"name"` NameEn string `json:"name_en"` @@ -269,6 +270,7 @@ type Token struct { gorm.Model ExpiredAt time.Time `json:"expired_at"` UserID uint `json:"user_id"` + User User `json:"user"` Status uint `json:"status"` //0: initToken(30m) 1: 30m 2:6h 3: 12h 10: 30d 11:180d Admin *bool `json:"admin"` UserToken string `json:"user_token"` diff --git a/pkg/api/core/support/chat/v0/chat.go b/pkg/api/core/support/chat/v0/chat.go index b06ff135..652e94c6 100644 --- a/pkg/api/core/support/chat/v0/chat.go +++ b/pkg/api/core/support/chat/v0/chat.go @@ -63,7 +63,7 @@ func Add(c *gin.Context) { return } // GroupIDが一致しない場合はここでエラーを返す - if resultTicket.Tickets[0].GroupID != result.Group.ID { + if resultTicket.Tickets[0].GroupID != result.User.GroupID { c.JSON(http.StatusInternalServerError, common.Error{Error: "Auth Error: group id failed..."}) return } diff --git a/pkg/api/core/support/ticket/v0/ticket.go b/pkg/api/core/support/ticket/v0/ticket.go index bffea323..1eb8ee36 100644 --- a/pkg/api/core/support/ticket/v0/ticket.go +++ b/pkg/api/core/support/ticket/v0/ticket.go @@ -51,7 +51,7 @@ func Create(c *gin.Context) { // Tickets DBに登録 ticketResult, err := dbTicket.Create(&core.Ticket{ - GroupID: result.Group.ID, + GroupID: result.User.GroupID, UserID: result.User.ID, Solved: &[]bool{false}[0], Title: input.Title, @@ -77,7 +77,7 @@ func Create(c *gin.Context) { attachment := slack.Attachment{} attachment.AddField(slack.Field{Title: "Title", Value: "新規チケット作成"}). AddField(slack.Field{Title: "発行者", Value: strconv.Itoa(int(result.User.ID))}). - AddField(slack.Field{Title: "Group", Value: strconv.Itoa(int(result.Group.ID)) + "-" + result.Group.Org}). + AddField(slack.Field{Title: "Group", Value: strconv.Itoa(int(result.User.GroupID)) + "-" + result.User.Group.Org}). AddField(slack.Field{Title: "Title", Value: input.Title}). AddField(slack.Field{Title: "Message", Value: input.Data}) notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true}) @@ -110,7 +110,7 @@ func Get(c *gin.Context) { } // GroupIDが一致しない場合はここでエラーを返す - if resultTicket.Tickets[0].GroupID != result.Group.ID { + if resultTicket.Tickets[0].GroupID != result.User.GroupID { c.JSON(http.StatusInternalServerError, common.Error{Error: "Auth Error: group id failed..."}) return } @@ -153,7 +153,7 @@ func GetAll(c *gin.Context) { } // Tickets DBからGroup IDのTicketデータを抽出 - resultTicket := dbTicket.Get(ticket.GID, &core.Ticket{GroupID: result.Group.ID}) + resultTicket := dbTicket.Get(ticket.GID, &core.Ticket{GroupID: result.User.GroupID}) if resultTicket.Err != nil { c.JSON(http.StatusInternalServerError, common.Error{Error: resultTicket.Err.Error()}) return @@ -234,7 +234,7 @@ func GetWebSocket(c *gin.Context) { Admin: false, UserID: result.User.ID, UserName: result.User.Name, - GroupID: result.Group.ID, + GroupID: result.User.GroupID, Socket: conn, }] = true @@ -249,7 +249,7 @@ func GetWebSocket(c *gin.Context) { Admin: false, UserID: result.User.ID, UserName: result.User.Name, - GroupID: result.Group.ID, + GroupID: result.User.GroupID, Socket: conn, }) break @@ -275,7 +275,7 @@ func GetWebSocket(c *gin.Context) { } else { msg.UserID = result.User.ID - msg.GroupID = resultGroup.Group.ID + msg.GroupID = resultGroup.User.GroupID msg.Admin = false msg.UserName = result.User.Name // Token関連の初期化 @@ -287,7 +287,7 @@ func GetWebSocket(c *gin.Context) { CreatedAt: msg.CreatedAt, UserID: result.User.ID, UserName: result.User.Name, - GroupID: resultGroup.Group.ID, + GroupID: resultGroup.User.GroupID, Admin: msg.Admin, Message: msg.Message, }) @@ -296,7 +296,7 @@ func GetWebSocket(c *gin.Context) { attachment := slack.Attachment{} attachment.AddField(slack.Field{Title: "Title", Value: "Support(新規メッセージ)"}). AddField(slack.Field{Title: "発行者", Value: strconv.Itoa(int(result.User.ID)) + "-" + result.User.Name}). - AddField(slack.Field{Title: "Group", Value: strconv.Itoa(int(result.Group.ID)) + "-" + result.Group.Org}). + AddField(slack.Field{Title: "Group", Value: strconv.Itoa(int(result.User.GroupID)) + "-" + result.User.Group.Org}). AddField(slack.Field{Title: "Title", Value: ticketResult.Tickets[0].Title}). AddField(slack.Field{Title: "Message", Value: msg.Message}) notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true}) diff --git a/pkg/api/core/user/v0/user.go b/pkg/api/core/user/v0/user.go index db698224..ef74ff55 100644 --- a/pkg/api/core/user/v0/user.go +++ b/pkg/api/core/user/v0/user.go @@ -80,7 +80,7 @@ func Add(c *gin.Context) { pass = gen.GenerateUUID() data = core.User{ - GroupID: authResult.Group.ID, + GroupID: authResult.User.Group.ID, Name: input.Name, NameEn: input.NameEn, Email: input.Email, @@ -119,7 +119,7 @@ func Add(c *gin.Context) { } else { attachment.AddField(slack.Field{Title: "Title", Value: "グループ内ユーザ登録"}). AddField(slack.Field{Title: "メールアドレス", Value: input.Email}). - AddField(slack.Field{Title: "GroupID", Value: strconv.Itoa(int(data.GroupID)) + ":" + authResult.Group.Org}). + AddField(slack.Field{Title: "GroupID", Value: strconv.Itoa(int(data.GroupID)) + ":" + authResult.User.Group.Org}). AddField(slack.Field{Title: "Name", Value: input.Name}). AddField(slack.Field{Title: "Name(English)", Value: input.NameEn}) } diff --git a/pkg/api/store/token/v0/token.go b/pkg/api/store/token/v0/token.go index 3b51786f..6afca326 100644 --- a/pkg/api/store/token/v0/token.go +++ b/pkg/api/store/token/v0/token.go @@ -89,7 +89,10 @@ func Get(base int, input *core.Token) token.ResultDatabase { input.UserToken, false, time.Now()).Find(&tokenStruct).Error } else if base == token.UserTokenAndAccessToken { err = db.Where("user_token = ? AND access_token = ? AND admin = ? AND expired_at > ?", - input.UserToken, input.AccessToken, false, time.Now()).Find(&tokenStruct).Error + input.UserToken, input.AccessToken, false, time.Now()). + Preload("User"). + Preload("User.Group"). + Find(&tokenStruct).Error } else if base == token.AdminToken { err = db.Where("access_token = ? AND admin = ? AND expired_at > ?", input.AccessToken, true, time.Now()).Find(&tokenStruct).Error