Skip to content

Commit

Permalink
Merge pull request #508 from gotify/update
Browse files Browse the repository at this point in the history
Update Dependencies
  • Loading branch information
jmattheis committed Sep 10, 2022
2 parents f16ce59 + e68c556 commit c4e6386
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -7,7 +7,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.19.x
- uses: actions/setup-node@v1
with:
node-version: '16'
Expand Down
2 changes: 1 addition & 1 deletion GO_VERSION
@@ -1 +1 @@
1.16.0
1.19.1
31 changes: 21 additions & 10 deletions api/user.go
Expand Up @@ -147,7 +147,7 @@ func (a *UserAPI) GetCurrentUser(ctx *gin.Context) {
// description: the user to add
// required: true
// schema:
// $ref: "#/definitions/UserWithPass"
// $ref: "#/definitions/CreateUserExternal"
// responses:
// 200:
// description: Ok
Expand All @@ -166,9 +166,13 @@ func (a *UserAPI) GetCurrentUser(ctx *gin.Context) {
// schema:
// $ref: "#/definitions/Error"
func (a *UserAPI) CreateUser(ctx *gin.Context) {
user := model.UserExternalWithPass{}
user := model.CreateUserExternal{}
if err := ctx.Bind(&user); err == nil {
internal := a.toInternalUser(&user, []byte{})
internal := &model.User{
Name: user.Name,
Admin: user.Admin,
Pass: password.CreatePassword(user.Pass, a.PasswordStrength),
}
existingUser, err := a.DB.GetUserByName(internal.Name)
if success := successOrAbort(ctx, 500, err); !success {
return
Expand Down Expand Up @@ -389,7 +393,7 @@ func (a *UserAPI) ChangePassword(ctx *gin.Context) {
// description: the updated user
// required: true
// schema:
// $ref: "#/definitions/UserWithPass"
// $ref: "#/definitions/UpdateUserExternal"
// responses:
// 200:
// description: Ok
Expand All @@ -413,7 +417,7 @@ func (a *UserAPI) ChangePassword(ctx *gin.Context) {
// $ref: "#/definitions/Error"
func (a *UserAPI) UpdateUserByID(ctx *gin.Context) {
withID(ctx, "id", func(id uint) {
var user *model.UserExternalWithPass
var user *model.UpdateUserExternal
if err := ctx.Bind(&user); err == nil {
oldUser, err := a.DB.GetUserByID(id)
if success := successOrAbort(ctx, 500, err); !success {
Expand All @@ -428,8 +432,15 @@ func (a *UserAPI) UpdateUserByID(ctx *gin.Context) {
ctx.AbortWithError(400, errors.New("cannot delete last admin"))
return
}
internal := a.toInternalUser(user, oldUser.Pass)
internal.ID = id
internal := &model.User{
ID: oldUser.ID,
Name: user.Name,
Admin: user.Admin,
Pass: oldUser.Pass,
}
if user.Pass != "" {
internal.Pass = password.CreatePassword(user.Pass, a.PasswordStrength)
}
if success := successOrAbort(ctx, 500, a.DB.UpdateUser(internal)); !success {
return
}
Expand All @@ -441,13 +452,13 @@ func (a *UserAPI) UpdateUserByID(ctx *gin.Context) {
})
}

func (a *UserAPI) toInternalUser(response *model.UserExternalWithPass, pw []byte) *model.User {
func (a *UserAPI) toInternalUser(response *model.UserExternal, newPass string, pw []byte) *model.User {
user := &model.User{
Name: response.Name,
Admin: response.Admin,
}
if response.Pass != "" {
user.Pass = password.CreatePassword(response.Pass, a.PasswordStrength)
if newPass != "" {
user.Pass = password.CreatePassword(newPass, a.PasswordStrength)
} else {
user.Pass = pw
}
Expand Down
94 changes: 58 additions & 36 deletions docs/spec.json
Expand Up @@ -1634,7 +1634,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/UserWithPass"
"$ref": "#/definitions/CreateUserExternal"
}
}
],
Expand Down Expand Up @@ -1771,7 +1771,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/UserWithPass"
"$ref": "#/definitions/UpdateUserExternal"
}
}
],
Expand Down Expand Up @@ -2005,6 +2005,37 @@
},
"x-go-package": "github.com/gotify/server/v2/model"
},
"CreateUserExternal": {
"description": "Used for user creation.",
"type": "object",
"title": "CreateUserExternal Model",
"required": [
"name",
"admin",
"pass"
],
"properties": {
"admin": {
"description": "If the user is an administrator.",
"type": "boolean",
"x-go-name": "Admin",
"example": true
},
"name": {
"description": "The user name. For login.",
"type": "string",
"x-go-name": "Name",
"example": "unicorn"
},
"pass": {
"description": "The user password. For login.",
"type": "string",
"x-go-name": "Pass",
"example": "nrocinu"
}
},
"x-go-package": "github.com/gotify/server/v2/model"
},
"Error": {
"description": "The Error contains error relevant information.",
"type": "object",
Expand Down Expand Up @@ -2290,13 +2321,13 @@
"x-go-name": "PluginConfExternal",
"x-go-package": "github.com/gotify/server/v2/model"
},
"User": {
"description": "The User holds information about permission and other stuff.",
"UpdateUserExternal": {
"description": "Used for updating a user.",
"type": "object",
"title": "UserExternal Model",
"title": "UpdateUserExternal Model",
"required": [
"id",
"name"
"name",
"admin"
],
"properties": {
"admin": {
Expand All @@ -2305,50 +2336,29 @@
"x-go-name": "Admin",
"example": true
},
"id": {
"description": "The user id.",
"type": "integer",
"format": "int64",
"x-go-name": "ID",
"readOnly": true,
"example": 25
},
"name": {
"description": "The user name. For login.",
"type": "string",
"x-go-name": "Name",
"example": "unicorn"
}
},
"x-go-name": "UserExternal",
"x-go-package": "github.com/gotify/server/v2/model"
},
"UserPass": {
"description": "The Password for updating the user.",
"type": "object",
"title": "UserExternalPass Model",
"required": [
"pass"
],
"properties": {
},
"pass": {
"description": "The user password. For login.",
"description": "The user password. For login. Empty for using old password",
"type": "string",
"x-go-name": "Pass",
"example": "nrocinu"
}
},
"x-go-name": "UserExternalPass",
"x-go-package": "github.com/gotify/server/v2/model"
},
"UserWithPass": {
"description": "The UserWithPass holds information about the credentials and other stuff.",
"User": {
"description": "The User holds information about permission and other stuff.",
"type": "object",
"title": "UserExternalWithPass Model",
"title": "UserExternal Model",
"required": [
"id",
"name",
"pass"
"admin"
],
"properties": {
"admin": {
Expand All @@ -2370,15 +2380,27 @@
"type": "string",
"x-go-name": "Name",
"example": "unicorn"
},
}
},
"x-go-name": "UserExternal",
"x-go-package": "github.com/gotify/server/v2/model"
},
"UserPass": {
"description": "The Password for updating the user.",
"type": "object",
"title": "UserExternalPass Model",
"required": [
"pass"
],
"properties": {
"pass": {
"description": "The user password. For login.",
"type": "string",
"x-go-name": "Pass",
"example": "nrocinu"
}
},
"x-go-name": "UserExternalWithPass",
"x-go-name": "UserExternalPass",
"x-go-package": "github.com/gotify/server/v2/model"
},
"VersionInfo": {
Expand Down
63 changes: 45 additions & 18 deletions go.mod
Expand Up @@ -2,34 +2,61 @@ module github.com/gotify/server/v2

require (
github.com/fortytw2/leaktest v1.3.0
github.com/gin-contrib/cors v1.3.1
github.com/gin-contrib/gzip v0.0.3
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.3.0
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/logger v1.0.3 // indirect
github.com/gobuffalo/packd v1.0.0 // indirect
github.com/gin-contrib/cors v1.4.0
github.com/gin-contrib/gzip v0.0.6
github.com/gin-gonic/gin v1.8.1
github.com/go-playground/validator/v10 v10.11.0
github.com/gobuffalo/packr/v2 v2.7.1
github.com/golang/protobuf v1.4.2 // indirect
github.com/gorilla/websocket v1.4.2
github.com/gorilla/websocket v1.5.0
github.com/gotify/configor v1.0.2
github.com/gotify/location v0.0.0-20170722210143-03bc4ad20437
github.com/gotify/plugin-api v1.0.0
github.com/h2non/filetype v1.1.1
github.com/h2non/filetype v1.1.3
github.com/jinzhu/gorm v1.9.16
github.com/json-iterator/go v1.1.10 // indirect
github.com/robfig/cron v1.2.0
github.com/stretchr/testify v1.8.0
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-sql-driver/mysql v1.5.0 // indirect
github.com/go-yaml/yaml v2.1.0+incompatible // indirect
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/logger v1.0.3 // indirect
github.com/gobuffalo/packd v1.0.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/joho/godotenv v1.3.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lib/pq v1.10.0 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v1.14.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967
github.com/rogpeppe/go-internal v1.6.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/spf13/cobra v0.0.6 // indirect
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
github.com/spf13/pflag v1.0.3 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/yaml.v2 v2.4.0
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.14
go 1.18

0 comments on commit c4e6386

Please sign in to comment.