From 98a7266ee3837a832e2ce8dadaeabfaebce12a9f Mon Sep 17 00:00:00 2001 From: yoneyan Date: Sat, 30 Oct 2021 04:50:01 +0900 Subject: [PATCH] [fix] #48 --- .../core/group/service/jpnicAdmin/v0/admin.go | 114 ------------ .../core/group/service/jpnicAdmin/v0/check.go | 29 --- .../group/service/jpnicAdmin/v0/jpnicAdmin.go | 114 ------------ .../core/group/service/jpnicAdmin/v0/slack.go | 129 ------------- .../core/group/service/jpnicTech/v0/admin.go | 114 ------------ .../core/group/service/jpnicTech/v0/check.go | 29 --- .../group/service/jpnicTech/v0/jpnicTech.go | 113 ------------ .../core/group/service/jpnicTech/v0/slack.go | 172 ------------------ pkg/api/core/token/v0/admin.go | 2 +- 9 files changed, 1 insertion(+), 815 deletions(-) delete mode 100644 pkg/api/core/group/service/jpnicAdmin/v0/admin.go delete mode 100644 pkg/api/core/group/service/jpnicAdmin/v0/check.go delete mode 100644 pkg/api/core/group/service/jpnicAdmin/v0/jpnicAdmin.go delete mode 100644 pkg/api/core/group/service/jpnicAdmin/v0/slack.go delete mode 100644 pkg/api/core/group/service/jpnicTech/v0/admin.go delete mode 100644 pkg/api/core/group/service/jpnicTech/v0/check.go delete mode 100644 pkg/api/core/group/service/jpnicTech/v0/jpnicTech.go delete mode 100644 pkg/api/core/group/service/jpnicTech/v0/slack.go diff --git a/pkg/api/core/group/service/jpnicAdmin/v0/admin.go b/pkg/api/core/group/service/jpnicAdmin/v0/admin.go deleted file mode 100644 index 03fc0031..00000000 --- a/pkg/api/core/group/service/jpnicAdmin/v0/admin.go +++ /dev/null @@ -1,114 +0,0 @@ -package v0 - -import ( - "github.com/gin-gonic/gin" - "github.com/homenoc/dsbd-backend/pkg/api/core" - auth "github.com/homenoc/dsbd-backend/pkg/api/core/auth/v0" - "github.com/homenoc/dsbd-backend/pkg/api/core/common" - "github.com/homenoc/dsbd-backend/pkg/api/core/group/service/jpnicAdmin" - dbJPNICAdmin "github.com/homenoc/dsbd-backend/pkg/api/store/group/service/jpnicAdmin/v0" - "gorm.io/gorm" - "log" - "net/http" - "strconv" -) - -func AddByAdmin(c *gin.Context) { - var input core.JPNICAdmin - - resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN")) - if resultAdmin.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()}) - return - } - - err := c.BindJSON(&input) - if err != nil { - log.Println(err) - c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) - return - } - - if _, err = dbJPNICAdmin.Create(&input); err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - return - } - c.JSON(http.StatusOK, jpnicAdmin.Result{}) -} - -func DeleteByAdmin(c *gin.Context) { - resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN")) - if resultAdmin.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()}) - return - } - - id, err := strconv.Atoi(c.Param("id")) - if err != nil { - c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) - return - } - - if err = dbJPNICAdmin.Delete(&core.JPNICAdmin{Model: gorm.Model{ID: uint(id)}}); err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - return - } - c.JSON(http.StatusOK, jpnicAdmin.Result{}) -} - -func UpdateByAdmin(c *gin.Context) { - var input core.JPNICAdmin - - resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN")) - if resultAdmin.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()}) - return - } - - err := c.BindJSON(&input) - if err != nil { - log.Println(err) - c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) - return - } - - if err := dbJPNICAdmin.Update(jpnicAdmin.UpdateAll, input); err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - return - } - c.JSON(http.StatusOK, jpnicAdmin.Result{}) -} - -func GetByAdmin(c *gin.Context) { - resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN")) - if resultAdmin.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()}) - return - } - id, err := strconv.Atoi(c.Param("id")) - if err != nil { - c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) - return - } - - result := dbJPNICAdmin.Get(jpnicAdmin.ID, &core.JPNICAdmin{Model: gorm.Model{ID: uint(id)}}) - if result.Err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: result.Err.Error()}) - return - } - c.JSON(http.StatusOK, jpnicAdmin.Result{Admins: result.Admins}) -} - -func GetAllByAdmin(c *gin.Context) { - resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN")) - if resultAdmin.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()}) - return - } - - if result := dbJPNICAdmin.GetAll(); result.Err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: result.Err.Error()}) - } else { - c.JSON(http.StatusOK, jpnicAdmin.Result{Admins: result.Admins}) - } -} diff --git a/pkg/api/core/group/service/jpnicAdmin/v0/check.go b/pkg/api/core/group/service/jpnicAdmin/v0/check.go deleted file mode 100644 index 1143df99..00000000 --- a/pkg/api/core/group/service/jpnicAdmin/v0/check.go +++ /dev/null @@ -1,29 +0,0 @@ -package v0 - -import ( - "fmt" - "github.com/homenoc/dsbd-backend/pkg/api/core" -) - -func check(input core.JPNICAdmin) error { - // check - if input.Org == "" { - return fmt.Errorf("failed data: org") - } - if input.OrgEn == "" { - return fmt.Errorf("failed data: org(english)") - } - if input.PostCode == "" { - return fmt.Errorf("failed data: postcode") - } - if input.Address == "" { - return fmt.Errorf("failed data: address") - } - if input.AddressEn == "" { - return fmt.Errorf("failed data: address(english)") - } - if input.Tel == "" { - return fmt.Errorf("failed data: tel") - } - return nil -} diff --git a/pkg/api/core/group/service/jpnicAdmin/v0/jpnicAdmin.go b/pkg/api/core/group/service/jpnicAdmin/v0/jpnicAdmin.go deleted file mode 100644 index 3e129447..00000000 --- a/pkg/api/core/group/service/jpnicAdmin/v0/jpnicAdmin.go +++ /dev/null @@ -1,114 +0,0 @@ -package v0 - -import ( - "fmt" - "github.com/gin-gonic/gin" - "github.com/homenoc/dsbd-backend/pkg/api/core" - auth "github.com/homenoc/dsbd-backend/pkg/api/core/auth/v0" - "github.com/homenoc/dsbd-backend/pkg/api/core/common" - "github.com/homenoc/dsbd-backend/pkg/api/core/group/service" - "github.com/homenoc/dsbd-backend/pkg/api/core/group/service/jpnicAdmin" - "github.com/homenoc/dsbd-backend/pkg/api/core/group/service/jpnicTech" - dbJPNICAdmin "github.com/homenoc/dsbd-backend/pkg/api/store/group/service/jpnicAdmin/v0" - dbService "github.com/homenoc/dsbd-backend/pkg/api/store/group/service/v0" - "gorm.io/gorm" - "log" - "net/http" - "strconv" -) - -func Add(c *gin.Context) { - var input core.JPNICAdmin - userToken := c.Request.Header.Get("USER_TOKEN") - accessToken := c.Request.Header.Get("ACCESS_TOKEN") - - err := c.BindJSON(&input) - if err != nil { - log.Println(err) - c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) - return - } - - result := auth.GroupAuthorization(0, core.Token{UserToken: userToken, AccessToken: accessToken}) - if result.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: result.Err.Error()}) - return - } - - if err = check(input); err != nil { - c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) - return - } - - // check authority - if result.User.Level > 2 { - c.JSON(http.StatusUnauthorized, common.Error{Error: "You don't have authority this operation"}) - return - } - - 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 - } - - _, err = dbJPNICAdmin.Create(&core.JPNICAdmin{ - Org: input.Org, - OrgEn: input.OrgEn, - PostCode: input.PostCode, - Address: input.Address, - AddressEn: input.AddressEn, - Dept: input.Dept, - DeptEn: input.DeptEn, - Tel: input.Tel, - Fax: input.Fax, - Country: input.Country, - Lock: &[]bool{true}[0], - }) - if err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - return - } - - c.JSON(http.StatusOK, jpnicAdmin.Result{}) -} - -func Delete(c *gin.Context) { - userToken := c.Request.Header.Get("USER_TOKEN") - accessToken := c.Request.Header.Get("ACCESS_TOKEN") - - id, err := strconv.Atoi(c.Param("id")) - if err != nil { - c.JSON(http.StatusBadRequest, common.Error{Error: fmt.Sprintf("id error")}) - return - } - - if id <= 0 { - c.JSON(http.StatusBadRequest, common.Error{Error: "wrong id"}) - return - } - - result := auth.GroupAuthorization(0, core.Token{UserToken: userToken, AccessToken: accessToken}) - if result.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: result.Err.Error()}) - return - } - - // check authority - if result.User.Level > 2 { - c.JSON(http.StatusUnauthorized, common.Error{Error: "You don't have authority this operation"}) - return - } - - resultTech := dbJPNICAdmin.Get(jpnicTech.ID, &core.JPNICAdmin{Model: gorm.Model{ID: uint(id)}}) - if resultTech.Err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: resultTech.Err.Error()}) - return - } - - if err = dbJPNICAdmin.Delete(&core.JPNICAdmin{Model: gorm.Model{ID: uint(id)}}); err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - } else { - c.JSON(http.StatusOK, jpnicAdmin.Result{}) - } -} diff --git a/pkg/api/core/group/service/jpnicAdmin/v0/slack.go b/pkg/api/core/group/service/jpnicAdmin/v0/slack.go deleted file mode 100644 index bd549550..00000000 --- a/pkg/api/core/group/service/jpnicAdmin/v0/slack.go +++ /dev/null @@ -1,129 +0,0 @@ -package v0 - -import ( - "github.com/ashwanthkumar/slack-go-webhook" - "github.com/homenoc/dsbd-backend/pkg/api/core" - "github.com/homenoc/dsbd-backend/pkg/api/core/group" - "github.com/homenoc/dsbd-backend/pkg/api/core/tool/notification" - "strconv" -) - -func noticeSlackAddByAdmin(before, after core.Group) { - // 審査ステータスのSlack通知 - attachment := slack.Attachment{} - - attachment.Text = &[]string{"Group情報の更新"}[0] - attachment.AddField(slack.Field{Title: "申請者", Value: "管理者"}). - AddField(slack.Field{Title: "Group", Value: strconv.Itoa(int(before.ID)) + ":" + before.Org}). - AddField(slack.Field{Title: "更新状況", Value: changeTextByAdmin(before, after)}) - notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true}) -} - -func noticeSlackUpdateByAdmin(before, after core.Group) { - // 審査ステータスのSlack通知 - attachment := slack.Attachment{} - - attachment.Text = &[]string{"Group情報の更新"}[0] - attachment.AddField(slack.Field{Title: "申請者", Value: "管理者"}). - AddField(slack.Field{Title: "Group", Value: strconv.Itoa(int(before.ID)) + ":" + before.Org}). - AddField(slack.Field{Title: "更新状況", Value: changeTextByAdmin(before, after)}) - notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true}) -} - -func addText(before core.Group, after group.Input) string { - data := "" - - if after.Org != "" && after.Org != before.Org { - data += "Org: " + before.Org + "=>" + after.Org + "\n" - } - - if after.OrgEn != "" && after.OrgEn != before.OrgEn { - data += "Org(En): " + before.OrgEn + "=>" + after.OrgEn + "\n" - } - - if after.PostCode != "" && after.PostCode != before.PostCode { - data += "PostCode: " + before.PostCode + "=>" + after.PostCode + "\n" - } - - if after.Address != "" && after.Address != before.Address { - data += "Address: " + before.Address + "=>" + after.Address + "\n" - } - - if after.AddressEn != "" && after.AddressEn != before.AddressEn { - data += "Address(En): " + before.AddressEn + "=>" + after.AddressEn + "\n" - } - - if after.Tel != "" && after.Tel != before.Tel { - data += "Tel: " + before.Tel + "=>" + after.Tel + "\n" - } - - if after.Country != "" && after.Country != before.Country { - data += "Country: " + before.Country + "=>" + after.Country + "\n" - } - - return data -} - -func changeTextByAdmin(before, after core.Group) string { - data := "" - - if after.Org != "" && after.Org != before.Org { - data += "Org: " + before.Org + "=>" + after.Org + "\n" - } - - if after.OrgEn != "" && after.OrgEn != before.OrgEn { - data += "Org(En): " + before.OrgEn + "=>" + after.OrgEn + "\n" - } - - if after.PostCode != "" && after.PostCode != before.PostCode { - data += "PostCode: " + before.PostCode + "=>" + after.PostCode + "\n" - } - - if after.Address != "" && after.Address != before.Address { - data += "Address: " + before.Address + "=>" + after.Address + "\n" - } - - if after.AddressEn != "" && after.AddressEn != before.AddressEn { - data += "Address(En): " + before.AddressEn + "=>" + after.AddressEn + "\n" - } - - if after.Tel != "" && after.Tel != before.Tel { - data += "Tel: " + before.Tel + "=>" + after.Tel + "\n" - } - - if after.Country != "" && after.Country != before.Country { - data += "Country: " + before.Country + "=>" + after.Country + "\n" - } - - return data -} - -func expiredStatusText(status uint) string { - if status == 0 { - return "0" - } else if status == 1 { - return "ユーザより廃止" - } else if status == 2 { - return "運営委員より廃止" - } else if status == 3 { - return "審査落ち" - } else { - return "status不明" - } -} - -func statusText(status uint) string { - if status == 0 { - return "0" - } else if status == 1 { - return "ネットワーク情報 記入段階" - } else if status == 2 { - return "審査中" - } else if status == 3 { - return "接続情報 記入段階" - } else if status == 4 { - return "開通作業中" - } else { - return "status不明" - } -} diff --git a/pkg/api/core/group/service/jpnicTech/v0/admin.go b/pkg/api/core/group/service/jpnicTech/v0/admin.go deleted file mode 100644 index d0e18a6a..00000000 --- a/pkg/api/core/group/service/jpnicTech/v0/admin.go +++ /dev/null @@ -1,114 +0,0 @@ -package v0 - -import ( - "github.com/gin-gonic/gin" - "github.com/homenoc/dsbd-backend/pkg/api/core" - auth "github.com/homenoc/dsbd-backend/pkg/api/core/auth/v0" - "github.com/homenoc/dsbd-backend/pkg/api/core/common" - "github.com/homenoc/dsbd-backend/pkg/api/core/group/service/jpnicTech" - dbJPNICTech "github.com/homenoc/dsbd-backend/pkg/api/store/group/service/jpnicTech/v0" - "gorm.io/gorm" - "log" - "net/http" - "strconv" -) - -func AddByAdmin(c *gin.Context) { - var input core.JPNICTech - - resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN")) - if resultAdmin.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()}) - return - } - - err := c.BindJSON(&input) - if err != nil { - log.Println(err) - c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) - return - } - - if _, err = dbJPNICTech.Create(&input); err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - return - } - c.JSON(http.StatusOK, jpnicTech.Result{}) -} - -func DeleteByAdmin(c *gin.Context) { - resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN")) - if resultAdmin.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()}) - return - } - - id, err := strconv.Atoi(c.Param("id")) - if err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - return - } - - if err = dbJPNICTech.Delete(&core.JPNICTech{Model: gorm.Model{ID: uint(id)}}); err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - return - } - c.JSON(http.StatusOK, jpnicTech.Result{}) -} - -func UpdateByAdmin(c *gin.Context) { - var input core.JPNICTech - - resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN")) - if resultAdmin.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()}) - return - } - - err := c.BindJSON(&input) - if err != nil { - log.Println(err) - c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) - return - } - - if err = dbJPNICTech.Update(jpnicTech.UpdateAll, input); err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - return - } - c.JSON(http.StatusOK, jpnicTech.Result{}) -} - -func GetByAdmin(c *gin.Context) { - resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN")) - if resultAdmin.Err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: resultAdmin.Err.Error()}) - return - } - id, err := strconv.Atoi(c.Param("id")) - if err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - return - } - - result := dbJPNICTech.Get(jpnicTech.ID, &core.JPNICTech{Model: gorm.Model{ID: uint(id)}}) - if result.Err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: result.Err.Error()}) - return - } - c.JSON(http.StatusOK, jpnicTech.Result{Tech: result.Tech}) -} - -func GetAllByAdmin(c *gin.Context) { - resultAdmin := auth.AdminAuthorization(c.Request.Header.Get("ACCESS_TOKEN")) - if resultAdmin.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()}) - return - } - - if result := dbJPNICTech.GetAll(); result.Err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: result.Err.Error()}) - } else { - c.JSON(http.StatusOK, jpnicTech.Result{Tech: result.Tech}) - } -} diff --git a/pkg/api/core/group/service/jpnicTech/v0/check.go b/pkg/api/core/group/service/jpnicTech/v0/check.go deleted file mode 100644 index 4aa3752e..00000000 --- a/pkg/api/core/group/service/jpnicTech/v0/check.go +++ /dev/null @@ -1,29 +0,0 @@ -package v0 - -import ( - "fmt" - "github.com/homenoc/dsbd-backend/pkg/api/core" -) - -func check(input core.JPNICTech) error { - // check - if input.Org == "" { - return fmt.Errorf("failed data: org") - } - if input.OrgEn == "" { - return fmt.Errorf("failed data: org(english)") - } - if input.PostCode == "" { - return fmt.Errorf("failed data: postcode") - } - if input.Address == "" { - return fmt.Errorf("failed data: address") - } - if input.AddressEn == "" { - return fmt.Errorf("failed data: address(english)") - } - if input.Tel == "" { - return fmt.Errorf("failed data: tel") - } - return nil -} diff --git a/pkg/api/core/group/service/jpnicTech/v0/jpnicTech.go b/pkg/api/core/group/service/jpnicTech/v0/jpnicTech.go deleted file mode 100644 index 5a1493e5..00000000 --- a/pkg/api/core/group/service/jpnicTech/v0/jpnicTech.go +++ /dev/null @@ -1,113 +0,0 @@ -package v0 - -import ( - "fmt" - "github.com/gin-gonic/gin" - "github.com/homenoc/dsbd-backend/pkg/api/core" - auth "github.com/homenoc/dsbd-backend/pkg/api/core/auth/v0" - "github.com/homenoc/dsbd-backend/pkg/api/core/common" - "github.com/homenoc/dsbd-backend/pkg/api/core/group/service" - "github.com/homenoc/dsbd-backend/pkg/api/core/group/service/jpnicTech" - dbJPNICTech "github.com/homenoc/dsbd-backend/pkg/api/store/group/service/jpnicTech/v0" - dbService "github.com/homenoc/dsbd-backend/pkg/api/store/group/service/v0" - "gorm.io/gorm" - "log" - "net/http" - "strconv" -) - -func Add(c *gin.Context) { - var input core.JPNICTech - userToken := c.Request.Header.Get("USER_TOKEN") - accessToken := c.Request.Header.Get("ACCESS_TOKEN") - - err := c.BindJSON(&input) - if err != nil { - log.Println(err) - c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) - return - } - - result := auth.GroupAuthorization(0, core.Token{UserToken: userToken, AccessToken: accessToken}) - if result.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: result.Err.Error()}) - return - } - - if err = check(input); err != nil { - c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) - return - } - - // check authority - if result.User.Level > 2 { - c.JSON(http.StatusUnauthorized, common.Error{Error: "You don't have authority this operation"}) - return - } - - 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 - } - - _, err = dbJPNICTech.Create(&core.JPNICTech{ - Org: input.Org, - OrgEn: input.OrgEn, - PostCode: input.PostCode, - Address: input.Address, - AddressEn: input.AddressEn, - Dept: input.Dept, - DeptEn: input.DeptEn, - Tel: input.Tel, - Fax: input.Fax, - Country: input.Country, - Lock: &[]bool{true}[0], - }) - if err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - return - } - - c.JSON(http.StatusOK, jpnicTech.Result{}) -} - -func Delete(c *gin.Context) { - userToken := c.Request.Header.Get("USER_TOKEN") - accessToken := c.Request.Header.Get("ACCESS_TOKEN") - - id, err := strconv.Atoi(c.Param("id")) - if err != nil { - c.JSON(http.StatusBadRequest, common.Error{Error: fmt.Sprintf("id error")}) - return - } - - if id <= 0 { - c.JSON(http.StatusBadRequest, common.Error{Error: "wrong id"}) - return - } - - result := auth.GroupAuthorization(0, core.Token{UserToken: userToken, AccessToken: accessToken}) - if result.Err != nil { - c.JSON(http.StatusUnauthorized, common.Error{Error: result.Err.Error()}) - return - } - - // check authority - if result.User.Level > 2 { - c.JSON(http.StatusUnauthorized, common.Error{Error: "You don't have authority this operation"}) - return - } - - resultTech := dbJPNICTech.Get(jpnicTech.ID, &core.JPNICTech{Model: gorm.Model{ID: uint(id)}}) - if resultTech.Err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: resultTech.Err.Error()}) - return - } - - if err = dbJPNICTech.Delete(&core.JPNICTech{Model: gorm.Model{ID: uint(id)}}); err != nil { - c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) - } else { - c.JSON(http.StatusOK, jpnicTech.Result{}) - } -} diff --git a/pkg/api/core/group/service/jpnicTech/v0/slack.go b/pkg/api/core/group/service/jpnicTech/v0/slack.go deleted file mode 100644 index 22cde3c8..00000000 --- a/pkg/api/core/group/service/jpnicTech/v0/slack.go +++ /dev/null @@ -1,172 +0,0 @@ -package v0 - -import ( - "github.com/ashwanthkumar/slack-go-webhook" - "github.com/homenoc/dsbd-backend/pkg/api/core" - "github.com/homenoc/dsbd-backend/pkg/api/core/group" - "github.com/homenoc/dsbd-backend/pkg/api/core/tool/notification" - slackTool "github.com/homenoc/dsbd-backend/pkg/api/core/tool/slack" - "strconv" -) - -func noticeSlack(genre uint, loginUser core.User, before core.Group, after group.Input) { - // 審査ステータスのSlack通知 - attachment := slack.Attachment{} - - attachment.Text = &[]string{"JPNIC技術連絡担当者の" + slackTool.NoticeSlackType(genre)}[0] - attachment.AddField(slack.Field{Title: "申請者", Value: strconv.Itoa(int(loginUser.ID)) + "-" + loginUser.Name}). - AddField(slack.Field{Title: "Group", Value: strconv.Itoa(int(before.ID)) + ":" + before.Org}). - AddField(slack.Field{Title: "更新状況", Value: changeText(before, after)}) - notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true}) -} - -func noticeSlackByAdmin(genre uint, before, after core.Group) { - // 審査ステータスのSlack通知 - attachment := slack.Attachment{} - - attachment.Text = &[]string{"JPNIC技術連絡担当者の" + slackTool.NoticeSlackType(genre)}[0] - attachment.AddField(slack.Field{Title: "申請者", Value: "管理者"}). - AddField(slack.Field{Title: "Group", Value: strconv.Itoa(int(before.ID)) + ":" + before.Org}). - AddField(slack.Field{Title: "更新状況", Value: changeTextByAdmin(before, after)}) - notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true}) -} - -func changeText(before core.Group, after group.Input) string { - data := "" - - if after.Org != "" && after.Org != before.Org { - data += "Org: " + before.Org + "=>" + after.Org + "\n" - } - - if after.OrgEn != "" && after.OrgEn != before.OrgEn { - data += "Org(En): " + before.OrgEn + "=>" + after.OrgEn + "\n" - } - - if after.PostCode != "" && after.PostCode != before.PostCode { - data += "PostCode: " + before.PostCode + "=>" + after.PostCode + "\n" - } - - if after.Address != "" && after.Address != before.Address { - data += "Address: " + before.Address + "=>" + after.Address + "\n" - } - - if after.AddressEn != "" && after.AddressEn != before.AddressEn { - data += "Address(En): " + before.AddressEn + "=>" + after.AddressEn + "\n" - } - - if after.Tel != "" && after.Tel != before.Tel { - data += "Tel: " + before.Tel + "=>" + after.Tel + "\n" - } - - if after.Country != "" && after.Country != before.Country { - data += "Country: " + before.Country + "=>" + after.Country + "\n" - } - - return data -} - -func changeTextByAdmin(before, after core.Group) string { - data := "" - if after.Open != nil { - if *before.Open != *after.Open { - if *after.Open { - data += "開通: 未開通 => 開通済み\n" - } else { - data += "開通: 開通 => 未開通\n" - } - } - } - - if after.Pass != nil { - if *before.Pass != *after.Pass { - if *after.Pass { - data += "審査: 未審査 => 審査合格済み\n" - } else { - data += "審査: 審査合格 => 未審査状態\n" - } - } - } - - if after.Lock != nil { - if !*before.Lock != *after.Lock { - if *after.Lock { - data += "ユーザ変更: 禁止 => 許可\n" - } else { - data += "ユーザ変更: 許可 => 禁止\n" - } - } - } - - if after.ExpiredStatus != nil { - if *before.ExpiredStatus != *after.ExpiredStatus { - data += "ExpiredStatus: " + expiredStatusText(*before.ExpiredStatus) + " => " + - expiredStatusText(*after.ExpiredStatus) + "\n" - } - } - - if after.Status != nil { - if *before.Status != *after.Status { - data += "ExpiredStatus: " + statusText(*before.Status) + " => " + statusText(*after.Status) + "\n" - } - } - - if after.Org != "" && after.Org != before.Org { - data += "Org: " + before.Org + "=>" + after.Org + "\n" - } - - if after.OrgEn != "" && after.OrgEn != before.OrgEn { - data += "Org(En): " + before.OrgEn + "=>" + after.OrgEn + "\n" - } - - if after.PostCode != "" && after.PostCode != before.PostCode { - data += "PostCode: " + before.PostCode + "=>" + after.PostCode + "\n" - } - - if after.Address != "" && after.Address != before.Address { - data += "Address: " + before.Address + "=>" + after.Address + "\n" - } - - if after.AddressEn != "" && after.AddressEn != before.AddressEn { - data += "Address(En): " + before.AddressEn + "=>" + after.AddressEn + "\n" - } - - if after.Tel != "" && after.Tel != before.Tel { - data += "Tel: " + before.Tel + "=>" + after.Tel + "\n" - } - - if after.Country != "" && after.Country != before.Country { - data += "Country: " + before.Country + "=>" + after.Country + "\n" - } - - return data -} - -func expiredStatusText(status uint) string { - if status == 0 { - return "0" - } else if status == 1 { - return "ユーザより廃止" - } else if status == 2 { - return "運営委員より廃止" - } else if status == 3 { - return "審査落ち" - } else { - return "status不明" - } -} - -func statusText(status uint) string { - if status == 0 { - return "0" - } else if status == 1 { - return "ネットワーク情報 記入段階" - } else if status == 2 { - return "審査中" - } else if status == 3 { - return "接続情報 記入段階" - } else if status == 4 { - return "開通作業中" - } else { - return "status不明" - } -} diff --git a/pkg/api/core/token/v0/admin.go b/pkg/api/core/token/v0/admin.go index a11833a4..0d22b250 100644 --- a/pkg/api/core/token/v0/admin.go +++ b/pkg/api/core/token/v0/admin.go @@ -118,7 +118,7 @@ func UpdateByAdmin(c *gin.Context) { return } - if err := dbToken.Update(token.UpdateAll, &input); err != nil { + if err = dbToken.Update(token.UpdateAll, &input); err != nil { c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) return }