144 specification_id checks

This commit is contained in:
msyu
2025-09-24 14:09:14 +03:00
parent f96659f31d
commit 93453fec88
6 changed files with 89 additions and 7 deletions
+1 -1
View File
@@ -51,7 +51,7 @@
//variables.framework.docs={}; //variables.framework.docs={};
variables.framework.docs.APIName="svc-api"; variables.framework.docs.APIName="svc-api";
variables.framework.docs.APIVersion="0.144"; /*auth_header*/ /*$ git config --global --unset user.password*/ variables.framework.docs.APIVersion="0.145"; /*$ git config --global --unset user.password*/
variables.framework.globalHeaders = structNew(); variables.framework.globalHeaders = structNew();
variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location"; variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location";
+2 -1
View File
@@ -275,7 +275,8 @@
order by sop.sort, p.param order by sop.sort, p.param
</cfquery> </cfquery>
<!--- *** здесь уместна параноидальная проверка прав ---> <!--- *** здесь уместна параноидальная проверка прав
потому что можно сослаться на чужой инстанс и увидеть какие-то лишние детали--->
<cfquery name="local.qDependentInstance"> <cfquery name="local.qDependentInstance">
select select
<m:field_set titleMapOut="local.dependentInstanceTitleMap" lengthOut="local.fieldCount"> <m:field_set titleMapOut="local.dependentInstanceTitleMap" lengthOut="local.fieldCount">
@@ -3,6 +3,18 @@
В данном случае никакого смысла смотреть на все CFS параметры нет, только в рамках операции В данном случае никакого смысла смотреть на все CFS параметры нет, только в рамках операции
Но: мы не хотели бы менять положение сущности в дереве. Либо она в корне, либо она ниже. И получится, когда мы выбираем один параметр, нам ни к чему контекст - мы к нему однозначно адресуемся. Но: мы не хотели бы менять положение сущности в дереве. Либо она в корне, либо она ниже. И получится, когда мы выбираем один параметр, нам ни к чему контекст - мы к нему однозначно адресуемся.
Проголосуем за отсутстие избыточности? Проголосуем за отсутстие избыточности?
--->
<!--- Все методы неявно получают
arguments.usrId
arguments.contragentId
arguments.contractId
arguments.specificationId
arguments.requestArguments.usrId=usrCustomerInfo.usrId; //Integer!
arguments.requestArguments.contragentId=usrCustomerInfo.contragentId; //Integer
arguments.requestArguments.contractId=usrCustomerInfo.contractId; //Integer
arguments.requestArguments.specificationId=usrCustomerInfo.specificationId; //Integer
---> --->
<cfsilent> <cfsilent>
@@ -118,6 +130,31 @@
<cfreturn representationOf(this.helper.formatMessage("Operation already started", "Parameter deletion disabled for started operation")).withStatus(422)/> <cfreturn representationOf(this.helper.formatMessage("Operation already started", "Parameter deletion disabled for started operation")).withStatus(422)/>
</cfif> </cfif>
<!--- <cfquery name="local.qCheckSpecification" result="local.result">
select si.specification_id
from instance_operation_cfs_param iop
join instance_operation io on iop.instance_operation_uid=io.instance_operation_uid
join instance e on (io.instance_uid=e.instance_uid)
left outer join specification_item si on (e.specification_item_id=si.specification_item_id)
where iop.instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/>
AND si.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/>
</cfquery>
<cfif local.qCheckSpecification.recordCount EQ 0>
<cfreturn representationOf(this.helper.formatMessage("Instance not accessible", "Instance does not belong to the current specification, contract or contragent")).withStatus(403)/>
</cfif> --->
<cfquery name="local.qCheckAccess" result="local.result">
select count(*) as cnt
from instance_operation_cfs_param iop
join instance_operation io on (iop.instance_operation_uid=io.instance_operation_uid)
join instance e on (io.instance_uid=e.instance_uid)
join specification_item si on (e.specification_item_id=si.specification_item_id)
where iop.instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/>
AND si.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/>
</cfquery>
<cfif local.qCheckAccess.cnt EQ 0>
<cfreturn representationOf(this.helper.formatMessage("Instance not accessible", "Instance of this CFS parameter is not accessible to the current user (at least does not belong to the default specification)")).withStatus(403)/>
</cfif>
<cfquery name="local.qSave"> <cfquery name="local.qSave">
delete from instance_operation_cfs_param delete from instance_operation_cfs_param
where instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/> where instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/>
@@ -3,6 +3,20 @@
В данном случае никакого смысла смотреть на все CFS параметры нет, только в рамках операции В данном случае никакого смысла смотреть на все CFS параметры нет, только в рамках операции
Но: мы не хотели бы менять положение сущности в дереве. Либо она в корне, либо она ниже. И получится, когда мы выбираем один параметр, нам ни к чему контекст - мы к нему однозначно адресуемся. Но: мы не хотели бы менять положение сущности в дереве. Либо она в корне, либо она ниже. И получится, когда мы выбираем один параметр, нам ни к чему контекст - мы к нему однозначно адресуемся.
Проголосуем за отсутстие избыточности? Проголосуем за отсутстие избыточности?
--->
<!--- Проверять принадлежность инстанса текущему клиенту
При выборке CFS параметров проверятся принадлежность текущей спецификации пользователя
--->
<!--- Все методы неявно получают
arguments.usrId
arguments.contragentId
arguments.contractId
arguments.specificationId
arguments.requestArguments.usrId=usrCustomerInfo.usrId; //Integer!
arguments.requestArguments.contragentId=usrCustomerInfo.contragentId; //Integer
arguments.requestArguments.contractId=usrCustomerInfo.contractId; //Integer
arguments.requestArguments.specificationId=usrCustomerInfo.specificationId; //Integer
---> --->
<cfsilent> <cfsilent>
@@ -176,17 +190,22 @@
<!--- Проверка: параметр от нашего ли сервиса *** и операции ---> <!--- Проверка: параметр от нашего ли сервиса *** и операции --->
<cfquery name="local.qInstanceService" result="local.result"> <cfquery name="local.qInstanceService" result="local.result">
select e.service_id, io.operation select e.service_id, io.operation, si.specification_id
from instance_operation io from instance_operation io
join instance e on (io.instance_uid=e.instance_uid) join instance e on (io.instance_uid=e.instance_uid)
left outer join specification_item si on (e.specification_item_id=si.specification_item_id)
where io.instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationUid#"/> where io.instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationUid#"/>
</cfquery> </cfquery>
<cfquery name="local.qTemplateSvc" result="local.result"> <cfquery name="local.qTemplateSvc" result="local.result">
select so.svc_id, so.operation select so.svc_id, so.operation
from svc_operation_cfs_param sop from svc_operation_cfs_param sop
join svc_operation so on (sop.svc_operation_id=so.svc_operation_id) join svc_operation so on (sop.svc_operation_id=so.svc_operation_id)
where sop.svc_operation_cfs_param_id=<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.svcOperationCfsParamId#"/> where sop.svc_operation_cfs_param_id=<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.svcOperationCfsParamId#"/>
</cfquery> </cfquery>
<cfif local.qInstanceService.specification_id NEQ arguments.specificationId>
<cfreturn representationOf(this.helper.formatMessage("Instance not accessible", "Instance does not belong to the current specification, contract or contragent")).withStatus(403)/>
</cfif>
<cfif local.qInstanceService.service_id NEQ local.qTemplateSvc.svc_id> <cfif local.qInstanceService.service_id NEQ local.qTemplateSvc.svc_id>
<cfreturn representationOf(this.helper.formatMessage("Invalid CFS parameter", "Parameter specified does not belong to this service")).withStatus(400)/> <cfreturn representationOf(this.helper.formatMessage("Invalid CFS parameter", "Parameter specified does not belong to this service")).withStatus(400)/>
</cfif> </cfif>
+13
View File
@@ -28,6 +28,18 @@
<cfif local.qCheckOperation.cnt EQ 0> <cfif local.qCheckOperation.cnt EQ 0>
<cfthrow type="invalidParamValue" message="Operation unsupported for this service/instance" detail="#arguments.operation#"/> <cfthrow type="invalidParamValue" message="Operation unsupported for this service/instance" detail="#arguments.operation#"/>
</cfif> </cfif>
<cfquery name="local.qCheckAccess" result="local.result">
select count(*) as cnt
from instance e
join specification_item si on (e.specification_item_id=si.specification_item_id)
where e.instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" null=#!isValid('guid',arguments.instanceUid)#/>
AND si.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/>
</cfquery>
<cfif local.qCheckAccess.cnt EQ 0>
<!--- *** вместо выбрасывания исключения мы сразу прерываем выполнение метода --->
<cfreturn representationOf(this.helper.formatMessage("Instance not accessible", "Instance is not accessible to the current user (at least does not belong to the default specification)")).withStatus(403)/>
</cfif>
<!--- *** Добавить проверку разрешенных переходов, например, create нельзя сделать на развернутом экземпляре <!--- *** Добавить проверку разрешенных переходов, например, create нельзя сделать на развернутом экземпляре
*** Вероятно, допустимые переходы нужно либо специфицировать в документации, либо явно опубликовать (инстанс может публиковать список допустимых операций) ---> *** Вероятно, допустимые переходы нужно либо специфицировать в документации, либо явно опубликовать (инстанс может публиковать список допустимых операций) --->
@@ -70,6 +82,7 @@
/> />
</cffunction> </cffunction>
<!--- *** NOT USED --->
<cffunction name="checkResourceRealmId" returntype="void" hint="deprecated"> <cffunction name="checkResourceRealmId" returntype="void" hint="deprecated">
<!--- В данном случае мы проверяем соответствие платформы сервису, а не операции, поэтому вопрос, нужен ли для данной операции параметр resourceRealm, надо решать вне этой функции ---> <!--- В данном случае мы проверяем соответствие платформы сервису, а не операции, поэтому вопрос, нужен ли для данной операции параметр resourceRealm, надо решать вне этой функции --->
<cfargument name="resourceRealmId" type="numeric" required=true/> <cfargument name="resourceRealmId" type="numeric" required=true/>
+12
View File
@@ -22,6 +22,18 @@
<!---NOT NULL fields---> <!---NOT NULL fields--->
<cfset this.helper.keyExistsAndValid(arguments, "instanceOperationUid", "guid")/> <cfset this.helper.keyExistsAndValid(arguments, "instanceOperationUid", "guid")/>
<cfquery name="local.qCheckAccess" result="local.result">
select count(*) as cnt
from instance_operation io
join instance e on (io.instance_uid=e.instance_uid)
join specification_item si on (e.specification_item_id=si.specification_item_id)
where io.instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationUid#" null=#!isValid('guid',arguments.instanceOperationUid)#/>
AND si.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/>
</cfquery>
<cfif local.qCheckAccess.cnt EQ 0>
<cfreturn representationOf(this.helper.formatMessage("Instance not accessible", "Instance is not accessible to the current user (at least does not belong to the default specification)")).withStatus(403)/>
</cfif>
<cfquery name="local.qSvcOperation" result="local.result"> <cfquery name="local.qSvcOperation" result="local.result">
select io.operation, s.svc_id, so.svc_operation_id select io.operation, s.svc_id, so.svc_operation_id
from instance_operation io from instance_operation io