mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-19 00:47:28 +00:00
refactor(oauth): update UpdateCustomOAuthProviderRequest to use pointers for optional fields
- Change fields in UpdateCustomOAuthProviderRequest struct to use pointers for optional values, allowing for better handling of nil cases. - Update UpdateCustomOAuthProvider function to check for nil before assigning optional fields, ensuring existing values are preserved when not provided.
This commit is contained in:
@@ -166,21 +166,21 @@ func CreateCustomOAuthProvider(c *gin.Context) {
|
|||||||
|
|
||||||
// UpdateCustomOAuthProviderRequest is the request structure for updating a custom OAuth provider
|
// UpdateCustomOAuthProviderRequest is the request structure for updating a custom OAuth provider
|
||||||
type UpdateCustomOAuthProviderRequest struct {
|
type UpdateCustomOAuthProviderRequest struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
Enabled bool `json:"enabled"`
|
Enabled *bool `json:"enabled"` // Optional: if nil, keep existing
|
||||||
ClientId string `json:"client_id"`
|
ClientId string `json:"client_id"`
|
||||||
ClientSecret string `json:"client_secret"` // Optional: if empty, keep existing
|
ClientSecret string `json:"client_secret"` // Optional: if empty, keep existing
|
||||||
AuthorizationEndpoint string `json:"authorization_endpoint"`
|
AuthorizationEndpoint string `json:"authorization_endpoint"`
|
||||||
TokenEndpoint string `json:"token_endpoint"`
|
TokenEndpoint string `json:"token_endpoint"`
|
||||||
UserInfoEndpoint string `json:"user_info_endpoint"`
|
UserInfoEndpoint string `json:"user_info_endpoint"`
|
||||||
Scopes string `json:"scopes"`
|
Scopes string `json:"scopes"`
|
||||||
UserIdField string `json:"user_id_field"`
|
UserIdField string `json:"user_id_field"`
|
||||||
UsernameField string `json:"username_field"`
|
UsernameField string `json:"username_field"`
|
||||||
DisplayNameField string `json:"display_name_field"`
|
DisplayNameField string `json:"display_name_field"`
|
||||||
EmailField string `json:"email_field"`
|
EmailField string `json:"email_field"`
|
||||||
WellKnown string `json:"well_known"`
|
WellKnown *string `json:"well_known"` // Optional: if nil, keep existing
|
||||||
AuthStyle int `json:"auth_style"`
|
AuthStyle *int `json:"auth_style"` // Optional: if nil, keep existing
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateCustomOAuthProvider updates an existing custom OAuth provider
|
// UpdateCustomOAuthProvider updates an existing custom OAuth provider
|
||||||
@@ -227,7 +227,9 @@ func UpdateCustomOAuthProvider(c *gin.Context) {
|
|||||||
if req.Slug != "" {
|
if req.Slug != "" {
|
||||||
provider.Slug = req.Slug
|
provider.Slug = req.Slug
|
||||||
}
|
}
|
||||||
provider.Enabled = req.Enabled
|
if req.Enabled != nil {
|
||||||
|
provider.Enabled = *req.Enabled
|
||||||
|
}
|
||||||
if req.ClientId != "" {
|
if req.ClientId != "" {
|
||||||
provider.ClientId = req.ClientId
|
provider.ClientId = req.ClientId
|
||||||
}
|
}
|
||||||
@@ -258,8 +260,12 @@ func UpdateCustomOAuthProvider(c *gin.Context) {
|
|||||||
if req.EmailField != "" {
|
if req.EmailField != "" {
|
||||||
provider.EmailField = req.EmailField
|
provider.EmailField = req.EmailField
|
||||||
}
|
}
|
||||||
provider.WellKnown = req.WellKnown
|
if req.WellKnown != nil {
|
||||||
provider.AuthStyle = req.AuthStyle
|
provider.WellKnown = *req.WellKnown
|
||||||
|
}
|
||||||
|
if req.AuthStyle != nil {
|
||||||
|
provider.AuthStyle = *req.AuthStyle
|
||||||
|
}
|
||||||
|
|
||||||
if err := model.UpdateCustomOAuthProvider(provider); err != nil {
|
if err := model.UpdateCustomOAuthProvider(provider); err != nil {
|
||||||
common.ApiError(c, err)
|
common.ApiError(c, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user