|
|
@@ -6,20 +6,29 @@ Lib::loadClass('Api_WfsNs');
|
|
|
class Relations {
|
|
|
|
|
|
static function isAllowedToCreateRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
|
|
|
+ DBG::log("TODO: Relations::isAllowedToCreateRelation()...");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
static function isAllowedToGetRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
|
|
|
- return false;
|
|
|
+ if ($userLogin !== User::getLogin()) throw new Exception("Not Implemented - isAllowedToGetRelation for another user");
|
|
|
+ $acl = ACL::getAclByNamespace( Api_WfsNs::toNamespace($typeName) );
|
|
|
+ if (!$acl->hasField($remoteTypeName)) throw new Exception("Missing field in given object. Field '{$remoteTypeName}' not exists in '{$typeName}'");
|
|
|
+ if (!$acl->canReadField($remoteTypeName)) throw new HttpException("Forbidden reading relations from {$typeName} to {$remoteTypeName} ", 403);
|
|
|
+ $item = $acl->getItem($primaryKey);
|
|
|
+ if (!$item) throw new HttpException("Object not found {$typeName}.{$primaryKey}", 404);
|
|
|
+ if (!$acl->canReadObjectField($remoteTypeName, $item)) throw new HttpException("Forbidden reading relations from {$typeName}.{$primaryKey} to {$remoteTypeName} ", 403);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
static function isAllowedToDeleteRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
|
|
|
+ DBG::log("TODO: Relations::isAllowedToDeleteRelation()...");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- static function getRelations($typeName, $primaryKey) {
|
|
|
- $acl = ACL::getAclByNamespace( Api_WfsNs::toNamespace($typeName) );
|
|
|
- throw new Exception("TODO: Relations::getRelations");
|
|
|
+ static function getRelations($typeName, $primaryKey, $remoteTypeName) {
|
|
|
+ $namespace = Api_WfsNs::toNamespace($typeName);
|
|
|
+ return ACL::fetchRefs($namespace, $primaryKey, $remoteTypeName);
|
|
|
}
|
|
|
|
|
|
static function createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys) {
|
|
|
@@ -29,7 +38,7 @@ class Relations {
|
|
|
|
|
|
static function deleteRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys) {
|
|
|
$acl = ACL::getAclByNamespace( Api_WfsNs::toNamespace($typeName) );
|
|
|
- throw new Exception("TODO: Relations::getRelations");
|
|
|
+ throw new Exception("TODO: Relations::deleteRelations");
|
|
|
}
|
|
|
|
|
|
}
|