Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide add key button if SSH is disabled #2873

Merged
merged 3 commits into from
Nov 21, 2017
Merged

Hide add key button if SSH is disabled #2873

merged 3 commits into from
Nov 21, 2017

Conversation

michaelkuhn
Copy link
Contributor

I have configured our Gitea instance with disabled SSH. However, the settings UI still shows an "Add Key" button but trying to add a key produces an error stating that SSH is disabled. A few users have already contacted me whether something is broken.

This PR simply hides the button if SSH is disabled. Alternatively, there could be some descriptive text stating that it is not possible to add SSH keys because SSH is disabled or the whole SSH key section could be hidden.

@codecov-io
Copy link

codecov-io commented Nov 7, 2017

Codecov Report

Merging #2873 into master will decrease coverage by 0.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2873      +/-   ##
==========================================
- Coverage   27.26%   27.24%   -0.02%     
==========================================
  Files          89       89              
  Lines       17640    17648       +8     
==========================================
  Hits         4809     4809              
- Misses      12144    12152       +8     
  Partials      687      687
Impacted Files Coverage Δ
models/error.go 18.62% <0%> (-0.31%) ⬇️
routers/user/setting.go 0% <0%> (ø) ⬆️
models/ssh_key.go 10.6% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1f7aab6...55fa973. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 7, 2017
@lafriks lafriks added the type/enhancement An improvement of existing functionality label Nov 7, 2017
@lafriks lafriks modified the milestones: 1.3.0, 1.x.x Nov 7, 2017
@lafriks
Copy link
Member

lafriks commented Nov 7, 2017

Can you please add also message that states that adding new keys is not allowed because SSH is disabled?

@@ -1,8 +1,10 @@
<h4 class="ui top attached header">
{{.i18n.Tr "settings.manage_ssh_keys"}}
{{if not .DisableSSH}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also hide this entire tab TBH. Or at least should a warning here that SSH is disabled 🙂

@michaelkuhn
Copy link
Contributor Author

Thanks for the feedback! I have updated the PR as follows:

  • Introduce a new string for "SSH is disabled" (not sure if this is the right way)
  • Instead of hiding the button, I now disable it and show an appropriate message
  • Use the new string for the error message in CheckPublicKeyString
  • Also disable the add deploy key button in repo settings

@@ -87,7 +87,7 @@ func HandleAddKeyError(ctx *context.APIContext, err error) {
// CreateDeployKey create deploy key for a repository
// see https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#add-a-new-deploy-key
func CreateDeployKey(ctx *context.APIContext, form api.CreateKeyOption) {
content, err := models.CheckPublicKeyString(form.Key)
content, err := models.CheckPublicKeyString(form.Key, ctx.Locale.Language())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be better to not pass context to CheckPublicKeyString and hanled the error inside HandleCheckKeyStringError.

@@ -543,7 +544,7 @@ func DeployKeysPost(ctx *context.Context, form auth.AddKeyForm) {
return
}

content, err := models.CheckPublicKeyString(form.Content)
content, err := models.CheckPublicKeyString(form.Content, ctx.Locale.Language())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Echoing sapk's comment from above, it would be better to have CheckPublicKeyString return a special type of error (say ErrSSHDisabled) when SSH is disabled, which we can check after calling the function (like we currently do for ErrKeyUnableVerify on line 549).

@michaelkuhn
Copy link
Contributor Author

I have updated the PR with the suggestions above:

  • Introduced a new error ErrSSHDisabled.
  • Check for the error in HandleCheckKeyStringError, DeployKeysPost and SettingsKeysPost. Within the Post functions, I had to move the Redirect and return out of the else branch, otherwise I got an internal server error.

@lafriks lafriks modified the milestones: 1.x.x, 1.4.0 Nov 20, 2017
@lafriks
Copy link
Member

lafriks commented Nov 20, 2017

LGTM as test failure does not seem related to this PR

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 20, 2017
@ethantkoenig
Copy link
Member

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Nov 21, 2017
@lunny lunny merged commit 420fc8e into go-gitea:master Nov 21, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants