mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	- Backport #19443 - Add a return for the first "block" of errors, which fixes the double error messages. - Add a return for `externallyManaged`. - Resolves #19398 Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
		@@ -266,16 +266,21 @@ func DeletePublicKey(ctx *context.APIContext) {
 | 
				
			|||||||
	id := ctx.ParamsInt64(":id")
 | 
						id := ctx.ParamsInt64(":id")
 | 
				
			||||||
	externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(id)
 | 
						externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
 | 
							if asymkey_model.IsErrKeyNotExist(err) {
 | 
				
			||||||
 | 
								ctx.NotFound()
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if externallyManaged {
 | 
						if externallyManaged {
 | 
				
			||||||
		ctx.Error(http.StatusForbidden, "", "SSH Key is externally managed for this user")
 | 
							ctx.Error(http.StatusForbidden, "", "SSH Key is externally managed for this user")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := asymkey_service.DeletePublicKey(ctx.User, id); err != nil {
 | 
						if err := asymkey_service.DeletePublicKey(ctx.User, id); err != nil {
 | 
				
			||||||
		if asymkey_model.IsErrKeyNotExist(err) {
 | 
							if asymkey_model.IsErrKeyAccessDenied(err) {
 | 
				
			||||||
			ctx.NotFound()
 | 
					 | 
				
			||||||
		} else if asymkey_model.IsErrKeyAccessDenied(err) {
 | 
					 | 
				
			||||||
			ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
 | 
								ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			ctx.Error(http.StatusInternalServerError, "DeletePublicKey", err)
 | 
								ctx.Error(http.StatusInternalServerError, "DeletePublicKey", err)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user