|
@@ -6,8 +6,14 @@ Lib::loadClass('Api_WfsNs');
|
|
|
class Relations {
|
|
class Relations {
|
|
|
|
|
|
|
|
static function isAllowedToCreateRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
|
|
static function isAllowedToCreateRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
|
|
|
- DBG::log("TODO: Relations::isAllowedToCreateRelation()...");
|
|
|
|
|
- return false;
|
|
|
|
|
|
|
+ if ($userLogin !== User::getLogin()) throw new Exception("Not Implemented - isAllowedToCreateRelation 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->canCreateField($remoteTypeName)) throw new HttpException("Forbidden create relations from {$typeName} to {$remoteTypeName} ", 403);
|
|
|
|
|
+ $item = $acl->getItem($primaryKey);
|
|
|
|
|
+ if (!$item) throw new HttpException("Object not found {$typeName}.{$primaryKey}", 404);
|
|
|
|
|
+ if (!$acl->canWriteObjectField($remoteTypeName, $item)) throw new HttpException("Forbidden create relations from {$typeName}.{$primaryKey} to {$remoteTypeName} ", 403);
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static function isAllowedToGetRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
|
|
static function isAllowedToGetRelation($userLogin, $typeName, $primaryKey, $remoteTypeName) {
|
|
@@ -32,13 +38,15 @@ class Relations {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static function createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys) {
|
|
static function createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys) {
|
|
|
- $acl = ACL::getAclByNamespace( Api_WfsNs::toNamespace($typeName) );
|
|
|
|
|
- throw new Exception("TODO: Relations::createRelation");
|
|
|
|
|
|
|
+ $namespace = Api_WfsNs::toNamespace($typeName);
|
|
|
|
|
+ $acl = ACL::getAclByNamespace($namespace);
|
|
|
|
|
+ ACL::addListRef($namespace, $remoteTypeName, $primaryKey, $listRemotePrimaryKeys);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static function deleteRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys) {
|
|
static function deleteRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys) {
|
|
|
- $acl = ACL::getAclByNamespace( Api_WfsNs::toNamespace($typeName) );
|
|
|
|
|
- throw new Exception("TODO: Relations::deleteRelations");
|
|
|
|
|
|
|
+ $namespace = Api_WfsNs::toNamespace($typeName);
|
|
|
|
|
+ $acl = ACL::getAclByNamespace($namespace);
|
|
|
|
|
+ ACL::removeListRef($namespace, $remoteTypeName, $primaryKey, $listRemotePrimaryKeys);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|