Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #621 from FlowzPlatform/permissionIssueResolve
Browse files Browse the repository at this point in the history
validation is not check if there is no write permission for field
  • Loading branch information
nikitam747 authored Oct 10, 2018
2 parents 7f14585 + c96050c commit 56dfcfa
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 80 deletions.
1 change: 0 additions & 1 deletion client/src/components/SchemaSubForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,6 @@ export default {
}
},
mounted () {
console.log('schemainstance', this.schemainstance)
// this.oldFiles = this.schemainstance.data[0].Fileattachment.length
},
created () {}
Expand Down
258 changes: 179 additions & 79 deletions client/src/components/SchemaView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,13 @@ export default {
this.validErr = []
let allcheck = []
this.bLoading = true
let currentStageP = this.$route.params.stateid
let currentStateP = this.flowzData.processList[currentStageP]
let permission = {}
permission = currentStateP.permission
console.log(permission)
for (let dobj of this.formSchemaInstance.data) {
let flag = this.checkValidation(dobj, this.entity)
let flag = this.checkValidation(dobj, this.entity, permission)
allcheck.push(flag)
}
this.check = _.indexOf(allcheck, false)
Expand Down Expand Up @@ -762,6 +767,10 @@ export default {
},
saveInstanceData () {
let currentStageP = this.$route.params.stateid
let currentStateP = this.flowzData.processList[currentStageP]
let permission = {}
permission = currentStateP.permission
let currentStateId = this.$route.params.stateid
if (this.schema.hasOwnProperty('emailSchema')) {
if (this.schema.emailSchema.action === true) {
Expand All @@ -784,7 +793,7 @@ export default {
this.validErr = []
let allcheck = []
for (let dobj of obj.data) {
let flag = this.checkValidation(dobj, this.entity)
let flag = this.checkValidation(dobj, this.entity, permission)
allcheck.push(flag)
}
this.check = _.indexOf(allcheck, false)
Expand Down Expand Up @@ -878,7 +887,7 @@ export default {
this.validErr = []
let allcheck = []
for (let dobj of obj.data) {
let flag = this.checkValidation(dobj, this.entity)
let flag = this.checkValidation(dobj, this.entity, permission)
allcheck.push(flag)
}
this.check = _.indexOf(allcheck, false)
Expand All @@ -894,7 +903,7 @@ export default {
this.validErr = []
let allcheck = []
for (let dobj of obj.data) {
let flag = this.checkValidation(dobj, this.entity)
let flag = this.checkValidation(dobj, this.entity, permission)
allcheck.push(flag)
}
this.check = _.indexOf(allcheck, false)
Expand Down Expand Up @@ -960,94 +969,185 @@ export default {
}
})
},
checkValidation (data, ent) {
checkValidation (data, ent, permission) {
let self = this
for (let v of ent) {
if (v.customtype) {
for (let d of data[v.name]) {
self.validFlag = self.checkValidation(d, v.entity[0].entity)
}
} else {
if (!v.property.optional) {
if (data[v.name] === '') {
self.validErr.push({name: v.name, errmsg: 'Field is required.'})
self.validFlag = false
} else if (Array.isArray(data[v.name]) && data[v.name].length === 0) {
self.validErr.push({name: v.name, errmsg: 'File is required.'})
self.validFlag = false
} else if (v.type === 'text') {
if (v.property.regEx !== '') {
let patt0 = v.property.regEx
let res0 = patt0.test(data[v.name])
if (!res0) {
self.validErr.push({name: v.name, errmsg: 'Invalid Email.'})
self.validFlag = false
}
} else if (v.property.max !== 0) {
if (data[v.name].length > v.property.max) {
self.validErr.push({name: v.name, errmsg: 'max ' + v.property.max + ' characters allowed.'})
self.validFlag = false
}
} else if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'})
self.validFlag = false
}
if (permission[v.name] !== undefined) {
if (permission[v.name].write || permission[v.name].read) {
if (v.customtype) {
for (let d of data[v.name]) {
self.validFlag = self.checkValidation(d, v.entity[0].entity, permission)
}
} else if (v.type === 'email' && data[v.name] !== '') {
let patt1 = (v.property.regEx === '') ? new RegExp('[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,3}$') : new RegExp(v.property.regEx)
let res1 = patt1.test(data[v.name])
if (!res1) {
self.validErr.push({name: v.name, errmsg: 'Invalid Email.'})
self.validFlag = false
} else if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'})
} else {
if (!v.property.optional) {
if (data[v.name] === '') {
self.validErr.push({name: v.name, errmsg: 'Field is required.'})
self.validFlag = false
}
}
} else if (v.type === 'phone') {
let patt2 = (v.property.regEx === '') ? new RegExp('^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$') : new RegExp(v.property.regEx)
let res2 = patt2.test(data[v.name])
if (!res2) {
self.validErr.push({name: v.name, errmsg: 'Invalid Phone.'})
self.validFlag = false
} else if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Phone, Please select allow one.'})
} else if (Array.isArray(data[v.name]) && data[v.name].length === 0) {
self.validErr.push({name: v.name, errmsg: 'File is required.'})
self.validFlag = false
} else if (v.type === 'text') {
if (v.property.regEx !== '') {
let patt0 = v.property.regEx
let res0 = patt0.test(data[v.name])
if (!res0) {
self.validErr.push({name: v.name, errmsg: 'Invalid Email.'})
self.validFlag = false
}
} else if (v.property.max !== 0) {
if (data[v.name].length > v.property.max) {
self.validErr.push({name: v.name, errmsg: 'max ' + v.property.max + ' characters allowed.'})
self.validFlag = false
}
} else if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'})
self.validFlag = false
}
}
} else if (v.type === 'email' && data[v.name] !== '') {
let patt1 = (v.property.regEx === '') ? new RegExp('[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,3}$') : new RegExp(v.property.regEx)
let res1 = patt1.test(data[v.name])
if (!res1) {
self.validErr.push({name: v.name, errmsg: 'Invalid Email.'})
self.validFlag = false
} else if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'})
self.validFlag = false
}
}
} else if (v.type === 'phone') {
let patt2 = (v.property.regEx === '') ? new RegExp('^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$') : new RegExp(v.property.regEx)
let res2 = patt2.test(data[v.name])
if (!res2) {
self.validErr.push({name: v.name, errmsg: 'Invalid Phone.'})
self.validFlag = false
} else if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Phone, Please select allow one.'})
self.validFlag = false
}
}
} else if (v.type === 'number') {
if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Number, Please select allow one.'})
self.validFlag = false
}
}
} else if (v.type === 'date') {
if (v.property.mindate !== '' && v.property.maxdate !== '') {
if (data[v.name] < v.property.mindate && data[v.name] > v.property.maxdate) {
self.validErr.push({name: v.name, errmsg: 'Date must in between ' + v.property.mindate + ' and ' + v.property.maxdate})
self.validFlag = false
}
} else if (v.property.mindate !== '') {
if (data[v.name] < v.property.mindate) {
self.validErr.push({name: v.name, errmsg: 'Date must be greater than or equal ' + v.property.mindate + '.'})
self.validFlag = false
}
} else if (v.property.maxdate !== '') {
if (data[v.name] > v.property.maxdate) {
self.validErr.push({name: v.name, errmsg: 'Date must be less than or equal ' + v.property.mindate + '.'})
self.validFlag = false
}
}
}
}
} else if (v.type === 'number') {
if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Number, Please select allow one.'})
self.validFlag = false
}
}
}
} else {
if (v.customtype) {
for (let d of data[v.name]) {
self.validFlag = self.checkValidation(d, v.entity[0].entity, permission)
}
} else if (v.type === 'date') {
if (v.property.mindate !== '' && v.property.maxdate !== '') {
if (data[v.name] < v.property.mindate && data[v.name] > v.property.maxdate) {
self.validErr.push({name: v.name, errmsg: 'Date must in between ' + v.property.mindate + ' and ' + v.property.maxdate})
} else {
if (!v.property.optional) {
if (data[v.name] === '') {
self.validErr.push({name: v.name, errmsg: 'Field is required.'})
self.validFlag = false
}
} else if (v.property.mindate !== '') {
if (data[v.name] < v.property.mindate) {
self.validErr.push({name: v.name, errmsg: 'Date must be greater than or equal ' + v.property.mindate + '.'})
self.validFlag = false
}
} else if (v.property.maxdate !== '') {
if (data[v.name] > v.property.maxdate) {
self.validErr.push({name: v.name, errmsg: 'Date must be less than or equal ' + v.property.mindate + '.'})
} else if (Array.isArray(data[v.name]) && data[v.name].length === 0) {
self.validErr.push({name: v.name, errmsg: 'File is required.'})
self.validFlag = false
} else if (v.type === 'text') {
if (v.property.regEx !== '') {
let patt0 = v.property.regEx
let res0 = patt0.test(data[v.name])
if (!res0) {
self.validErr.push({name: v.name, errmsg: 'Invalid Email.'})
self.validFlag = false
}
} else if (v.property.max !== 0) {
if (data[v.name].length > v.property.max) {
self.validErr.push({name: v.name, errmsg: 'max ' + v.property.max + ' characters allowed.'})
self.validFlag = false
}
} else if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'})
self.validFlag = false
}
}
} else if (v.type === 'email' && data[v.name] !== '') {
let patt1 = (v.property.regEx === '') ? new RegExp('[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,3}$') : new RegExp(v.property.regEx)
let res1 = patt1.test(data[v.name])
if (!res1) {
self.validErr.push({name: v.name, errmsg: 'Invalid Email.'})
self.validFlag = false
} else if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'})
self.validFlag = false
}
}
} else if (v.type === 'phone') {
let patt2 = (v.property.regEx === '') ? new RegExp('^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$') : new RegExp(v.property.regEx)
let res2 = patt2.test(data[v.name])
if (!res2) {
self.validErr.push({name: v.name, errmsg: 'Invalid Phone.'})
self.validFlag = false
} else if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Phone, Please select allow one.'})
self.validFlag = false
}
}
} else if (v.type === 'number') {
if (v.property.allowedValue.length > 0) {
let exist = _.indexOf(v.property.allowedValue, data[v.name])
if (exist === -1) {
self.validErr.push({name: v.name, errmsg: 'Not Allowed Number, Please select allow one.'})
self.validFlag = false
}
}
} else if (v.type === 'date') {
if (v.property.mindate !== '' && v.property.maxdate !== '') {
if (data[v.name] < v.property.mindate && data[v.name] > v.property.maxdate) {
self.validErr.push({name: v.name, errmsg: 'Date must in between ' + v.property.mindate + ' and ' + v.property.maxdate})
self.validFlag = false
}
} else if (v.property.mindate !== '') {
if (data[v.name] < v.property.mindate) {
self.validErr.push({name: v.name, errmsg: 'Date must be greater than or equal ' + v.property.mindate + '.'})
self.validFlag = false
}
} else if (v.property.maxdate !== '') {
if (data[v.name] > v.property.maxdate) {
self.validErr.push({name: v.name, errmsg: 'Date must be less than or equal ' + v.property.mindate + '.'})
self.validFlag = false
}
}
}
}
}
}
}
}
return self.validFlag
Expand Down

0 comments on commit 56dfcfa

Please sign in to comment.