Skip to content

Commit

Permalink
Fix set key permissions as owner (#3604)
Browse files Browse the repository at this point in the history
* Fix set key permissions as owner

* improvement
  • Loading branch information
mauretto78 authored Oct 15, 2024
1 parent d9da8aa commit 1546604
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/Controller/updateJobKeysController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use TmKeyManagement\UserKeysModel;

/**
* Created by PhpStorm.
* User: roberto
Expand Down Expand Up @@ -99,10 +101,10 @@ function doAction() {

// moved here because self::isRevision() in constructor
// generates an infinite loop
if ( self::isRevision() ) {
$this->userRole = TmKeyManagement_Filter::ROLE_REVISOR;
} elseif ( $this->user->email == $this->jobData[ 'owner' ] ) {
if ( $this->user->email == $this->jobData[ 'owner' ] ) {
$this->userRole = TmKeyManagement_Filter::OWNER;
} elseif ( self::isRevision() ) {
$this->userRole = TmKeyManagement_Filter::ROLE_REVISOR;
}

//if some error occured, stop execution.
Expand Down Expand Up @@ -165,11 +167,23 @@ function doAction() {
*/
$tm_keys = json_decode( $this->tm_keys, true );

$clientKeys = $this->jobData->getClientKeys($this->user, $this->userRole);

/*
* sanitize owner role key type
*/
foreach ( $tm_keys[ 'mine' ] as $k => $val ) {
$tm_keys[ 'mine' ][ $k ][ 'owner' ] = ( $this->userRole == TmKeyManagement_Filter::OWNER );

// check if logged user is owner of $val['key']
$check = array_filter($clientKeys['job_keys'], function (TmKeyManagement_ClientTmKeyStruct $element) use ($val){
if($element->isEncryptedKey()){
return false;
}

return $val['key'] === $element->key;
});

$tm_keys[ 'mine' ][ $k ][ 'owner' ] = !empty($check);
}

$tm_keys = array_merge( $tm_keys[ 'ownergroup' ], $tm_keys[ 'mine' ], $tm_keys[ 'anonymous' ] );
Expand Down

0 comments on commit 1546604

Please sign in to comment.