mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Fix comment permissions (#28213)
This PR will fix some missed checks for private repositories' data on web routes and API routes.
This commit is contained in:
		@@ -92,10 +92,9 @@ func CountUserGPGKeys(ctx context.Context, userID int64) (int64, error) {
 | 
			
		||||
	return db.GetEngine(ctx).Where("owner_id=? AND primary_key_id=''", userID).Count(&GPGKey{})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetGPGKeyByID returns public key by given ID.
 | 
			
		||||
func GetGPGKeyByID(ctx context.Context, keyID int64) (*GPGKey, error) {
 | 
			
		||||
func GetGPGKeyForUserByID(ctx context.Context, ownerID, keyID int64) (*GPGKey, error) {
 | 
			
		||||
	key := new(GPGKey)
 | 
			
		||||
	has, err := db.GetEngine(ctx).ID(keyID).Get(key)
 | 
			
		||||
	has, err := db.GetEngine(ctx).Where("id=? AND owner_id=?", keyID, ownerID).Get(key)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	} else if !has {
 | 
			
		||||
@@ -225,7 +224,7 @@ func deleteGPGKey(ctx context.Context, keyID string) (int64, error) {
 | 
			
		||||
 | 
			
		||||
// DeleteGPGKey deletes GPG key information in database.
 | 
			
		||||
func DeleteGPGKey(ctx context.Context, doer *user_model.User, id int64) (err error) {
 | 
			
		||||
	key, err := GetGPGKeyByID(ctx, id)
 | 
			
		||||
	key, err := GetGPGKeyForUserByID(ctx, doer.ID, id)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if IsErrGPGKeyNotExist(err) {
 | 
			
		||||
			return nil
 | 
			
		||||
@@ -233,11 +232,6 @@ func DeleteGPGKey(ctx context.Context, doer *user_model.User, id int64) (err err
 | 
			
		||||
		return fmt.Errorf("GetPublicKeyByID: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Check if user has access to delete this key.
 | 
			
		||||
	if !doer.IsAdmin && doer.ID != key.OwnerID {
 | 
			
		||||
		return ErrGPGKeyAccessDenied{doer.ID, key.ID}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ctx, committer, err := db.TxContext(ctx)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user