Skip to content
Snippets Groups Projects
Commit b52ccff0 authored by S.Listl's avatar S.Listl
Browse files

GrantDelete processes changed

parent 0c2eca79
No related branches found
No related tags found
No related merge requests found
Showing
with 79 additions and 18 deletions
......@@ -4,6 +4,7 @@
<majorModelMode>DISTRIBUTED</majorModelMode>
<documentation>%aditoprj%/entity/Attribute_entity/documentation.adoc</documentation>
<title>Attribute</title>
<grantDeleteProcess>%aditoprj%/entity/Attribute_entity/grantDeleteProcess.js</grantDeleteProcess>
<contentTitleProcess>%aditoprj%/entity/Attribute_entity/contentTitleProcess.js</contentTitleProcess>
<afterUiInit>%aditoprj%/entity/Attribute_entity/afterUiInit.js</afterUiInit>
<onValidation>%aditoprj%/entity/Attribute_entity/onValidation.js</onValidation>
......
import("system.result");
import("Attribute_lib");
import("system.vars");
import("Sql_lib");
import("Entity_lib");
var attributeId = vars.get("$field.UID");
var childCountSql = newSelect("count(*)")
.from("AB_ATTRIBUTE")
.where("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", attributeId);
var canDelete = new HasLinkedObjectTester()
.andSqlYieldsZero(childCountSql)
.and(function () {return !AttributeUtil.hasRelations(attributeId);})
.validate();
result.string(canDelete);
\ No newline at end of file
......@@ -363,7 +363,6 @@
<name>jdito</name>
<jDitoRecordAlias>Data_alias</jDitoRecordAlias>
<isFilterable v="true" />
<isRequireContainerFiltering v="true" />
<isSortable v="true" />
<contentProcess>%aditoprj%/entity/Employee_entity/recordcontainers/jdito/contentProcess.js</contentProcess>
<onInsert>%aditoprj%/entity/Employee_entity/recordcontainers/jdito/onInsert.js</onInsert>
......
import("Entity_lib");
import("Employee_lib");
import("Document_lib");
import("system.vars");
import("system.result");
var res = false;
var userTitle = vars.get("$field.TITLE");
var userId = vars.get("$field.UID");
var contactId = vars.get("$field.CONTACT_ID");
//the current user should not delete himself
if (EmployeeUtils.getCurrentUserName() != vars.get("$field.TITLE")
&& !EmployeeUtils.hasRelations(vars.get("$field.CONTACT_ID"))
&& !DocumentUtil.hasDocuments("EMPLOYEE", null, EmployeeUtils.sliceUserId(vars.get("$field.UID")))
)
{
res = true;
}
var canDelete = new HasLinkedObjectTester()
.and(function () {return EmployeeUtils.getCurrentUserName() != userTitle;})
.and(function () {return !EmployeeUtils.hasRelations(contactId);})
.andNoEntityRows("Document_entity", "Documents", {AssignmentTable_param : "EMPLOYEE", AssignmentRowId_param : userId})
.validate();
result.string(res);
\ No newline at end of file
result.string(canDelete);
\ No newline at end of file
import("system.logging");
import("Sql_lib");
import("system.db");
import("Attribute_lib");
......@@ -8,7 +7,7 @@ import("system.tools");
import("Util_lib");
import("Contact_lib");
import("JditoFilter_lib");
import("Employee_lib");attrib
import("Employee_lib");
var users;
if (vars.exists("$local.idvalues") && vars.get("$local.idvalues"))
......@@ -68,15 +67,19 @@ var filterFns = {
{
if (pOperator == "CONTAINS")
{
return pRow.some(function (fieldValue)
pRow = [pRow[1], pRow[3], pRow[4], pRow[5]];
var filterValues = pFilterValue.split(" ").filter(function (val) {return val.trim();});
return filterValues.every(function (filterValue)
{
return (new RegExp(pFilterValue, "i")).test(fieldValue);
return pRow.some(function (fieldValue)
{
return (new RegExp(filterValue, "i")).test(fieldValue);
});
});
}
return false;
}
};
logging.log(JSON.stringify(filter, null, "\t"))
users = JditoFilterUtils.filterRecords(filterFields, users, filter.filter, filterFns);
users.forEach(function (user) {user[12] = "";}); //clean up the ROLE_FILTER field, we don't need it after filtering
......
......@@ -15,6 +15,7 @@ var canDelete = new HasLinkedObjectTester()
.andNoEntityRows("Salesproject_entity", "Salesprojects", {ContactId_param : contactId}) //Salesprojects
.andNoEntityRows("Offer_entity", "ContactOffers", {ContactId_param : contactId}) //Offers
.andNoEntityRows("Contract_entity", "Contracts", {ContactId_param : contactId}) //Contracts
.andNoEntityRows("ObjectTree_entity", "TreeProvider", {ObjectIds_param : JSON.stringify([contactId]), ObjectTypes_param : JSON.stringify([currentContext])}) //ObjectTrees
.validate();
result.string(canDelete);
\ No newline at end of file
import("Sql_lib");
import("Context_lib");
import("Workflow_lib");
import("system.vars");
......@@ -11,5 +12,9 @@ DuplicateScannerUtils.DeleteCachedDuplicate(contactId);
new AttributeRelationQuery(contactId, null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
newWhere("COMMUNICATION.CONTACT_ID", contactId).deleteData();
newWhere("ADDRESS.CONTACT_ID", contactId).deleteData();
newWhere("COMMRESTRICTION.CONTACT_ID", contactId).deleteData();
//WorkflowStarter.deleted();
//WorkflowSignalSender.deleted();
\ No newline at end of file
......@@ -14,6 +14,7 @@ var canDelete = new HasLinkedObjectTester()
.and(function () {return !EmployeeUtils.isUser(contactId);})
.andNoEntityRows("Offer_entity", "ContactOffers", {ContactId_param : contactId}) //Offers
.andNoEntityRows("Contract_entity", "Contracts", {ContactId_param : contactId}) //Contracts
.andNoEntityRows("ObjectTree_entity", "TreeProvider", {ObjectIds_param : JSON.stringify([contactId, vars.get("$field.PERSON_ID")]), ObjectTypes_param : JSON.stringify([currentContext, "PrivatePerson"])})
.validate();
result.string(canDelete);
import("Sql_lib");
import("Context_lib");
import("Attribute_lib");
import("Workflow_lib");
......@@ -10,5 +11,9 @@ DuplicateScannerUtils.DeleteCachedDuplicate(contactId);
new AttributeRelationQuery(contactId, null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
newWhere("COMMUNICATION.CONTACT_ID", contactId).deleteData();
newWhere("ADDRESS.CONTACT_ID", contactId).deleteData();
newWhere("COMMRESTRICTION.CONTACT_ID", contactId).deleteData();
//WorkflowStarter.deleted();
//WorkflowSignalSender.deleted();
\ No newline at end of file
......@@ -10,6 +10,7 @@ var canDelete = new HasLinkedObjectTester()
.andNoEntityRows("Activity_entity", "LinkedObjects", {ObjectId_param : currentContext, RowId_param : rowId}) //Activities
.andNoEntityRows("Task_entity", "Tasks", {ObjectId_param : currentContext, RowId_param : rowId}) //Tasks
.andNoEntityRows("Document_entity", "Documents", {AssignmentTable_param : "SALESPROJECT", AssignmentRowId_param : rowId}) //Documents
.andNoEntityRows("Timetracking_entity", "Timetrackings", {ObjectId_param : currentContext, RowId_param : rowId}) //Timetrackings
.validate();
result.string(canDelete);
\ No newline at end of file
......@@ -39,8 +39,6 @@ if (currentId)
db.deletes(toDelete);
// TODO: auch Dokumente, Aktivitäten, Aufgaben, Zeiterfassungen löschen?
}
new AttributeRelationQuery(currentId, null, ContextUtils.getCurrentContextId())
......
......@@ -3,6 +3,7 @@ import("system.entities");
import("system.result");
import("system.neon");
import("system.vars");
import("Sql_lib");
/**
* provides static methods for special handling of entities in JDito-Processes
......@@ -237,6 +238,15 @@ HasLinkedObjectTester._testForCallback = function ()
: fnResult;
}
/**
* @ignore
*/
HasLinkedObjectTester._testForSqlCount = function ()
{
//also works for empty string because Number("") returns 0
return Number(this.sqlQuery.cell()) === 0;
}
/**
* !!! YOU CAN'T USE THIS FUNCTION YET !!!
*
......@@ -301,6 +311,25 @@ HasLinkedObjectTester.prototype.and = function (pCallbackFn, pFailValue)
return this;
}
/**
* Adds a SqlBuilder object to the validation that should return a single number (e. g. "select count(*) ..."). If the result of the SQL is not 0,
* the overall validation will return false.
*
* @param {SqlBuilder} pSqlQuery the SqlBuilder object, the SQL will be executed with SqlBuilder.prototype.cell() and is expected to result in a number
* @return {HasLinkedObjectTester} current object
*/
HasLinkedObjectTester.prototype.andSqlYieldsZero = function (pSqlQuery)
{
if (!(pSqlQuery instanceof SqlBuilder))
throw new TypeError(translate.text("pSqlQuery must be of type SqlBuilder"));
this._validationObjects.push({
checkForObjects : HasLinkedObjectTester._testForSqlCount,
sqlQuery : pSqlQuery
});
return this;
}
/**
* Executes the validation of all tests that have been added to the object. If every test returns true, the result will also be true,
* but if any test returns false, the execution will stop and false is returned.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment