mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-04 02:04:11 +01:00 
			
		
		
		
	Add note to GPG key response if user has no keys (#18961)
* Prevent invalid key response. * Display note instead of 404 response. * Fixed test. Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
		
							parent
							
								
									df9802ca61
								
							
						
					
					
						commit
						f8898c30dc
					
				@ -121,6 +121,7 @@ func TestExportUserGPGKeys(t *testing.T) {
 | 
			
		||||
	defer prepareTestEnv(t)()
 | 
			
		||||
	// Export empty key list
 | 
			
		||||
	testExportUserGPGKeys(t, "user1", `-----BEGIN PGP PUBLIC KEY BLOCK-----
 | 
			
		||||
Note: This user hasn't uploaded any GPG keys.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
=twTO
 | 
			
		||||
 | 
			
		||||
@ -736,6 +736,7 @@ func ShowGPGKeys(ctx *context.Context, uid int64) {
 | 
			
		||||
		ctx.ServerError("ListGPGKeys", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	entities := make([]*openpgp.Entity, 0)
 | 
			
		||||
	failedEntitiesID := make([]string, 0)
 | 
			
		||||
	for _, k := range keys {
 | 
			
		||||
@ -755,6 +756,8 @@ func ShowGPGKeys(ctx *context.Context, uid int64) {
 | 
			
		||||
	headers := make(map[string]string)
 | 
			
		||||
	if len(failedEntitiesID) > 0 { // If some key need re-import to be exported
 | 
			
		||||
		headers["Note"] = fmt.Sprintf("The keys with the following IDs couldn't be exported and need to be reuploaded %s", strings.Join(failedEntitiesID, ", "))
 | 
			
		||||
	} else if len(entities) == 0 {
 | 
			
		||||
		headers["Note"] = "This user hasn't uploaded any GPG keys."
 | 
			
		||||
	}
 | 
			
		||||
	writer, _ := armor.Encode(&buf, "PGP PUBLIC KEY BLOCK", headers)
 | 
			
		||||
	for _, e := range entities {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user