//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); } }
} // 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()
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()
}//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()
} // 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(); } }
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()