177 instance.delete
This commit is contained in:
@@ -427,6 +427,78 @@
|
||||
<cfreturn noData().withStatus(204, "No Content") />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="delete" hint="Удаление экземпляра сервиса по ключу. Допускается в статусе not configured">
|
||||
<cfargument name="instanceUid" type="string" required=true hint="type:guid"/>
|
||||
|
||||
<cftry>
|
||||
<cfset this.helper.validateField(arguments, "instanceUid", "guid")/>
|
||||
|
||||
<cfcatch type="invalidParamValue">
|
||||
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
|
||||
<cfset local={}/>
|
||||
<cftry>
|
||||
|
||||
<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 or does not exist",
|
||||
"Instance is not accessible for the current user (possibly does not belong to the default specification)")
|
||||
).withStatus(404)/>
|
||||
</cfif>
|
||||
|
||||
<!--- халява какая-то --->
|
||||
<cfquery name="local.qCheckOperation" result="local.result">
|
||||
select count(*) as cnt
|
||||
from instance_operation io
|
||||
where io.dt_finish IS NULL AND
|
||||
io.submit_result like '2%' /*201 etc*/ AND
|
||||
io.instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" null=#!isValid('guid',arguments.instanceUid)#/>
|
||||
</cfquery>
|
||||
<cfif local.qCheckOperation.cnt GT 0>
|
||||
<cfreturn representationOf(this.helper.formatMessage(
|
||||
"Operation already started", "Instance deletion disabled when operation is started")
|
||||
).withStatus(422)/>
|
||||
</cfif>
|
||||
|
||||
<cfquery name="local.qCheckState" result="local.result">
|
||||
select count(*) as cnt
|
||||
from instance_state st
|
||||
where
|
||||
st.instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" null=#!isValid('guid',arguments.instanceUid)#/>
|
||||
</cfquery>
|
||||
<cfif local.qCheckState.cnt GT 0>
|
||||
<cfreturn representationOf(this.helper.formatMessage(
|
||||
"Instance has a state", "Instance deletion disabled when having state")
|
||||
).withStatus(422)/>
|
||||
</cfif>
|
||||
|
||||
<!--- мы не включаем проверку доступа в саму операцию удаления, а выполняем отдельно --->
|
||||
<cfquery name="local.qSave">
|
||||
delete from instance_state
|
||||
where instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" null=#!isValid('guid',arguments.instanceUid)#/>;
|
||||
delete from instance_operation
|
||||
where instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" null=#!isValid('guid',arguments.instanceUid)#/>;
|
||||
delete from instance
|
||||
where instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" null=#!isValid('guid',arguments.instanceUid)#/>;
|
||||
</cfquery>
|
||||
|
||||
<cfcatch type="any">
|
||||
<cfreturn representationOf(this.helper.formatException(cfcatch, "Internal Error")).withStatus(500)/><!--- это не нужно показывать в продуктиве --->
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
|
||||
<cfreturn noData().withStatus(204, "No Content") />
|
||||
</cffunction><!--- delete --->
|
||||
|
||||
|
||||
|
||||
<!--- неудобно бегать из одного компонента в соседний при том, что разделение ответственности между ними получается довольно странное
|
||||
|
||||
Reference in New Issue
Block a user