Skip to content

Commit

Permalink
fix: error for the permission of the UserKey
Browse files Browse the repository at this point in the history
  • Loading branch information
saltbo committed Jul 26, 2021
1 parent 10d4b10 commit fc48150
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions internal/app/api/user_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (rs *UserKeyResource) create(c *gin.Context) {
// @Failure 500 {object} httputil.JSONResponse
// @Router /user/keys/{name} [get]
func (rs *UserKeyResource) find(c *gin.Context) {
uk, err := rs.dUserKey.Find(c.Param("name"))
uk, err := rs.dUserKey.Find(authed.UidGet(c), c.Param("name"))
if err != nil {
ginutil.JSONBadRequest(c, err)
return
Expand All @@ -89,7 +89,7 @@ func (rs *UserKeyResource) find(c *gin.Context) {
// @Failure 500 {object} httputil.JSONResponse
// @Router /user/keys/{name}/secret [patch]
func (rs *UserKeyResource) reset(c *gin.Context) {
uk, err := rs.dUserKey.Find(c.Param("name"))
uk, err := rs.dUserKey.Find(authed.UidGet(c), c.Param("name"))
if err != nil {
ginutil.JSONBadRequest(c, err)
return
Expand All @@ -115,7 +115,7 @@ func (rs *UserKeyResource) reset(c *gin.Context) {
// @Failure 500 {object} httputil.JSONResponse
// @Router /user/keys/{name} [delete]
func (rs *UserKeyResource) remove(c *gin.Context) {
uk, err := rs.dUserKey.Find(c.Param("name"))
uk, err := rs.dUserKey.Find(authed.UidGet(c), c.Param("name"))
if err != nil {
ginutil.JSONBadRequest(c, err)
return
Expand Down
6 changes: 3 additions & 3 deletions internal/app/dao/user_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func NewUserKey() *UserKey {
return &UserKey{}
}

func (u *UserKey) Find(name string) (*model.UserKey, error) {
func (u *UserKey) Find(uid int64, name string) (*model.UserKey, error) {
uk := new(model.UserKey)
if err := gdb.Where("name=?", name).First(uk).Error; errors.Is(err, gorm.ErrRecordNotFound) {
if err := gdb.Where("uid=? and name=?", uid, name).First(uk).Error; errors.Is(err, gorm.ErrRecordNotFound) {
return nil, fmt.Errorf("userKey not exist")
}

Expand All @@ -46,7 +46,7 @@ func (u *UserKey) FindAll(query *Query) (list []*model.UserKey, total int64, err
}

func (u *UserKey) Create(uk *model.UserKey) (*model.UserKey, error) {
if _, err := u.Find(uk.Name); err == nil {
if _, err := u.Find(uk.Uid, uk.Name); err == nil {
return nil, fmt.Errorf("userKey already exist: %s", uk.Name)
}

Expand Down

0 comments on commit fc48150

Please sign in to comment.