Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions cmd/server/openapi/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/Forge"
"$ref": "#/definitions/ForgeWithOAuthClientSecret"
}
}
],
Expand Down Expand Up @@ -774,7 +774,7 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/Forge"
"$ref": "#/definitions/ForgeWithOAuthClientSecret"
}
}
],
Expand Down Expand Up @@ -4809,6 +4809,37 @@ const docTemplate = `{
}
}
},
"ForgeWithOAuthClientSecret": {
"type": "object",
"properties": {
"additional_options": {
"type": "object",
"additionalProperties": {}
},
"client": {
"type": "string"
},
"id": {
"type": "integer"
},
"oauth_client_secret": {
"type": "string"
},
"oauth_host": {
"description": "public url for oauth if different from url",
"type": "string"
},
"skip_verify": {
"type": "boolean"
},
"type": {
"$ref": "#/definitions/model.ForgeType"
},
"url": {
"type": "string"
}
}
},
"LogEntry": {
"type": "object",
"properties": {
Expand Down
24 changes: 9 additions & 15 deletions server/api/forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,13 @@ func GetForge(c *gin.Context) {
// @Produce json
// @Success 200 {object} Forge
// @Tags Forges
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param forgeId path int true "the forge's id"
// @Param forgeData body Forge true "the forge's data"
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param forgeId path int true "the forge's id"
// @Param forgeData body ForgeWithOAuthClientSecret true "the forge's data"
func PatchForge(c *gin.Context) {
_store := store.FromContext(c)

// use this struct to allow updating the client secret
type ForgeWithClientSecret struct {
model.Forge
ClientSecret string `json:"client_secret"`
}

in := &ForgeWithClientSecret{}
in := &model.ForgeWithOAuthClientSecret{}
err := c.Bind(in)
if err != nil {
c.AbortWithStatus(http.StatusBadRequest)
Expand All @@ -129,8 +123,8 @@ func PatchForge(c *gin.Context) {
forge.OAuthHost = in.OAuthHost
forge.SkipVerify = in.SkipVerify
forge.AdditionalOptions = in.AdditionalOptions
if in.ClientSecret != "" {
forge.OAuthClientSecret = in.ClientSecret
if in.OAuthClientSecret != "" {
forge.OAuthClientSecret = in.OAuthClientSecret
}

err = _store.ForgeUpdate(forge)
Expand All @@ -150,10 +144,10 @@ func PatchForge(c *gin.Context) {
// @Produce json
// @Success 200 {object} Forge
// @Tags Forges
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param forge body Forge true "the forge's data (only 'name' and 'no_schedule' are read)"
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param forge body ForgeWithOAuthClientSecret true "the forge's data (only 'name' and 'no_schedule' are read)"
func PostForge(c *gin.Context) {
in := &model.Forge{}
in := &model.ForgeWithOAuthClientSecret{}
err := c.Bind(in)
if err != nil {
c.String(http.StatusBadRequest, err.Error())
Expand Down
6 changes: 6 additions & 0 deletions server/model/forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ func (f *Forge) PublicCopy() *Forge {

return forge
}

// ForgeWithOAuthClientSecret allows to update the client secret.
type ForgeWithOAuthClientSecret struct {
Forge
OAuthClientSecret string `json:"oauth_client_secret"`
} // @name ForgeWithOAuthClientSecret
3 changes: 1 addition & 2 deletions web/src/components/admin/settings/forges/AdminForgeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<InputField v-slot="{ id }" :label="$t('oauth_client_secret')">
<TextField
:id="id"
v-model="forge.client_secret"
v-model="forge.oauth_client_secret"
:placeholder="isNew ? '' : $t('leave_empty_to_keep_current_value')"
:required="isNew"
/>
Expand Down Expand Up @@ -263,7 +263,6 @@ const oauthAppForgeUrl = computed(() => {
case 'forgejo':
return `${forgeUrl}/user/settings/applications`;
case 'bitbucket':
return `${forgeUrl}/account/settings/app-passwords`;
case 'bitbucket-dc':
return `${forgeUrl}/account/settings/app-passwords`;
default:
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/api/types/forge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface Forge {
type: ForgeType;
url: string;
client?: string;
client_secret?: string;
oauth_client_secret?: string;
skip_verify?: boolean;
oauth_host?: string;
additional_options?: Record<string, unknown>;
Expand Down