Skip to content

Commit

Permalink
Merge pull request #512 from traPtitech/fix-privilege-typo
Browse files Browse the repository at this point in the history
✏️ fix privilege typo
  • Loading branch information
iChemy authored Jan 5, 2024
2 parents 1bf18fe + 8956f62 commit a05162a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion domain/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type UserRepository interface {
ReNewMyiCalSecret(info *ConInfo) (string, error)
GetMyiCalSecret(info *ConInfo) (string, error)

IsPrevilege(info *ConInfo) bool
IsPrivilege(info *ConInfo) bool
GrantPrivilege(userID uuid.UUID) error
SyncUsers(info *ConInfo) error
}
2 changes: 1 addition & 1 deletion infra/db/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (repo *GormRepository) SyncUsers(users []*User) error {

// saveUser user.IcalSecret == "" の時、値は更新されません。
// また、user.Provider, user.Tokenは空の時、更新されません。
// user.Previlegeは常に更新されません
// user.Privilegeは常に更新されません
func saveUser(db *gorm.DB, user *User) (*User, error) {
err := db.Transaction(func(tx *gorm.DB) error {
existingUser, err := getUser(tx.Preload("Provider").Preload("Token"), user.ID)
Expand Down
6 changes: 3 additions & 3 deletions repository/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (repo *Repository) CreateUnVerifiedRoom(params domain.WriteRoomParams, info
}

func (repo *Repository) CreateVerifiedRoom(params domain.WriteRoomParams, info *domain.ConInfo) (*domain.Room, error) {
if !repo.IsPrevilege(info) {
if !repo.IsPrivilege(info) {
return nil, domain.ErrForbidden
}
p := db.CreateRoomParams{
Expand All @@ -46,15 +46,15 @@ func (repo *Repository) UpdateRoom(roomID uuid.UUID, params domain.WriteRoomPara
}

func (repo *Repository) VerifyRoom(roomID uuid.UUID, info *domain.ConInfo) error {
if !repo.IsPrevilege(info) {
if !repo.IsPrivilege(info) {
return domain.ErrForbidden
}
err := repo.GormRepo.UpdateRoomVerified(roomID, true)
return defaultErrorHandling(err)
}

func (repo *Repository) UnVerifyRoom(roomID uuid.UUID, info *domain.ConInfo) error {
if !repo.IsPrevilege(info) {
if !repo.IsPrivilege(info) {
return domain.ErrForbidden
}
err := repo.GormRepo.UpdateRoomVerified(roomID, false)
Expand Down
6 changes: 3 additions & 3 deletions repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
const traQIssuerName = "traQ"

func (repo *Repository) SyncUsers(info *domain.ConInfo) error {
if !repo.IsPrevilege(info) {
if !repo.IsPrivilege(info) {
return domain.ErrForbidden
}
t, err := repo.GormRepo.GetToken(info.ReqUserID)
Expand Down Expand Up @@ -174,7 +174,7 @@ func (repo *Repository) GetMyiCalSecret(info *domain.ConInfo) (string, error) {
return user.IcalSecret, nil
}

func (repo *Repository) IsPrevilege(info *domain.ConInfo) bool {
func (repo *Repository) IsPrivilege(info *domain.ConInfo) bool {
user, err := repo.GormRepo.GetUser(info.ReqUserID)
if err != nil {
return false
Expand All @@ -185,7 +185,7 @@ func (repo *Repository) IsPrevilege(info *domain.ConInfo) bool {
func traQUserMap(users []traq.User) map[uuid.UUID]*traq.User {
userMap := make(map[uuid.UUID]*traq.User)
for _, u := range users {
user:=u
user := u
userMap[uuid.Must(uuid.FromString(user.GetId()))] = &user
}
return userMap
Expand Down
6 changes: 3 additions & 3 deletions router/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ func (h *Handlers) TraQUserMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
}
}

// PrevilegeUserMiddleware 管理者ユーザーか判定するミドルウェア
func (h *Handlers) PrevilegeUserMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
// PrivilegeUserMiddleware 管理者ユーザーか判定するミドルウェア
func (h *Handlers) PrivilegeUserMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// 判定
if !h.Repo.IsPrevilege(getConinfo(c)) {
if !h.Repo.IsPrivilege(getConinfo(c)) {
return forbidden(
errors.New("not admin"),
message("You are not admin user."),
Expand Down
14 changes: 7 additions & 7 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func (h *Handlers) SetupRoute() *echo.Echo {
roomsAPI.DELETE("/:roomid", h.HandleDeleteRoom)

// サービス管理者権限が必要
roomsAPIWithPrevilegeAuth := roomsAPI.Group("", h.PrevilegeUserMiddleware)
roomsAPIWithPrivilegeAuth := roomsAPI.Group("", h.PrivilegeUserMiddleware)
{
roomsAPIWithPrevilegeAuth.POST("/all", h.HandleCreateVerifedRooms)
roomsAPIWithPrevilegeAuth.POST("/:roomid/verified", h.HandleVerifyRoom)
roomsAPIWithPrevilegeAuth.DELETE("/:roomid/verified", h.HandleUnVerifyRoom)
roomsAPIWithPrivilegeAuth.POST("/all", h.HandleCreateVerifedRooms)
roomsAPIWithPrivilegeAuth.POST("/:roomid/verified", h.HandleVerifyRoom)
roomsAPIWithPrivilegeAuth.DELETE("/:roomid/verified", h.HandleUnVerifyRoom)
}
}

Expand All @@ -132,10 +132,10 @@ func (h *Handlers) SetupRoute() *echo.Echo {
usersAPI.GET("/:userid/groups", h.HandleGetGroupIDsByUserID)

// サービス管理者権限が必要
usersAPIWithPrevilegeAuth := usersAPI.Group("", h.PrevilegeUserMiddleware)
usersAPIWithPrivilegeAuth := usersAPI.Group("", h.PrivilegeUserMiddleware)
{
usersAPIWithPrevilegeAuth.PATCH("/:userid/privileged", h.HandleGrantPrivilege)
usersAPIWithPrevilegeAuth.POST("/sync", h.HandleSyncUser)
usersAPIWithPrivilegeAuth.PATCH("/:userid/privileged", h.HandleGrantPrivilege)
usersAPIWithPrivilegeAuth.POST("/sync", h.HandleSyncUser)
}
}

Expand Down

0 comments on commit a05162a

Please sign in to comment.