public static void clearBlob(ICswResources CswResources, BlobDataReturn Return, BlobDataParams Request) { CswNbtResources NbtResources = (CswNbtResources)CswResources; CswPropIdAttr PropId = new CswPropIdAttr(Request.propid); CswNbtNode Node = NbtResources.Nodes[PropId.NodeId]; if (null != Node) { CswNbtMetaDataNodeTypeProp MetaDataProp = NbtResources.MetaData.getNodeTypeProp(PropId.NodeTypePropId); if (null != MetaDataProp) { CswNbtNodePropWrapper FileProp = Node.Properties[MetaDataProp]; if (NbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Edit, MetaDataProp.getNodeType(), NbtResources.CurrentNbtUser) && NbtResources.Permit.isPropWritable(CswEnumNbtNodeTypePermission.Edit, MetaDataProp, null, FileProp)) { CswNbtSdTabsAndProps tabsandprops = new CswNbtSdTabsAndProps(NbtResources); tabsandprops.ClearPropValue(Request.propid, true); Request.Blob = new CswNbtSdBlobData.CswNbtBlob(); Request.success = true; Return.Data = Request; } else { throw new CswDniException(CswEnumErrorType.Warning, "You do not have sufficient priveledges to clear this File property", "User " + NbtResources.CurrentNbtUser.UserId + " attempted to call clearBlob without sufficient priviledges."); } } } }
}//if we got any result public static void getImageProp(ICswResources CswResources, NodePropImageReturn Return, BlobDataParams Request) { CswNbtResources NbtResources = (CswNbtResources)CswResources; CswPropIdAttr PropIdAttr = new CswPropIdAttr(Request.propid); CswNbtNode node = NbtResources.Nodes[PropIdAttr.NodeId]; if (null != node) { CswNbtMetaDataNodeType NodeType = node.getNodeType(); CswNbtNodePropWrapper prop = node.Properties[PropIdAttr.NodeTypePropId]; if (NbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.View, NodeType, NbtResources.CurrentNbtUser)) { if (Int32.MinValue == prop.JctNodePropId) { prop.makePropRow(); //if we don't have a jct_node_prop row for this prop, we do now node.postChanges(true); } prop.AsImage.SetImages(Request.date); if (null != prop) { Return.Data = prop; } } else { throw new CswDniException(CswEnumErrorType.Warning, "You do not have sufficient priviledges to get this image property", "User " + NbtResources.CurrentNbtUser.UserId + " attempted to call getImageProp on prop " + prop.JctNodePropId); } } }
public void onSetFk(CswNbtObjClassDesignNodeTypeProp DesignNTPNode) { Collection <CswNbtFieldTypeAttribute> Attributes = getAttributes(); CswNbtFieldTypeAttribute FkTypeAttr = Attributes.FirstOrDefault(a => a.Column == CswEnumNbtPropertyAttributeColumn.Fktype); if (DesignNTPNode.AttributeProperty.ContainsKey(FkTypeAttr.Name)) { CswNbtNodePropWrapper FkTypeProp = DesignNTPNode.AttributeProperty[FkTypeAttr.Name]; if (null != FkTypeProp && FkTypeProp.wasAnySubFieldModified(false)) { CswNbtNodePropMetaDataList FkProp = FkTypeProp.AsMetaDataList; CswNbtViewId ViewId = DesignNTPNode.AttributeProperty[AttributeName.UnitView].AsViewReference.ViewId; CswNbtView View = _CswNbtFieldResources.CswNbtResources.ViewSelect.restoreView(ViewId); if (CswEnumNbtViewRelatedIdType.Unknown != FkProp.Type && Int32.MinValue != FkProp.Id) { //We have valid values that are different that what is currently set CswNbtFieldTypeRuleDefaultImpl.setDefaultView(_CswNbtFieldResources.CswNbtResources.MetaData, DesignNTPNode, View, FkProp.Type, FkProp.Id, false); } else { //Make sure a default view is set CswEnumNbtViewRelatedIdType TargetType = DesignNTPNode.AttributeProperty[AttributeName.UnitTarget].AsMetaDataList.Type; Int32 TargetId = DesignNTPNode.AttributeProperty[AttributeName.UnitTarget].AsMetaDataList.Id; if (CswEnumNbtViewRelatedIdType.Unknown != TargetType && Int32.MinValue != TargetId) { CswNbtFieldTypeRuleDefaultImpl.setDefaultView(_CswNbtFieldResources.CswNbtResources.MetaData, DesignNTPNode, View, TargetType, TargetId, true); } } } } // if( DesignNTPNode.AttributeProperty.ContainsKey( FkTypeAttr.Name ) ) } // onSetFk()
//mark any property references to this property on other nodes as pending update private void _markExternalPropRefsDirty(CswNbtNodePropWrapper CurrentProp) { if (CswTools.IsPrimaryKey(CurrentProp.NodeId)) { CswNbtFieldTypeRulePropertyReference PropRefFTR = (CswNbtFieldTypeRulePropertyReference)_CswNbtResources.MetaData.getFieldTypeRule(CswEnumNbtFieldType.PropertyReference); CswEnumNbtPropColumn PropRefColumn = PropRefFTR.CachedValueSubField.Column; string SQL = @"update jct_nodes_props set pendingupdate = '" + CswConvert.ToDbVal(true) + @"', " + PropRefColumn.ToString() + @" = '' where jctnodepropid in (select j.jctnodepropid from jct_nodes_props j join nodes n on n.nodeid = j.nodeid join nodetype_props p on p.nodetypepropid = j.nodetypepropid join field_types f on p.fieldtypeid = f.fieldtypeid left outer join jct_nodes_props jntp on (jntp.nodetypepropid = p.fkvalue and jntp.nodeid = n.nodeid and jntp.field1_fk = " + CurrentProp.NodeId.PrimaryKey.ToString() + @") left outer join (select jx.jctnodepropid, ox.objectclasspropid, jx.nodeid from jct_nodes_props jx join nodetype_props px on jx.nodetypepropid = px.nodetypepropid join object_class_props ox on px.objectclasspropid = ox.objectclasspropid where jx.field1_fk = " + CurrentProp.NodeId.PrimaryKey.ToString() + @") jocp on (jocp.objectclasspropid = p.fkvalue and jocp.nodeid = n.nodeid) where f.fieldtype = 'PropertyReference' and ((lower(p.fktype) = 'nodetypepropid' and jntp.jctnodepropid is not null) or (lower(p.fktype) = 'objectclasspropid' and jocp.jctnodepropid is not null)) and ((lower(p.valueproptype) = 'nodetypepropid' and p.valuepropid = " + CurrentProp.NodeTypePropId.ToString() + @") or (lower(p.valueproptype) = 'objectclasspropid' and p.valuepropid = " + CurrentProp.ObjectClassPropId + @")))"; // We're not doing this in a CswTableUpdate because it might be a large operation, // and we don't care about auditing for this change. _CswNbtResources.execArbitraryPlatformNeutralSql(SQL); } }
protected override void beforeWriteNodeLogic(bool Creating, bool OverrideUniqueValidation) { if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.CISPro) && Location.wasAnySubFieldModified() && _CswNbtResources.EditMode != CswEnumNbtNodeEditMode.Add) { CswNbtNodePropWrapper LocationWrapper = Node.Properties[PropertyName.Location]; string PrevLocationId = LocationWrapper.GetOriginalPropRowValue(((CswNbtFieldTypeRuleLocation)_CswNbtResources.MetaData.getFieldTypeRule(LocationWrapper.getFieldTypeValue())).NodeIdSubField.Column); CswPrimaryKey PrevLocationPk = null; CswPrimaryKey CurrLocationPk = null; if (false == String.IsNullOrEmpty(PrevLocationId)) { PrevLocationPk = new CswPrimaryKey("nodes", CswConvert.ToInt32(PrevLocationId)); } if (null != Location.SelectedNodeId) { CurrLocationPk = Location.SelectedNodeId; } if (PrevLocationPk != null && PrevLocationPk != CurrLocationPk) { //Case 26849 - Executing even if one of the locations is Top or null so that the other location can still be updated CswNbtBatchOpInventoryLevels BatchOp = new CswNbtBatchOpInventoryLevels(_CswNbtResources); BatchOp.makeBatchOp(PrevLocationPk, CurrLocationPk); } } //Case 27495 - Sites can only be at "Top" if (NodeType.NodeTypeName == "Site") { Location.SelectedNodeId = null; Location.RefreshNodeName(); Location.SyncGestalt(); } }//beforeWriteNode()
private void _runProperties(CswNbtNode Node, JObject SubItemsJProp) { Collection <CswNbtMetaDataNodeTypeTab> Tabs = new Collection <CswNbtMetaDataNodeTypeTab>(); foreach (CswNbtMetaDataNodeTypeTab Tab in from _Tab in _CswNbtResources.MetaData.getNodeTypeTabs(Node.NodeTypeId) orderby _Tab.TabOrder select _Tab) { Tabs.Add(Tab); } for (Int32 i = 0; i < Tabs.Count; i++) { CswNbtMetaDataNodeTypeTab CurrentTab = Tabs[i]; SubItemsJProp[CurrentTab.TabName] = new JObject(); //if( i > 1 ) //{ // CswNbtMetaDataNodeTypeTab PrevTab = Tabs[i - 1]; // TabObj.Add( new JProperty( "prevtab", PrevTab.TabName ) ); //} SubItemsJProp[CurrentTab.TabName]["currenttab"] = Tabs[i].TabName; if (i < Tabs.Count - 1) { SubItemsJProp[CurrentTab.TabName]["nexttab"] = Tabs[i + 1].TabName; } foreach (CswNbtMetaDataNodeTypeProp Prop in from _Prop in CurrentTab.getNodeTypePropsByDisplayOrder() where false == _Prop.HideInMobile && _Prop.getFieldType().FieldType != CswNbtMetaDataFieldType.NbtFieldType.Password && _Prop.getFieldType().FieldType != CswNbtMetaDataFieldType.NbtFieldType.Grid select _Prop) { CswNbtNodePropWrapper PropWrapper = Node.Properties[Prop]; string PropId = PropIdPrefix + Prop.PropId + "_" + NodeIdPrefix + Node.NodeId; SubItemsJProp[CurrentTab.TabName][PropId] = new JObject(); SubItemsJProp[CurrentTab.TabName][PropId]["prop_name"] = CswTools.SafeJavascriptParam(Prop.PropNameWithQuestionNo); SubItemsJProp[CurrentTab.TabName][PropId]["fieldtype"] = Prop.getFieldType().FieldType.ToString(); SubItemsJProp[CurrentTab.TabName][PropId]["gestalt"] = CswTools.SafeJavascriptParam(PropWrapper.Gestalt); SubItemsJProp[CurrentTab.TabName][PropId]["ocpname"] = CswTools.SafeJavascriptParam(PropWrapper.ObjectClassPropName); PropWrapper.ToJSON((JObject)SubItemsJProp[CurrentTab.TabName][PropId]); } } }
} // copyPropertyValues() /// <summary> /// Sets the values of all relationships whose target matches /// the ParentNode's nodetypeid or objectclassid to the ParentNode's nodeid. /// </summary> public void RelateToNode(CswNbtNode ParentNode, CswNbtView View) { CswNbtNodePropWrapper Prop = null; // BZ 10372 - Iterate all relationships foreach (CswNbtViewRelationship ViewRelationship in View.Root.GetAllChildrenOfType(CswEnumNbtViewNodeType.CswNbtViewRelationship)) { // BZ 8355 - Set relationships on children pointing to parents, not the other way if (ViewRelationship.PropOwner == CswEnumNbtViewPropOwnerType.Second) { //if( ( ( ViewRelationship.SecondType == NbtViewRelatedIdType.NodeTypeId && ViewRelationship.SecondId == this.NodeTypeId ) || // ( ViewRelationship.SecondType == NbtViewRelatedIdType.ObjectClassId && ViewRelationship.SecondId == this.getObjectClassId() ) ) && // ( ( ViewRelationship.FirstType == NbtViewRelatedIdType.NodeTypeId && ViewRelationship.FirstId == ParentNode.NodeTypeId ) || // ( ViewRelationship.FirstType == NbtViewRelatedIdType.ObjectClassId && ViewRelationship.FirstId == ParentNode.getObjectClassId() ) ) ) if (ViewRelationship.SecondMatches(this.getNodeType()) && ViewRelationship.FirstMatches(ParentNode.getNodeType())) { if (ViewRelationship.PropType == CswEnumNbtViewPropIdType.NodeTypePropId) { Prop = this.Properties[_CswNbtResources.MetaData.getNodeTypeProp(ViewRelationship.PropId)]; } else if (ViewRelationship.PropType == CswEnumNbtViewPropIdType.ObjectClassPropId) { Prop = this.Properties[_CswNbtResources.MetaData.getObjectClassProp(ViewRelationship.PropId).PropName]; } if (Prop != null) { CswEnumNbtFieldType FT = Prop.getFieldTypeValue(); if (FT == CswEnumNbtFieldType.Relationship) { Prop.AsRelationship.RelatedNodeId = ParentNode.NodeId; Prop.AsRelationship.RefreshNodeName(); } if (FT == CswEnumNbtFieldType.Location) { Prop.AsLocation.SelectedNodeId = ParentNode.NodeId; Prop.AsLocation.RefreshNodeName(); } } } } // if( ViewRelationship.PropOwner == PropOwnerType.Second ) } // foreach( CswNbtViewRelationship ViewRelationship in View.Root.GetAllChildrenOfType( NbtViewNodeType.CswNbtViewRelationship ) ) } // RelateToNode()
//afterWriteNode() protected override void beforeDeleteNodeLogic() { //prevent user from deleting their own user if (_CswNbtNode.NodeId == _CswNbtResources.CurrentUser.UserId) { throw (new CswDniException(CswEnumErrorType.Warning, "You can not delete your own user account.", "Current user (" + _CswNbtResources.CurrentUser.Username + ") can not delete own UserClass node.")); } // case 22635 - prevent deleting chemsw admin user CswNbtNodePropWrapper UsernamePropWrapper = Node.Properties[PropertyName.Username]; if ( UsernamePropWrapper.GetOriginalPropRowValue( UsernamePropWrapper.NodeTypeProp.getFieldTypeRule().SubFields.Default.Column) == ChemSWAdminUsername && false == (_CswNbtResources.CurrentNbtUser is CswNbtSystemUser)) { throw new CswDniException(CswEnumErrorType.Warning, "The '" + ChemSWAdminUsername + "' user cannot be deleted", "Current user (" + _CswNbtResources.CurrentUser.Username + ") attempted to delete the '" + ChemSWAdminUsername + "' user."); } CswPrimaryKey RoleId = Role.RelatedNodeId; if (RoleId != null) { CswNbtNode RoleNode = _CswNbtResources.Nodes[RoleId]; //prevent user from deleting admin if they are not an admin if (_RoleNodeObjClass.Administrator.Checked == CswEnumTristate.True && _CswNbtResources.CurrentNbtUser.IsAdministrator() != true) { throw (new CswDniException(CswEnumErrorType.Warning, "You can not delete administrator accounts because you are not an administrator.", "Block user account delete because login user (" + _CswNbtResources.CurrentUser.Username + ") is not an administrator.")); } } //case 28010 - delete all view assigned to this user _CswNbtResources.ViewSelect.deleteViewsByUserId(NodeId); }
//Updates related Relationship, Location, and Quantity properties private void _markExternalRelatedPropsDirty(CswNbtNodePropWrapper CurrentProp) { if (CurrentProp.getFieldTypeValue() == CswEnumNbtFieldType.Relationship || CurrentProp.getFieldTypeValue() == CswEnumNbtFieldType.Location || CurrentProp.getFieldTypeValue() == CswEnumNbtFieldType.Quantity) { string SQL = @"update jct_nodes_props set pendingupdate = '" + CswConvert.ToDbVal(true) + @"' where jctnodepropid in (select j.jctnodepropid from jct_nodes_props j join nodetype_props p on j.nodetypepropid = p.nodetypepropid join field_types f on p.fieldtypeid = f.fieldtypeid where (f.fieldtype = 'Relationship' or f.fieldtype = 'Location' or f.fieldtype = 'Quantity') and j.field1_fk = " + _CswNbtNode.NodeId.PrimaryKey.ToString() + ")"; // We're not doing this in a CswTableUpdate because it might be a large operation, // and we don't care about auditing for this change. _CswNbtResources.execArbitraryPlatformNeutralSql(SQL); } }
public void ReadPropertyData(CswNbtNode Node, CswNbtWcfProperty WcfProp) { CswNbtMetaDataNodeType NodeType = Node.getNodeType(); CswNbtNodePropWrapper propWrapper = null; if (false == String.IsNullOrEmpty(WcfProp.OriginalPropName)) { propWrapper = Node.Properties[WcfProp.OriginalPropName]; } else { CswNbtMetaDataNodeTypeProp ntp = NodeType.getNodeTypeProp(WcfProp.PropName); propWrapper = Node.Properties[ntp]; } JObject propData = ConvertWcfPropertyData(WcfProp); propWrapper.ReadJSON(propData, null, null); }
public void onBeforeWriteDesignNode(CswNbtObjClassDesignNodeTypeProp DesignNTPNode) { CswNbtNodePropRelationship SequenceProp = DesignNTPNode.AttributeProperty[CswEnumNbtPropertyAttributeName.Sequence].AsRelationship; if (SequenceProp.wasSubFieldModified(CswNbtFieldTypeRuleRelationship.SubFieldName.NodeID)) { if (null != DesignNTPNode.RelationalNodeTypeProp && null != DesignNTPNode.RelationalNodeType) { // Update nodes foreach (CswNbtNode CurrentNode in DesignNTPNode.RelationalNodeType.getNodes(false, false)) { CswNbtNodePropWrapper CurrentProp = CurrentNode.Properties[DesignNTPNode.RelationalNodeTypeProp]; if (CurrentProp.AsSequence.Empty) { CurrentProp.AsSequence.setSequenceValue(); } } } // if prop is sequence or barcode } // if(SequenceProp.wasSubFieldModified( CswNbtFieldTypeRuleRelationship.SubFieldName.NodeID ) ) } // onBeforeWriteDesignNode()
public void onBeforeWriteDesignNode(CswNbtObjClassDesignNodeTypeProp DesignNTPNode) { CswNbtMetaDataNodeTypeProp PossibleAnswersNTP = DesignNTPNode.NodeType.getNodeTypeProp(CswEnumNbtPropertyAttributeName.PossibleAnswers.ToString()); CswNbtMetaDataNodeTypeProp CompliantAnswersNTP = DesignNTPNode.NodeType.getNodeTypeProp(CswEnumNbtPropertyAttributeName.CompliantAnswers.ToString()); if (null != PossibleAnswersNTP && null != CompliantAnswersNTP) { CswNbtNodePropWrapper PossibleAnswersProp = DesignNTPNode.Node.Properties[PossibleAnswersNTP]; CswNbtNodePropWrapper CompliantAnswersProp = DesignNTPNode.Node.Properties[CompliantAnswersNTP]; if (null != PossibleAnswersProp && null != CompliantAnswersProp) { // Guarantee a Compliant Answer for Question if (CompliantAnswersProp.AsMultiList.Empty && CompliantAnswersProp.AsMultiList.Options.Count > 0) { //throw new CswDniException( CswEnumErrorType.Warning, "Compliant Answer is a required field", "Compliant Answer is a required field" ); CompliantAnswersProp.AsMultiList.AddValue(CompliantAnswersProp.AsMultiList.Options.First().Value); } } } }
/// <summary> /// Update the attributes of an Object Class Prop, and cascade changes to existing NodeTypeProps /// </summary> public void UpdateObjectClassProp(CswNbtMetaDataObjectClassProp ObjectClassProp, CswEnumNbtObjectClassPropAttributes AttributeColumnName, object Value) { if (AttributeColumnName != CswResources.UnknownEnum) { string AttributeColumnNameString = CswNbtMetaDataObjectClassProp.getObjectClassPropAttributesAsString(AttributeColumnName); object DBValue = CswConvert.ToDbVal(Value); if (ObjectClassProp._DataRow[AttributeColumnNameString] != DBValue) { ObjectClassProp._DataRow[AttributeColumnNameString] = DBValue; if (AttributeColumnName == CswEnumNbtObjectClassPropAttributes.setvalonadd) { ObjectClassProp._DataRow[CswNbtMetaDataObjectClassProp.getObjectClassPropAttributesAsString(CswEnumNbtObjectClassPropAttributes.display_col_add)] = DBNull.Value; ObjectClassProp._DataRow[CswNbtMetaDataObjectClassProp.getObjectClassPropAttributesAsString(CswEnumNbtObjectClassPropAttributes.display_row_add)] = DBNull.Value; } _CswNbtMetaDataResources.ObjectClassPropTableUpdate.update(ObjectClassProp._DataRow.Table); foreach (CswNbtMetaDataNodeTypeProp NodeTypeProp in ObjectClassProp.getNodeTypeProps()) { CswNbtFieldTypeAttribute attr = NodeTypeProp.getFieldTypeRule().getAttributes().FirstOrDefault(a => a.Column == AttributeColumnName); if (null != attr) { CswNbtNodePropWrapper attrProp = NodeTypeProp.DesignNode.AttributeProperty[attr.Name]; attrProp.SetSubFieldValue(attrProp.NodeTypeProp.getFieldTypeRule().SubFields.Default, DBValue); } if (AttributeColumnName == CswEnumNbtObjectClassPropAttributes.setvalonadd) { if (CswConvert.ToBoolean(Value)) { NodeTypeProp.updateLayout(CswEnumNbtLayoutType.Add, true); } else { NodeTypeProp.removeFromLayout(CswEnumNbtLayoutType.Add); } } } } } } // UpdateObjectClassProp()
}//afterWriteNode() protected override void beforeDeleteNodeLogic() { // Prevent deleting your own role if( _CswNbtNode.NodeId == _CswNbtResources.CurrentUser.RoleId ) { throw ( new CswDniException( CswEnumErrorType.Warning, "You can not delete your own role account.", "Current user (" + _CswNbtResources.CurrentUser.Username + ") can not delete own RoleClass node." ) ); } // case 22635 - prevent deleting the chemsw admin role CswNbtNodePropWrapper NamePropWrapper = Node.Properties[PropertyName.Name]; if( NamePropWrapper.GetOriginalPropRowValue( _CswNbtResources.MetaData.getFieldTypeRule( NamePropWrapper.getFieldTypeValue() ).SubFields.Default.Column ) == ChemSWAdminRoleName && false == ( _CswNbtResources.CurrentNbtUser is CswNbtSystemUser ) ) { throw new CswDniException( CswEnumErrorType.Warning, "The '" + ChemSWAdminRoleName + "' role cannot be deleted", "Current user (" + _CswNbtResources.CurrentUser.Username + ") attempted to delete the '" + ChemSWAdminRoleName + "' role." ); } //case 28010 - delete all view assigned to this role _CswNbtResources.ViewSelect.deleteViewsByRoleId( NodeId ); //Case 30628 - Delete all PermissionSet nodes assigned to this Role _deleteRelatedPermissionNodes(); }//beforeDeleteNode()
public static void clearImage(ICswResources CswResources, NodePropImageReturn Return, BlobDataParams Request) { CswNbtResources NbtResources = (CswNbtResources)CswResources; CswPropIdAttr PropId = new CswPropIdAttr(Request.propid); CswNbtNode Node = NbtResources.Nodes[PropId.NodeId]; if (null != Node) { CswNbtMetaDataNodeTypeProp MetaDataProp = NbtResources.MetaData.getNodeTypeProp(PropId.NodeTypePropId); if (null != MetaDataProp) { CswNbtNodePropWrapper FileProp = Node.Properties[MetaDataProp]; if (NbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Edit, MetaDataProp.getNodeType(), NbtResources.CurrentNbtUser) && NbtResources.Permit.isPropWritable(CswEnumNbtNodeTypePermission.Edit, MetaDataProp, null, FileProp)) { int BlobDataId = Request.Blob.BlobDataId; CswTableUpdate blobDataTS = NbtResources.makeCswTableUpdate("clearImage", "blob_data"); DataTable blobDataTbl = blobDataTS.getTable("where blobdataid = " + BlobDataId); foreach (DataRow row in blobDataTbl.Rows) { row.Delete(); } blobDataTS.update(blobDataTbl); Request.Blob = new CswNbtSdBlobData.CswNbtBlob(); Request.success = true; getImageProp(CswResources, Return, Request); } } } else { throw new CswDniException(CswEnumErrorType.Warning, "You do not have sufficient priveledges to clear this Image property", "User " + NbtResources.CurrentNbtUser.UserId + " attempted to call clearImg without sufficient priviledges."); } }
public override void update() { //Move blob data from jct_nodes_props to blob_data CswNbtMetaDataFieldType molFT = _CswNbtSchemaModTrnsctn.MetaData.getFieldType( CswEnumNbtFieldType.MOL ); CswNbtMetaDataFieldType imageFT = _CswNbtSchemaModTrnsctn.MetaData.getFieldType( CswEnumNbtFieldType.Image ); CswNbtMetaDataFieldType fileFT = _CswNbtSchemaModTrnsctn.MetaData.getFieldType( CswEnumNbtFieldType.File ); string sql = "select distinct nodetypeid from nodetype_props where fieldtypeid in (" + molFT.FieldTypeId + "," + imageFT.FieldTypeId + "," + fileFT.FieldTypeId + ")"; CswArbitrarySelect arbSelect = _CswNbtSchemaModTrnsctn.makeCswArbitrarySelect( "findBlobDataNTs", sql ); DataTable nodeTypes = arbSelect.getTable(); foreach( DataRow Row in nodeTypes.Rows ) { int NodeTypeId = CswConvert.ToInt32( Row["nodetypeid"].ToString() ); CswNbtMetaDataNodeType NodeType = _CswNbtSchemaModTrnsctn.MetaData.getNodeType( NodeTypeId ); if( null != NodeType ) { foreach( CswNbtNode Node in NodeType.getNodes( false, true, false, true ) ) { foreach( CswNbtMetaDataNodeTypeProp Prop in NodeType.getNodeTypeProps() ) { CswEnumNbtFieldType Type = Prop.getFieldTypeValue(); if( Type == CswEnumNbtFieldType.MOL || Type == CswEnumNbtFieldType.File || Type == CswEnumNbtFieldType.Image ) { CswNbtNodePropWrapper propWrapper = Node.Properties[Prop]; _moveBlobData( propWrapper, Node ); } } } } } } // update()
} // update() private void _moveBlobData( CswNbtNodePropWrapper PropWrapper, CswNbtNode Node ) { if( Int32.MinValue != PropWrapper.JctNodePropId ) { CswNbtSdBlobData SdBlobData = _CswNbtSchemaModTrnsctn.CswNbtSdBlobData; CswPropIdAttr PropId = new CswPropIdAttr( Node.NodeId, PropWrapper.NodeTypePropId ); byte[] BlobData = new byte[0]; string ContentType = string.Empty; string FileName = string.Empty; CswTableSelect JctTS = _CswNbtSchemaModTrnsctn.makeCswTableSelect( "getBlobData", "jct_nodes_props" ); { DataTable JctDT = JctTS.getTable( "jctnodepropid", PropWrapper.JctNodePropId ); foreach( DataRow Row in JctDT.Rows ) //should only be one { if( _CswNbtSchemaModTrnsctn.isColumnDefined( "jct_nodes_props", "blobdata" ) ) { BlobData = Row["blobdata"] as byte[]; } else { BlobData = new byte[0]; } FileName = Row["field1"].ToString(); ContentType = Row["field2"].ToString(); } if( null != BlobData ) { string Href; SdBlobData.saveFile( PropId.ToString(), BlobData, ContentType, FileName, out Href ); } } } }
public void AddUniqueFilterToView(CswNbtView View, CswNbtViewProperty UniqueValueViewProperty, CswNbtNodePropWrapper PropertyValueToCheck, bool EnforceNullEntries = false) { _CswNbtFieldTypeRuleDefault.AddUniqueFilterToView(View, UniqueValueViewProperty, PropertyValueToCheck, EnforceNullEntries); }
public void SetLastModified(CswNbtNodePropWrapper BlobProp) { //BlobProp.SetPropRowValue( CswEnumNbtPropColumn.Field2_Date, DateTime.Now ); BlobProp.SetSubFieldValue(CswNbtFieldTypeRuleBlob.SubFieldName.DateModified, DateTime.Now); }
public override void update() { { CswCommaDelimitedString LogicalsMissingValidDefaultValues = new CswCommaDelimitedString(); foreach (CswNbtMetaDataNodeType NodeType in _CswNbtSchemaModTrnsctn.MetaData.getNodeTypes()) { foreach (CswNbtMetaDataNodeTypeProp Logical in NodeType.getNodeTypeProps(CswEnumNbtFieldType.Logical)) { if (Logical.IsRequired && (false == Logical.HasDefaultValue() || (CswEnumTristate.False != Logical.DefaultValue.AsLogical.Checked && CswEnumTristate.True != Logical.DefaultValue.AsLogical.Checked))) { LogicalsMissingValidDefaultValues.Add(Logical.PropId.ToString()); Logical.DefaultValue.AsLogical.Checked = CswEnumTristate.False; } } } if (LogicalsMissingValidDefaultValues.Count > 0) { string NodesToUpdateSql = @" select nodeid, nodetypepropid from jct_nodes_props where nodetypepropid in (" + LogicalsMissingValidDefaultValues.ToString() + ")"; CswArbitrarySelect ArbSelect = _CswNbtSchemaModTrnsctn.makeCswArbitrarySelect("logicals_missing_default_values", NodesToUpdateSql); DataTable NodeTable = ArbSelect.getTable(); foreach (DataRow Row in NodeTable.Rows) { CswPrimaryKey NodeId = new CswPrimaryKey("nodes", CswConvert.ToInt32(Row["nodeid"])); CswNbtNode Node = _CswNbtSchemaModTrnsctn.Nodes[NodeId]; if (null != Node) { Int32 NodeTypePropId = CswConvert.ToInt32(Row["nodetypepropid"]); CswNbtNodePropWrapper PropWrapper = Node.Properties[NodeTypePropId]; if (null != PropWrapper) { if (CswEnumTristate.False != PropWrapper.AsLogical.Checked && CswEnumTristate.True != PropWrapper.AsLogical.Checked) { PropWrapper.SetDefaultValue(); } } Node.postChanges(ForceUpdate: false); } } } } { CswCommaDelimitedString ImageListsWithDefaultValue = new CswCommaDelimitedString(); foreach (CswNbtMetaDataNodeType NodeType in _CswNbtSchemaModTrnsctn.MetaData.getNodeTypes()) { foreach (CswNbtMetaDataNodeTypeProp ImageList in NodeType.getNodeTypeProps(CswEnumNbtFieldType.ImageList)) { if (ImageList.IsRequired && ImageList.HasDefaultValue()) { ImageListsWithDefaultValue.Add(ImageList.PropId.ToString()); } } } if (ImageListsWithDefaultValue.Count > 0) { string NodesToUpdateSql = @" select nodeid, nodetypepropid from jct_nodes_props where nodetypepropid in (" + ImageListsWithDefaultValue.ToString() + ")"; CswArbitrarySelect ArbSelect = _CswNbtSchemaModTrnsctn.makeCswArbitrarySelect("imagelists_default_values", NodesToUpdateSql); DataTable NodeTable = ArbSelect.getTable(); foreach (DataRow Row in NodeTable.Rows) { CswPrimaryKey NodeId = new CswPrimaryKey("nodes", CswConvert.ToInt32(Row["nodeid"])); CswNbtNode Node = _CswNbtSchemaModTrnsctn.Nodes[NodeId]; if (null != Node) { Int32 NodeTypePropId = CswConvert.ToInt32(Row["nodetypepropid"]); CswNbtNodePropWrapper PropWrapper = Node.Properties[NodeTypePropId]; if (null != PropWrapper) { if (PropWrapper.Empty) { PropWrapper.SetDefaultValue(); } } Node.postChanges(ForceUpdate: false); } } } } }
} // getProp() public JProperty makePropJson(CswPrimaryKey NodeId, Int32 TabId, CswNbtMetaDataNodeTypeProp Prop, CswNbtNodePropWrapper PropWrapper, Int32 Row, Int32 Column, string TabGroup, bool NodeLocked) { return(_TabsPropsSd.makePropJson(NodeId, Prop, PropWrapper, new CswNbtMetaDataNodeTypeLayoutMgr.NodeTypeLayout(Prop.NodeTypeId, Prop.PropId, Row, Column, TabId, null, TabGroup), NodeLocked: NodeLocked)); } // makePropJson()
} // getMergeInfo() private void _addMergeNodes(MergeInfoData ret, CswPrimaryKey NodeId1, CswPrimaryKey NodeId2, CswNbtMetaDataNodeTypeProp NodeReferenceProp = null) { CswNbtNode Node1 = _CswNbtResources.Nodes[NodeId1]; CswNbtNode Node2 = _CswNbtResources.Nodes[NodeId2]; if (null != Node1 && null != Node2) { // Make sure there isn't already a node pair for these nodes if (false == ret.NodePairs.Any(np => (np.Node1Id == Node1.NodeId.ToString() && np.Node2Id == Node2.NodeId.ToString()) || (np.Node1Id == Node2.NodeId.ToString() && np.Node2Id == Node1.NodeId.ToString()))) { CswNbtMetaDataNodeType Node1NT = Node1.getNodeType(); MergeInfoData.MergeInfoNodePair NodePair = new MergeInfoData.MergeInfoNodePair(); NodePair.NodeReferences = new Collection <MergeInfoData.MergeInfoNodeReference>(); NodePair.NodeTypeName = Node1NT.NodeTypeName; NodePair.Node1Id = Node1.NodeId.ToString(); NodePair.Node2Id = Node2.NodeId.ToString(); NodePair.Node1Name = Node1.NodeName; NodePair.Node2Name = Node2.NodeName; if (null != NodeReferenceProp) { NodePair.NodeReferencePropId = NodeReferenceProp.PropId; } else { NodePair.NodeReferencePropId = Int32.MinValue; } foreach (CswNbtNodePropWrapper Prop1 in Node1.Properties.Where(p => (null == NodeReferenceProp || p.NodeTypePropId != NodeReferenceProp.PropId))) { CswNbtNodePropWrapper Prop2 = Node2.Properties[Prop1.NodeTypePropId]; if (null == Prop2 || Prop1.Gestalt != Prop2.Gestalt) { NodePair.Properties.Add(new MergeInfoData.MergeInfoProperty() { PropName = Prop1.PropName, NodeTypePropId = Prop1.NodeTypePropId, Node1Value = Prop1.Gestalt, Node2Value = Prop2.Gestalt }); } // if( null == Prop2 || Prop1.Gestalt != Prop2.Gestalt ) } // foreach( CswNbtNodePropWrapper Prop1 in Node1.Properties ) ret.NodePairs.Add(NodePair); // If two nodes that formerly related to each of node1 and node2 now relate to the merged target, // and they now would be compound unique violations, we have to merge those too. // First, find references that point to the merged nodes foreach (CswNbtMetaDataNodeTypeProp thisProp in _CswNbtResources.MetaData.getNodeTypeProps().Where(p => p.IsNodeReference() && p.FkMatches(Node1.getNodeType()))) { // Find unique key sets for nodes using this reference that point to either node1 or node2 Dictionary <CswDelimitedString, CswPrimaryKey> Node1UniqueKeysDict = _getUniqueKeysDict(NodePair, Node1, thisProp); Dictionary <CswDelimitedString, CswPrimaryKey> Node2UniqueKeysDict = _getUniqueKeysDict(NodePair, Node2, thisProp); // Look for redundant keys to indicate a potential unique violation foreach (CswDelimitedString key in Node1UniqueKeysDict.Keys) { if (Node2UniqueKeysDict.ContainsKey(key)) { // unique violation! gotta merge these too. _addMergeNodes(ret, Node1UniqueKeysDict[key], Node2UniqueKeysDict[key], thisProp); } } // foreach( CswDelimitedString key in Node1UniqueKeysDict.Keys ) } // foreach( CswNbtMetaDataNodeTypeProp thisProp in _CswNbtResources.MetaData.getNodeTypeProps().Where( p => p.IsNodeReference() ) ) // Special case: UserSelect properties if (Node1NT.getObjectClassValue() == CswEnumNbtObjectClass.UserClass) { foreach (CswNbtMetaDataNodeTypeProp thisUserSelProp in _CswNbtResources.MetaData.getNodeTypeProps(CswEnumNbtFieldType.UserSelect)) { // Create a view of nodes that point to either merged node via this reference CswNbtView view = new CswNbtView(_CswNbtResources); CswNbtViewRelationship rel1 = view.AddViewRelationship(thisUserSelProp.getNodeType(), false); view.AddViewPropertyAndFilter(rel1, thisUserSelProp, Conjunction: CswEnumNbtFilterConjunction.And, FilterMode: CswEnumNbtFilterMode.Contains, Value: Node1.NodeId.PrimaryKey.ToString()); view.AddViewPropertyAndFilter(rel1, thisUserSelProp, Conjunction: CswEnumNbtFilterConjunction.Or, FilterMode: CswEnumNbtFilterMode.Contains, Value: Node2.NodeId.PrimaryKey.ToString()); // Add nodes with matching UserSelect properties to NodeReferences for later updating ICswNbtTree tree = _CswNbtResources.Trees.getTreeFromView(view, RequireViewPermissions: false, IncludeHiddenNodes: true, IncludeSystemNodes: true); for (Int32 c = 0; c < tree.getChildNodeCount(); c++) { tree.goToNthChild(c); NodePair.NodeReferences.Add(new MergeInfoData.MergeInfoNodeReference() { NodeId = tree.getNodeIdForCurrentPosition().ToString(), NodeTypePropId = thisUserSelProp.PropId }); tree.goToParentNode(); } // for( Int32 c = 0; c < tree.getChildNodeCount(); c++ ) } // foreach( CswNbtMetaDataNodeTypeProp thisUserSelProp in _CswNbtResources.MetaData.getNodeTypeProps( CswEnumNbtFieldType.UserSelect ) ) } // if( Node1NT.getObjectClassValue() == CswEnumNbtObjectClass.UserClass ) } // if(false == ret.NodePairs.Any( ... )) } // if( null != Node1 && null != Node2 ) } // _addMergeNodes()
} // getNodeIdByRelationalId() /// <summary> /// Find a node by a unique property value /// </summary> /// <param name="MetaDataProp">Property to search with</param> /// <param name="PropWrapper">Value to find</param> /// <returns></returns> public CswNbtNode FindNodeByUniqueProperty(CswNbtMetaDataNodeTypeProp MetaDataProp, CswNbtNodePropWrapper PropWrapper) { CswNbtNode ret = null; string SQLQuery = string.Empty; foreach (CswNbtSubField SubField in MetaDataProp.getFieldTypeRule().SubFields) { if (SQLQuery != string.Empty) { SQLQuery += " INTERSECT "; } //if( SubField.RelationalTable == string.Empty ) //{ SQLQuery += " (select nodeid, 'nodes' tablename "; SQLQuery += " from jct_nodes_props "; SQLQuery += " where nodetypepropid = " + MetaDataProp.PropId.ToString() + " "; SQLQuery += " and " + SubField.Column.ToString() + " = '" + PropWrapper.GetSubFieldValue(SubField) + "') "; //} //else //{ // string PrimeKeyCol = _CswNbtResources.DataDictionary.getPrimeKeyColumn( SubField.RelationalTable ); // SQLQuery += " (select " + PrimeKeyCol + " nodeid, '" + SubField.RelationalTable + "' tablename "; // SQLQuery += " from " + SubField.RelationalTable + " "; // SQLQuery += " where " + SubField.RelationalColumn + " = '" + PropWrapper.GetSubFieldValue( SubField ) + "') "; //} } SQLQuery = "select nodeid, tablename from " + SQLQuery; CswArbitrarySelect UniquePropSelect = _CswNbtResources.makeCswArbitrarySelect("FindNodeByUniqueProperty_select", SQLQuery); DataTable UniquePropTable = UniquePropSelect.getTable(); if (UniquePropTable.Rows.Count > 0) { ret = this[new CswPrimaryKey(UniquePropTable.Rows[0]["tablename"].ToString(), CswConvert.ToInt32(UniquePropTable.Rows[0]["nodeid"]))]; } return(ret); } // FindNodeByUniqueProperty()
} // beforeWriteNode() //Updates related composite, propertyreference, relationship, and location private void _updateExternalRelatedProps(CswNbtNodePropWrapper CurrentProp) { // When a property changes, we need to: // 1. recalculate composite property values which include changed properties on this node foreach (CswNbtNodePropWrapper CompositeProp in _CswNbtNode.Properties[(CswEnumNbtFieldType)CswEnumNbtFieldType.Composite]) { if (CompositeProp.AsComposite.TemplateValue.Contains(CswNbtMetaData.MakeTemplateEntry(CurrentProp.NodeTypePropId.ToString()))) { CompositeProp.AsComposite.RecalculateCompositeValue(); } } // 2. recalculate property references attached to relationships whose values changed if (CurrentProp.getFieldTypeValue() == CswEnumNbtFieldType.Relationship) { foreach (CswNbtNodePropWrapper PropRefPropWrapper in _CswNbtNode.Properties[(CswEnumNbtFieldType)CswEnumNbtFieldType.PropertyReference]) { CswNbtNodePropPropertyReference PropRefProp = PropRefPropWrapper.AsPropertyReference; if ((PropRefProp.RelationshipType == CswEnumNbtViewPropIdType.NodeTypePropId && PropRefProp.RelationshipId == CurrentProp.NodeTypePropId) || (PropRefProp.RelationshipType == CswEnumNbtViewPropIdType.ObjectClassPropId && PropRefProp.RelationshipId == CurrentProp.ObjectClassPropId)) { PropRefProp.RecalculateReferenceValue(); } } } // 3. mark any property references to this property on other nodes as pending update if (CswTools.IsPrimaryKey(CurrentProp.NodeId)) { //BZ 10239 - Fetch the cached value field name. CswNbtFieldTypeRulePropertyReference PropRefFTR = (CswNbtFieldTypeRulePropertyReference)_CswNbtResources.MetaData.getFieldTypeRule(CswEnumNbtFieldType.PropertyReference); CswEnumNbtPropColumn PropRefColumn = PropRefFTR.CachedValueSubField.Column; string SQL = @"update jct_nodes_props set pendingupdate = '" + CswConvert.ToDbVal(true) + @"', " + PropRefColumn.ToString() + @" = '' where jctnodepropid in (select j.jctnodepropid from jct_nodes_props j join nodes n on n.nodeid = j.nodeid join nodetype_props p on p.nodetypepropid = j.nodetypepropid join field_types f on p.fieldtypeid = f.fieldtypeid left outer join jct_nodes_props jntp on (jntp.nodetypepropid = p.fkvalue and jntp.nodeid = n.nodeid and jntp.field1_fk = " + CurrentProp.NodeId.PrimaryKey.ToString() + @") left outer join (select jx.jctnodepropid, ox.objectclasspropid, jx.nodeid from jct_nodes_props jx join nodetype_props px on jx.nodetypepropid = px.nodetypepropid join object_class_props ox on px.objectclasspropid = ox.objectclasspropid where jx.field1_fk = " + CurrentProp.NodeId.PrimaryKey.ToString() + @") jocp on (jocp.objectclasspropid = p.fkvalue and jocp.nodeid = n.nodeid) where f.fieldtype = 'PropertyReference' and ((lower(p.fktype) = 'nodetypepropid' and jntp.jctnodepropid is not null) or (lower(p.fktype) = 'objectclasspropid' and jocp.jctnodepropid is not null)) and ((lower(p.valueproptype) = 'nodetypepropid' and p.valuepropid = " + CurrentProp.NodeTypePropId.ToString() + @") or (lower(p.valueproptype) = 'objectclasspropid' and p.valuepropid = " + CurrentProp.ObjectClassPropId + @")))"; // We're not doing this in a CswTableUpdate because it might be a large operation, // and we don't care about auditing for this change. _CswNbtResources.execArbitraryPlatformNeutralSql(SQL); } // 4. For locations, if this node's location changed, we need to update the pathname on the children if (CurrentProp.getFieldTypeValue() == CswEnumNbtFieldType.Location && CswTools.IsPrimaryKey(_CswNbtNode.NodeId)) { _CswNbtNode.updateRelationsToThisNode(); } }
} //isPropWritable /// <summary> /// Determines if the Property is editable /// </summary> public bool isPropWritable(CswEnumNbtNodeTypePermission Permission, CswNbtMetaDataNodeTypeProp MetaDataProp, CswNbtMetaDataNodeTypeTab MetaDataTab, CswNbtNodePropWrapper NodePropWrapper, CswNbtObjClassRole Role) { bool ret = false; if (null != MetaDataProp) { _initPermissionInfo(Role, null, MetaDataProp.getNodeType(), Permission, ((null != NodePropWrapper) ? NodePropWrapper.NodeId : null), MetaDataProp); ret = _isPropWritableImpl(MetaDataTab, MetaDataProp, NodePropWrapper); } //if-else we have metadata prop return(ret); } //isPropWritable
public int saveFile(string PropIdAttr, byte[] BlobData, string ContentType, string FileName, out string Href, int BlobDataId = Int32.MinValue, bool PostChanges = true, CswNbtNode Node = null) { CswPropIdAttr PropId = new CswPropIdAttr(PropIdAttr); CswNbtMetaDataNodeTypeProp MetaDataProp = _CswNbtResources.MetaData.getNodeTypeProp(PropId.NodeTypePropId); if (null == Node) { Node = _CswNbtResources.Nodes[PropId.NodeId]; } CswNbtNodePropWrapper FileProp = Node.Properties[MetaDataProp]; if (_CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Edit, MetaDataProp.getNodeType(), _CswNbtResources.CurrentNbtUser) && _CswNbtResources.Permit.isPropWritable(CswEnumNbtNodeTypePermission.Edit, MetaDataProp, null, FileProp)) { if (Int32.MinValue == FileProp.JctNodePropId) { FileProp.makePropRow(); //if we don't have a jct_node_prop row for this prop, we do now if (PostChanges) { Node.postChanges(true); } } if (FileProp.getFieldType().FieldType == CswEnumNbtFieldType.Image) { //case 29692: support EXIF image rotation metadata to properly orient photos bool img_ok = false; MemoryStream ms = new MemoryStream(BlobData, 0, BlobData.Length); ms.Write(BlobData, 0, BlobData.Length); System.Drawing.Image img = null; try { img = Image.FromStream(ms, true); img_ok = true; } catch { } if (img_ok == true) { FixOrientation(ref img); ImageConverter converter = new ImageConverter(); BlobData = (byte[])converter.ConvertTo(img, typeof(byte[])); } } //Save the file to blob_data CswTableUpdate BlobUpdate = _CswNbtResources.makeCswTableUpdate("saveBlob", "blob_data"); string whereClause = "where jctnodepropid = " + FileProp.JctNodePropId; if (Int32.MinValue != BlobDataId) { whereClause += " and blobdataid = " + BlobDataId; } DataTable BlobTbl = BlobUpdate.getTable(whereClause); if (BlobTbl.Rows.Count > 0 && (Int32.MinValue != BlobDataId || FileProp.getFieldTypeValue() == CswEnumNbtFieldType.File || FileProp.getFieldTypeValue() == CswEnumNbtFieldType.MOL)) { BlobTbl.Rows[0]["blobdata"] = BlobData; BlobTbl.Rows[0]["contenttype"] = ContentType; BlobTbl.Rows[0]["filename"] = FileName; BlobTbl.Rows[0]["auditlevel"] = MetaDataProp.AuditLevel; BlobDataId = CswConvert.ToInt32(BlobTbl.Rows[0]["blobdataid"]); } else { DataRow NewRow = BlobTbl.NewRow(); NewRow["jctnodepropid"] = FileProp.JctNodePropId; NewRow["blobdata"] = BlobData; NewRow["contenttype"] = ContentType; NewRow["filename"] = FileName; NewRow["auditlevel"] = MetaDataProp.AuditLevel; BlobDataId = CswConvert.ToInt32(NewRow["blobdataid"]); BlobTbl.Rows.Add(NewRow); } BlobUpdate.update(BlobTbl); if (Node.getObjectClass().ObjectClass == CswEnumNbtObjectClass.ReportClass) { CswNbtObjClassReport Report = Node; CswFilePath FilePathTools = new CswFilePath(_CswNbtResources); string ReportPath = FilePathTools.getFullReportFilePath(Report.RPTFile.JctNodePropId.ToString()); _createReportFile(ReportPath, Report.RPTFile.JctNodePropId, BlobData); } if (CswEnumNbtFieldType.File == FileProp.getFieldTypeValue()) { SetLastModified(FileProp); } FileProp.SyncGestalt(); if (PostChanges) { Node.postChanges(false); } Href = CswNbtNodePropBlob.getLink(FileProp.JctNodePropId, PropId.NodeId, BlobDataId); } //canNodeType() && isPropWritable() else { Href = string.Empty; //To satifsy the "ref string Href" throw new CswDniException(CswEnumErrorType.Error, "You do not have sufficient priveledges to save files", "User " + _CswNbtResources.CurrentNbtUser.UserId + " attemped to save blobdata on JctNodeProp " + FileProp.JctNodePropId); } return(BlobDataId); }
public static bool IsBlobProp(CswNbtNodePropWrapper Prop) { bool ret = (Prop.getFieldTypeValue() == CswEnumNbtFieldType.MOL || Prop.getFieldTypeValue() == CswEnumNbtFieldType.Image || Prop.getFieldTypeValue() == CswEnumNbtFieldType.File); return(ret); }
protected override void beforeWriteNodeLogic( bool Creating, bool OverrideUniqueValidation ) { // The user cannot change his or her own Administrator privileges. if( Administrator.wasAnySubFieldModified() && Administrator.Checked != CswConvert.ToTristate( Administrator.GetOriginalPropRowValue() ) && _CswNbtResources.CurrentUser.RoleId == _CswNbtNode.NodeId ) { _CswNbtNode.Properties.clearModifiedFlag(); // prevents multiple error messages from appearing if we attempt to write() again throw new CswDniException( CswEnumErrorType.Warning, "You may not change your own administrator status", "User (" + _CswNbtResources.CurrentUser.Username + ") attempted to edit the Administrator property of their own Role" ); } // case 22512 // also case 22557 - use the original name, not the new one CswNbtNodePropWrapper NamePropWrapper = Node.Properties[PropertyName.Name]; if( NamePropWrapper.GetOriginalPropRowValue( _CswNbtResources.MetaData.getFieldTypeRule( NamePropWrapper.getFieldTypeValue() ).SubFields.Default.Column ) == ChemSWAdminRoleName && _CswNbtResources.CurrentNbtUser.Username != CswNbtObjClassUser.ChemSWAdminUsername && false == ( _CswNbtResources.CurrentNbtUser is CswNbtSystemUser ) ) { throw new CswDniException( CswEnumErrorType.Warning, "The " + ChemSWAdminRoleName + " role cannot be edited", "Current user (" + _CswNbtResources.CurrentUser.Username + ") attempted to edit the '" + ChemSWAdminRoleName + "' role." ); } if( NodeTypePermissions.wasAnySubFieldModified( false ) ) { // case 25444 - was it *really* modified? CswNbtNodePropWrapper NodeTypePermissionsPropWrapper = Node.Properties[PropertyName.NodeTypePermissions]; string NodeTypePermissionsOriginalValueStr = NodeTypePermissionsPropWrapper.GetOriginalPropRowValue( CswEnumNbtPropColumn.ClobData ); CswCommaDelimitedString NodeTypePermissionsOriginalValue = new CswCommaDelimitedString(); NodeTypePermissionsOriginalValue.FromString( NodeTypePermissionsOriginalValueStr ); if( NodeTypePermissions.Value != NodeTypePermissionsOriginalValue ) { // Prevent granting permission to Design nodetypes without Design Action permission if( NodeTypePermissions.Gestalt.Contains( "Design" ) && // shortcut false == _CswNbtResources.Permit.can( CswEnumNbtActionName.Design, this ) ) { throw new CswDniException( CswEnumErrorType.Warning, "You may not grant access to Design NodeTypes without the Design Action Permission", "User (" + _CswNbtResources.CurrentUser.Username + ") attempted to grant access to Design NodeTypes on role: " + _CswNbtNode.NodeName ); } } } // case 22437 if( ActionPermissions.wasAnySubFieldModified() ) { // case 25444 - was it *really* modified? CswNbtNodePropWrapper ActionPermissionsPropWrapper = Node.Properties[PropertyName.ActionPermissions]; string ActionPermissionsOriginalValueStr = ActionPermissionsPropWrapper.GetOriginalPropRowValue( ( (CswNbtFieldTypeRuleMultiList) _CswNbtResources.MetaData.getFieldTypeRule( ActionPermissionsPropWrapper.getFieldTypeValue() ) ).ValueSubField.Column ); CswCommaDelimitedString ActionPermissionsOriginalValue = new CswCommaDelimitedString(); ActionPermissionsOriginalValue.FromString( ActionPermissionsOriginalValueStr ); if( ActionPermissions.Value != ActionPermissionsOriginalValue ) { // You can never grant your own action permissions if( _CswNbtResources.CurrentUser.RoleId == _CswNbtNode.NodeId && this.Name.Text != ChemSWAdminRoleName ) { // case 26346 - we might be trimming invalid actions out automatically, // so just throw if an action permissions is being ADDED, not removed bool ActionAdded = false; foreach( string ActionStr in ActionPermissions.Value ) { if( false == ActionPermissionsOriginalValue.Contains( ActionStr ) ) { ActionAdded = true; } } if( ActionAdded ) { throw new CswDniException( CswEnumErrorType.Warning, "You may not grant access to actions for which you have no permissions", "User (" + _CswNbtResources.CurrentUser.Username + ") attempted to edit their own action permissions on role: " + _CswNbtNode.NodeName ); } } // You can only grant action permissions on other roles to which you have access foreach( CswNbtAction Action in _CswNbtResources.Actions ) { if( true == _CswNbtResources.Permit.can( Action, this ) ) // permission is being granted { if( ( Action.Name == CswEnumNbtActionName.Design || Action.Name == CswEnumNbtActionName.Create_Inspection || //Case 24288 Action.Name == CswEnumNbtActionName.View_Scheduled_Rules ) && //Case 28564 _CswNbtResources.CurrentNbtUser.Rolename != ChemSWAdminRoleName && //Case 28433: chemsw_admin can grant Design to anyone. false == _CswNbtResources.IsSystemUser ) { // case 23677 throw new CswDniException( CswEnumErrorType.Warning, "You may not grant access to " + Action.DisplayName + " to this role", "User (" + _CswNbtResources.CurrentUser.Username + ") attempted to grant access to action " + Action.DisplayName + " to role " + _CswNbtNode.NodeName ); } //Case 29338 - If the Role has no Material NT create permissions, remove the Create Material action permission if( Action.Name == CswEnumNbtActionName.Create_Material ) { CswNbtMetaDataPropertySet MaterialPS = _CswNbtResources.MetaData.getPropertySet( CswEnumNbtPropertySetName.MaterialSet ); bool HasOneMaterialCreate = false; foreach( CswNbtMetaDataObjectClass MaterialOc in MaterialPS.getObjectClasses() ) { foreach( CswNbtMetaDataNodeType MaterialNt in MaterialOc.getNodeTypes() ) { string NodeTypePermission = MakeNodeTypePermissionValue( MaterialNt.FirstVersionNodeTypeId, CswEnumNbtNodeTypePermission.Create ); HasOneMaterialCreate = HasOneMaterialCreate || NodeTypePermissions.CheckValue( NodeTypePermission ); } } if( false == HasOneMaterialCreate ) { ActionPermissions.RemoveValue( MakeActionPermissionValue( Action ) ); } } if( false == _CswNbtResources.Permit.can( Action, _CswNbtResources.CurrentNbtUser ) ) { throw new CswDniException( CswEnumErrorType.Warning, "You may not grant access to actions for which you have no permissions", "User (" + _CswNbtResources.CurrentUser.Username + ") attempted to grant access to action " + Action.DisplayName + " to role " + _CswNbtNode.NodeName ); } } // if( true == _CswNbtResources.Permit.can( Action, this ) ) } // foreach( string ActionNameString in ActionPermissions.YValues ) } // if( ActionPermissions.Value != ActionPermissionsOriginalValue ) } // if( ActionPermissions.getAnySubFieldModified() ) }//beforeWriteNode()
// This is used by CswNbtNodeProp for unique value enforcement public void AddUniqueFilterToView(CswNbtView View, CswNbtViewProperty UniqueValueViewProperty, CswNbtNodePropWrapper PropertyValueToCheck, bool EnforceNullEntries = false, CswNbtSubField SubField = null) { if (SubField == null) { SubField = SubFields.Default; } string StringValueToCheck = PropertyValueToCheck.GetSubFieldValue(SubField); // case 31292 - Kludge fix for NodeID filters if (SubField.Name == CswEnumNbtSubFieldName.NodeID && false == string.IsNullOrEmpty(StringValueToCheck)) { CswPrimaryKey pkValue = new CswPrimaryKey(); pkValue.FromString(StringValueToCheck); StringValueToCheck = pkValue.PrimaryKey.ToString(); } CswEnumNbtFilterMode FilterMode; //case 27670 - in order to reserve the right for compound unique props to be empty, it has to be explicitly stated when creating the ForCompundUnique view if (EnforceNullEntries && String.IsNullOrEmpty(StringValueToCheck)) { FilterMode = CswEnumNbtFilterMode.Null; } else { FilterMode = CswEnumNbtFilterMode.Equals; } View.AddViewPropertyFilter(UniqueValueViewProperty, SubField.Name, FilterMode, StringValueToCheck.Trim(), false); }
} //isPropWritable private bool _isPropWritableImpl(CswNbtMetaDataNodeTypeTab MetaDataTab, CswNbtMetaDataNodeTypeProp MetaDataProp, CswNbtNodePropWrapper NodePropWrapper) { bool ret = _CswNbtPermitInfo.IsUberUser; if ((false == ret) || (MetaDataProp.ServerManaged) || ((MetaDataProp.ReadOnly) || (null != NodePropWrapper && NodePropWrapper.ReadOnly))) // case 29321 { if (_CswNbtPermitInfo.shouldPermissionCheckProceed()) { ret = _CswNbtPermitInfo.NoExceptionCases; if (ret) { if (null != MetaDataTab && false == canTab(_CswNbtPermitInfo.NodeTypePermission, _CswNbtPermitInfo.NodeType, MetaDataTab)) { ret = false; _CswNbtResources.CswLogger.reportAppState("The property " + MetaDataProp.PropName + " (" + MetaDataProp.PropId + ") has been displayed as non-editable because the viewer cannot see tab " + MetaDataTab.TabId + ".", "ReadOnlyConditions"); } else if (_CswNbtPermitInfo.NodeTypePermission == CswEnumNbtNodeTypePermission.View) { ret = false; _CswNbtResources.CswLogger.reportAppState("The property " + MetaDataProp.PropName + " (" + MetaDataProp.PropId + ") has been displayed as non-editable because the viewer does not have edit permissions on nodetype " + MetaDataProp.NodeTypeId + ".", "ReadOnlyConditions"); } else if (MetaDataProp.ServerManaged) { ret = false; _CswNbtResources.CswLogger.reportAppState("The property " + MetaDataProp.PropName + " (" + MetaDataProp.PropId + ") has been displayed as non-editable because this property is server managed.", "ReadOnlyConditions"); } else if (MetaDataProp.getFieldType().FieldType != CswEnumNbtFieldType.Button) { if (false == (MetaDataProp.IsRequired && _CswNbtResources.EditMode == CswEnumNbtNodeEditMode.Add && null != MetaDataProp.getAddLayout())) { if (MetaDataProp.ReadOnly) { ret = false; _CswNbtResources.CswLogger.reportAppState("The property " + MetaDataProp.PropName + " (" + MetaDataProp.PropId + ") has been displayed as non-editable because this property is read only.", "ReadOnlyConditions"); } else if (null != NodePropWrapper) { if (NodePropWrapper.ReadOnly) { ret = false; _CswNbtResources.CswLogger.reportAppState("The property " + MetaDataProp.PropName + " (" + MetaDataProp.PropId + ") has been displayed as non-editable because this property's nodepropwrapper is read only.", "ReadOnlyConditions"); } else if (NodePropWrapper.Node.ReadOnly) { ret = false; _CswNbtResources.CswLogger.reportAppState("The property " + MetaDataProp.PropName + " (" + MetaDataProp.PropId + ") has been displayed as non-editable because this property's nodepropwrapper's node is read only.", "ReadOnlyConditions"); } } //else if( null != NodePropWrapper ) } //if( false == ( MetaDataProp.IsRequired && _CswNbtResources.EditMode == CswEnumNbtNodeEditMode.Add && null != MetaDataProp.getAddLayout() ) } //else if MetaDataProp.getFieldType().FieldType != CswEnumNbtFieldType.Button } // if( _CswNbtPermitInfo.shouldPermissionCheckProceed() ) } } return(ret); }//_isPropWritableImpl()