Merge "Fixed scope edition"

This commit is contained in:
Jenkins 2017-02-14 19:12:14 +00:00 committed by Gerrit Code Review
commit e3d54eec1d
4 changed files with 27 additions and 1 deletions

View File

@ -70,4 +70,15 @@ final class CacheApiScopeRepository extends BaseCacheRepository implements IApiS
return $this->repository->getAssignableByGroups();
});
}
/**
* @param string $scope_name
* @return IApiScope
*/
public function getFirstByName($scope_name)
{
return Cache::remember($this->cache_base_key.'_'.$scope_name, $this->cache_minutes_lifetime, function() use($scope_name) {
return $this->repository->getFirstByName($scope_name);
});
}
}

View File

@ -69,4 +69,13 @@ final class EloquentApiScopeRepository extends AbstractEloquentEntityRepository
->where('assigned_by_groups', '=', true)
->orderBy('api_id')->get();
}
/**
* @param string $scope_name
* @return IApiScope
*/
public function getFirstByName($scope_name)
{
return $this->entity->where('active', '=', true)->where('name', $scope_name)->first();
}
}

View File

@ -160,7 +160,7 @@ final class ApiScopeService implements IApiScopeService
if ($param == 'name') {
//check if we have a former scope with selected name
$former_scope = $this->repository->getByName($params[$param]);
$former_scope = $this->repository->getFirstByName($params[$param]);
if (!is_null($former_scope) && $former_scope->id != $id) {
throw new InvalidApiScope(sprintf('scope name %s already exists!', $params[$param]));

View File

@ -25,6 +25,12 @@ interface IApiScopeRepository extends IBaseRepository
*/
public function getByName(array $scopes_names);
/**
* @param string $scope_name
* @return IApiScope
*/
public function getFirstByName($scope_name);
/**
* @return IApiScope[]
*/