diff options
author | qwerty287 <80460567+qwerty287@users.noreply.github.com> | 2022-10-09 14:07:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-09 20:07:41 +0800 |
commit | a813c9d8f3862fec934ff657fb4e490530167183 (patch) | |
tree | 877ca996565a94fa0f22d53e9e737dfd47ba8077 /templates/user | |
parent | 97f3f1988b2b544350f58aa8b49cb958bb4da5b5 (diff) | |
download | gitea-a813c9d8f3862fec934ff657fb4e490530167183.tar.gz gitea-a813c9d8f3862fec934ff657fb4e490530167183.zip |
Allow creation of OAuth2 applications for orgs (#18084)
Adds the settings pages to create OAuth2 apps also to the org settings
and allows to create apps for orgs.
Refactoring: the oauth2 related templates are shared for
instance-wide/org/user, and the backend code uses `OAuth2CommonHandlers`
to share code for instance-wide/org/user.
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'templates/user')
5 files changed, 110 insertions, 118 deletions
diff --git a/templates/user/settings/applications_oauth2.tmpl b/templates/user/settings/applications_oauth2.tmpl index 5e53ed00ca..47d8dfc2de 100644 --- a/templates/user/settings/applications_oauth2.tmpl +++ b/templates/user/settings/applications_oauth2.tmpl @@ -1,59 +1,6 @@ <h4 class="ui top attached header"> {{.locale.Tr "settings.manage_oauth2_applications"}} </h4> -<div class="ui attached segment"> - <div class="ui key list"> - <div class="item"> - {{.locale.Tr "settings.oauth2_application_create_description"}} - </div> - {{range $app := .Applications}} - <div class="item"> - <div class="right floated content"> - <a href="{{$.Link}}/oauth2/{{$app.ID}}" class="ui primary tiny button"> - {{svg "octicon-pencil" 16 "mr-2"}} - {{$.locale.Tr "settings.oauth2_application_edit"}} - </a> - <button class="ui red tiny button delete-button" data-modal-id="remove-gitea-oauth2-application" - data-url="{{AppSubUrl}}/user/settings/applications/oauth2/delete" - data-id="{{$app.ID}}"> - {{svg "octicon-trash" 16 "mr-2"}} - {{$.locale.Tr "settings.delete_key"}} - </button> - </div> - <div class="content"> - <strong>{{$app.Name}}</strong> - </div> - </div> - {{end}} - </div> -</div> -<div class="ui attached bottom segment"> - <h5 class="ui top header"> - {{.locale.Tr "settings.create_oauth2_application"}} - </h5> - <form class="ui form ignore-dirty" action="{{.Link}}/oauth2" method="post"> - {{.CsrfTokenHtml}} - <div class="field {{if .Err_AppName}}error{{end}}"> - <label for="application-name">{{.locale.Tr "settings.oauth2_application_name"}}</label> - <input id="application-name" name="application_name" value="{{.application_name}}" required> - </div> - <div class="field {{if .Err_RedirectURI}}error{{end}}"> - <label for="redirect-uri">{{.locale.Tr "settings.oauth2_redirect_uri"}}</label> - <input type="url" name="redirect_uri" id="redirect-uri"> - </div> - <button class="ui green button"> - {{.locale.Tr "settings.create_oauth2_application_button"}} - </button> - </form> -</div> -<div class="ui small basic delete modal" id="remove-gitea-oauth2-application"> - <div class="ui icon header"> - {{svg "octicon-trash"}} - {{.locale.Tr "settings.remove_oauth2_application"}} - </div> - <div class="content"> - <p>{{.locale.Tr "settings.oauth2_application_remove_description"}}</p> - </div> - {{template "base/delete_modal_actions" .}} -</div> +{{template "user/settings/applications_oauth2_list" .}} + diff --git a/templates/user/settings/applications_oauth2_edit.tmpl b/templates/user/settings/applications_oauth2_edit.tmpl index be3e78e46b..eb40976fb1 100644 --- a/templates/user/settings/applications_oauth2_edit.tmpl +++ b/templates/user/settings/applications_oauth2_edit.tmpl @@ -1,68 +1,8 @@ {{template "base/head" .}} <div class="page-content user settings applications"> {{template "user/settings/navbar" .}} - <div class="ui container"> - {{template "base/alert" .}} - <h4 class="ui top attached header"> - {{.locale.Tr "settings.edit_oauth2_application"}} - </h4> - <div class="ui attached segment"> - <p>{{.locale.Tr "settings.oauth2_application_create_description"}}</p> - </div> - <div class="ui attached segment form ignore-dirty"> - {{.CsrfTokenHtml}} - <div class="field"> - <label for="client-id">{{.locale.Tr "settings.oauth2_client_id"}}</label> - <input id="client-id" readonly value="{{.App.ClientID}}"> - </div> - {{if .ClientSecret}} - <div class="field"> - <label for="client-secret">{{.locale.Tr "settings.oauth2_client_secret"}}</label> - <input id="client-secret" type="text" readonly value="{{.ClientSecret}}"> - </div> - {{else}} - <div class="field"> - <label for="client-secret">{{.locale.Tr "settings.oauth2_client_secret"}}</label> - <input id="client-secret" type="password" readonly value="averysecuresecret"> - </div> - {{end}} - <div class="item"> - <!-- TODO add regenerate secret functionality */ --> - {{.locale.Tr "settings.oauth2_regenerate_secret_hint"}} - <form class="ui form ignore-dirty" action="{{AppSubUrl}}/user/settings/applications/oauth2/{{.App.ID}}/regenerate_secret" method="post"> - {{.CsrfTokenHtml}} - <a href="#" onclick="event.target.parentNode.submit()">{{.locale.Tr "settings.oauth2_regenerate_secret"}}</a> - </form> - </div> - </div> - <div class="ui attached bottom segment"> - <form class="ui form ignore-dirty" action="{{AppSubUrl}}/user/settings/applications/oauth2/{{.App.ID}}" method="post"> - {{.CsrfTokenHtml}} - <div class="field {{if .Err_AppName}}error{{end}}"> - <label for="application-name">{{.locale.Tr "settings.oauth2_application_name"}}</label> - <input id="application-name" value="{{.App.Name}}" name="application_name" required> - </div> - <div class="field {{if .Err_RedirectURI}}error{{end}}"> - <label for="redirect-uri">{{.locale.Tr "settings.oauth2_redirect_uri"}}</label> - <input type="url" name="redirect_uri" value="{{.App.PrimaryRedirectURI}}" id="redirect-uri"> - </div> - <button class="ui green button"> - {{.locale.Tr "settings.save_application"}} - </button> - </form> - </div> - </div> -</div> -<div class="ui small basic delete modal" id="delete-oauth2-application"> - <div class="ui icon header"> - {{svg "octicon-trash"}} - {{.locale.Tr "settings.remove_oauth2_application"}} - </div> - <div class="content"> - <p>{{.locale.Tr "settings.remove_oauth2_application_desc"}}</p> - </div> - {{template "base/delete_modal_actions" .}} + {{template "user/settings/applications_oauth2_edit_form" .}} </div> {{template "base/footer" .}} diff --git a/templates/user/settings/applications_oauth2_edit_form.tmpl b/templates/user/settings/applications_oauth2_edit_form.tmpl new file mode 100644 index 0000000000..60311983c9 --- /dev/null +++ b/templates/user/settings/applications_oauth2_edit_form.tmpl @@ -0,0 +1,51 @@ +<div class="ui container"> + {{template "base/alert" .}} + <h4 class="ui top attached header"> + {{.locale.Tr "settings.edit_oauth2_application"}} + </h4> + <div class="ui attached segment"> + <p>{{.locale.Tr "settings.oauth2_application_create_description"}}</p> + </div> + <div class="ui attached segment form ignore-dirty"> + {{.CsrfTokenHtml}} + <div class="field"> + <label for="client-id">{{.locale.Tr "settings.oauth2_client_id"}}</label> + <input id="client-id" readonly value="{{.App.ClientID}}"> + </div> + {{if .ClientSecret}} + <div class="field"> + <label for="client-secret">{{.locale.Tr "settings.oauth2_client_secret"}}</label> + <input id="client-secret" type="text" readonly value="{{.ClientSecret}}"> + </div> + {{else}} + <div class="field"> + <label for="client-secret">{{.locale.Tr "settings.oauth2_client_secret"}}</label> + <input id="client-secret" type="password" readonly value="averysecuresecret"> + </div> + {{end}} + <div class="item"> + <!-- TODO add regenerate secret functionality */ --> + <form class="ui form ignore-dirty" action="{{.FormActionPath}}/regenerate_secret" method="post"> + {{.CsrfTokenHtml}} + {{.locale.Tr "settings.oauth2_regenerate_secret_hint"}} + <button class="ui tertiary button" type="submit">{{.locale.Tr "settings.oauth2_regenerate_secret"}}</button> + </form> + </div> + </div> + <div class="ui attached bottom segment"> + <form class="ui form ignore-dirty" action="{{.FormActionPath}}" method="post"> + {{.CsrfTokenHtml}} + <div class="field {{if .Err_AppName}}error{{end}}"> + <label for="application-name">{{.locale.Tr "settings.oauth2_application_name"}}</label> + <input id="application-name" value="{{.App.Name}}" name="application_name" required> + </div> + <div class="field {{if .Err_RedirectURI}}error{{end}}"> + <label for="redirect-uri">{{.locale.Tr "settings.oauth2_redirect_uri"}}</label> + <input type="url" name="redirect_uri" value="{{.App.PrimaryRedirectURI}}" id="redirect-uri"> + </div> + <button class="ui green button"> + {{.locale.Tr "settings.save_application"}} + </button> + </form> + </div> +</div> diff --git a/templates/user/settings/applications_oauth2_list.tmpl b/templates/user/settings/applications_oauth2_list.tmpl new file mode 100644 index 0000000000..47d7ecfaa4 --- /dev/null +++ b/templates/user/settings/applications_oauth2_list.tmpl @@ -0,0 +1,55 @@ +<div class="ui attached segment"> + <div class="ui key list"> + <div class="item"> + {{.locale.Tr "settings.oauth2_application_create_description"}} + </div> + {{range $app := .Applications}} + <div class="item"> + <div class="right floated content"> + <a href="{{$.Link}}/oauth2/{{$app.ID}}" class="ui primary tiny button"> + {{svg "octicon-pencil" 16 "mr-2"}} + {{$.locale.Tr "settings.oauth2_application_edit"}} + </a> + <button class="ui red tiny button delete-button" data-modal-id="remove-gitea-oauth2-application" + data-url="{{$.Link}}/oauth2/{{$app.ID}}/delete"> + {{svg "octicon-trash" 16 "mr-2"}} + {{$.locale.Tr "settings.delete_key"}} + </button> + </div> + <div class="content"> + <strong>{{$app.Name}}</strong> + </div> + </div> + {{end}} + </div> +</div> +<div class="ui attached bottom segment"> + <h5 class="ui top header"> + {{.locale.Tr "settings.create_oauth2_application"}} + </h5> + <form class="ui form ignore-dirty" action="{{.Link}}/oauth2" method="post"> + {{.CsrfTokenHtml}} + <div class="field {{if .Err_AppName}}error{{end}}"> + <label for="application-name">{{.locale.Tr "settings.oauth2_application_name"}}</label> + <input id="application-name" name="application_name" value="{{.application_name}}" required> + </div> + <div class="field {{if .Err_RedirectURI}}error{{end}}"> + <label for="redirect-uri">{{.locale.Tr "settings.oauth2_redirect_uri"}}</label> + <input type="url" name="redirect_uri" id="redirect-uri"> + </div> + <button class="ui green button"> + {{.locale.Tr "settings.create_oauth2_application_button"}} + </button> + </form> +</div> + +<div class="ui small basic delete modal" id="remove-gitea-oauth2-application"> + <div class="ui icon header"> + {{svg "octicon-trash"}} + {{.locale.Tr "settings.remove_oauth2_application"}} + </div> + <div class="content"> + <p>{{.locale.Tr "settings.oauth2_application_remove_description"}}</p> + </div> + {{template "base/delete_modal_actions" .}} +</div> diff --git a/templates/user/settings/grants_oauth2.tmpl b/templates/user/settings/grants_oauth2.tmpl index 40432c729b..e67fd2d222 100644 --- a/templates/user/settings/grants_oauth2.tmpl +++ b/templates/user/settings/grants_oauth2.tmpl @@ -10,8 +10,7 @@ <div class="item"> <div class="right floated content"> <button class="ui red tiny button delete-button" data-modal-id="revoke-gitea-oauth2-grant" - data-url="{{AppSubUrl}}/user/settings/applications/oauth2/revoke" - data-id="{{$grant.ID}}"> + data-url="{{AppSubUrl}}/user/settings/applications/oauth2/{{$grant.ApplicationID}}/revoke/{{$grant.ID}}"> {{$.locale.Tr "settings.revoke_key"}} </button> </div> |