Skip to content

Commit

Permalink
Merge pull request #890 from traPtitech/fix/887
Browse files Browse the repository at this point in the history
fix #887
  • Loading branch information
wtks authored May 5, 2020
2 parents 87ab64e + 79b9ba8 commit 716e99a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 5 additions & 1 deletion docs/v3-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,8 @@ paths:
$ref: '#/components/schemas/UserTag'
'400':
description: Bad Request
'403':
description: Forbidden
'404':
description: |-
Not Found
Expand All @@ -1777,7 +1779,9 @@ paths:
schema:
$ref: '#/components/schemas/PostUserTagRequest'
description: ''
description: 指定したユーザーに指定したタグを追加します。
description: |-
指定したユーザーに指定したタグを追加します。
Webhookユーザーにタグを追加することは出来ません。
'/users/{userId}/tags/{tagId}':
parameters:
- $ref: '#/components/parameters/userIdInPath'
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,6 @@ google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/
google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
google.golang.org/api v0.20.0 h1:jz2KixHX7EcCPiQrySzPdnYT7DbINAypCqKZ1Z7GM40=
google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
google.golang.org/api v0.22.0 h1:J1Pl9P2lnmYFSJvgs70DKELqHNh8CNWXPbud4njEE2s=
google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
google.golang.org/api v0.23.0 h1:YlvGEOq2NA2my8cZ/9V8BcEO9okD48FlJcdqN0xJL3s=
google.golang.org/api v0.23.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs=
Expand Down
8 changes: 6 additions & 2 deletions router/v1/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
vd "github.com/go-ozzo/ozzo-validation/v4"
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/traPtitech/traQ/model"
"github.com/traPtitech/traQ/repository"
"github.com/traPtitech/traQ/router/consts"
"github.com/traPtitech/traQ/router/extension/herror"
Expand Down Expand Up @@ -35,7 +36,10 @@ func (r PostUserTagRequest) Validate() error {

// PostUserTag POST /users/:userID/tags
func (h *Handlers) PostUserTag(c echo.Context) error {
userID := getRequestParamAsUUID(c, consts.ParamUserID)
user := getUserFromContext(c)
if user.GetUserType() == model.UserTypeWebhook {
return herror.Forbidden("tags cannot be added to webhook user")
}

// リクエスト検証
var req PostUserTagRequest
Expand All @@ -50,7 +54,7 @@ func (h *Handlers) PostUserTag(c echo.Context) error {
}

// ユーザーにタグを付与
if err := h.Repo.AddUserTag(userID, t.ID); err != nil {
if err := h.Repo.AddUserTag(user.GetID(), t.ID); err != nil {
switch err {
case repository.ErrAlreadyExists:
return c.NoContent(http.StatusNoContent)
Expand Down
4 changes: 4 additions & 0 deletions router/v3/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
vd "github.com/go-ozzo/ozzo-validation/v4"
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/traPtitech/traQ/model"
"github.com/traPtitech/traQ/repository"
"github.com/traPtitech/traQ/router/consts"
"github.com/traPtitech/traQ/router/extension/herror"
Expand Down Expand Up @@ -43,6 +44,9 @@ func (r PostUserTagRequest) Validate() error {

// AddUserTag POST /users/:userID/tags
func (h *Handlers) AddUserTag(c echo.Context) error {
if getParamUser(c).GetUserType() == model.UserTypeWebhook {
return herror.Forbidden("tags cannot be added to webhook user")
}
return addUserTags(c, h.Repo, getParamAsUUID(c, consts.ParamUserID))
}

Expand Down

0 comments on commit 716e99a

Please sign in to comment.