public bool MemberCanAddAssets(Guid userId, Guid assetTypeId, EXObjectRequestType requestType) { if (requestType == EXObjectRequestType.Both) { throw new LogicalException("Request must be for adding instances or adding definitions"); } StringBuilder sql = new StringBuilder(); sql.AppendLine("select COUNT(RATP.[Id])"); sql.AppendLine("FROM [RolesAssetTypesPermissions] RATP WITH (NoLock)"); sql.AppendLine("INNER JOIN [Permissions] P WITH (NoLock) ON P.[Id] = RATP.[PermissionId]"); sql.AppendLine("INNER JOIN [RolesMembers] RM WITH (NoLock) ON RM.[RoleId] = RATP.[RoleId]"); sql.AppendLine("WHERE RM.[MemberId] = @UserId"); sql.AppendLine("AND RM.[Deleted] IS NULL"); sql.AppendLine("AND RATP.[Deleted] IS NULL"); sql.AppendLine("AND P.[Value] = @PermissionId"); sql.AppendLine("AND RATP.[AssetTypeId] = @AssetTypeId"); List <SqlParameter> paramList = new List <SqlParameter>(); paramList.Add(new SqlParameter("@AssetTypeId", assetTypeId)); paramList.Add(new SqlParameter("@UserId", userId)); if (requestType == EXObjectRequestType.Definition) { paramList.Add(new SqlParameter("@PermissionId", EPermissionType.Create.GetHashCode())); } else if (requestType == EXObjectRequestType.Instance) { paramList.Add(new SqlParameter("@PermissionId", EPermissionType.Create.GetHashCode())); } return(base.ExecuteScalarInLine(sql.ToString(), paramList) > 0); }
public XRoleHelper(Guid roleId, string roleName, Guid atId, EXObjectRequestType requestType) { this.RoleId = roleId; this.RoleName = roleName; this.AssetTypeId = atId; this.RequestType = requestType; }
public bool HasAssets(Guid assetTypeId, EXObjectRequestType requestType) { List <SqlParameter> paramList = new List <SqlParameter>(); paramList.Add(new SqlParameter("@AssetTypeId", assetTypeId)); paramList.Add(new SqlParameter("@IsInstance", (requestType == EXObjectRequestType.Instance))); return(base.ExecuteScalar(StoredProcs.AssetType_HasAssets, paramList) > 0); }
public static EXObjectRequestType EAssetRequestTypeFromValue(int value) { foreach (EXObjectRequestType item in EXObjectRequestType.GetValues(typeof(EXObjectRequestType))) { if (item.GetHashCode() == value) { return(item); } } throw new Exception("Invalid value for EAssetRequestType"); }
/// <summary> /// Whether or not the specified role has a certain permission to a particual assetType (instance or def) /// </summary> /// <param name="roleId">id of the role to check</param> /// <param name="assetTypeId">id of the assetType to check</param> /// <param name="requestType"></param> /// <param name="permission">id of the permission type we are looking for</param> /// <returns></returns> public bool HasPermission(Guid roleId, Guid assetTypeId, EXObjectRequestType requestType, EPermissionType permission) { List <SqlParameter> paramList = new List <SqlParameter>(); paramList.Add(new SqlParameter("@RoleId", roleId)); paramList.Add(new SqlParameter("@AssetTypeId", assetTypeId)); paramList.Add(new SqlParameter("@IsInstance", requestType == EXObjectRequestType.Instance)); paramList.Add(new SqlParameter("@PermissionId", permission.GetHashCode())); return(base.ExecuteScalar(StoredProcs.Role_HasPermission, paramList) > 0); }
public IDictionary <Guid, Guid> AssetTypes_GetDefaultViews(Guid userId, EXObjectRequestType requestType) { throw new Exception("NOT IMPLEMENTED"); //if (new MemberLayer().IsAdmin(userId)) //{ // return this.dal.AssetTypes_GetDefaultViews(null, requestType); //} //else //{ // return this.dal.AssetTypes_GetDefaultViews(userId, requestType); //} }
public bool HasAssets(Guid assetTypeId, EXObjectRequestType requestType, bool searchChildAssetTypes) { bool hasAssets = this.dal.HasAssets(assetTypeId, requestType); if (!hasAssets && searchChildAssetTypes) { IList <Guid> childAssetTypeIds = this.AssetType_GetChildren(assetTypeId, true); foreach (Guid childId in childAssetTypeIds) { hasAssets = this.dal.HasAssets(childId, requestType); if (hasAssets) { break; } } } return(hasAssets); }
/// <summary> /// Gets a list of all properties that rely on an external source for their values (i.e. picklists, those that represent roles) /// This would exclude types such as int, float, datetime, etc. If the user can type a value into the property, it is not /// a free-entry property and as such will not be returned in this list /// </summary> /// <param name="assetTypeIds"></param> /// <param name="includeInheritedPropeties"></param> /// <returns></returns> public IDictionary <Guid, string> Properties_GetNonFreeEntry(List <Guid> assetTypeIds, EXObjectRequestType requestType, bool includeInheritedPropeties) { if ((assetTypeIds == null) || (assetTypeIds.Count == 0)) { return(new Dictionary <Guid, string>()); } StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT DISTINCT P.[Id],"); sql.AppendLine("ISNULL(p.[DisplayValue], p.[Name]) as [Property Name]"); sql.AppendLine("FROM [Properties] P WITH (NoLock)"); sql.AppendLine("INNER JOIN [AssetTypesProperties] ATP WITH (NoLock) ON ATP.[PropertyId] = P.[Id]"); sql.AppendLine("WHERE ATP.[AssetTypeId] IN ("); List <Guid> allAssetTypeIds = new List <Guid>(); foreach (Guid id in assetTypeIds) { allAssetTypeIds.Add(id); } if (includeInheritedPropeties) { foreach (Guid assetTypeId in assetTypeIds) { Guid?parentAssetTypeId = new XObjectTypeRepository <XObjectType>().ParentId(assetTypeId); while (parentAssetTypeId.HasValue) { if (!assetTypeIds.Contains(parentAssetTypeId.Value)) { allAssetTypeIds.Add(parentAssetTypeId.Value); } parentAssetTypeId = new XObjectTypeRepository <XObjectType>().ParentId(parentAssetTypeId.Value); } } } var index = 0; var atIdCount = allAssetTypeIds.Count; foreach (var assetTypeId in allAssetTypeIds) { if (index == (atIdCount - 1)) { sql.AppendLine("'" + assetTypeId.ToString() + "'"); } else { sql.AppendLine("'" + assetTypeId.ToString() + "',"); } index++; } sql.AppendLine(")"); sql.AppendLine("AND (P.[DataTypeId] NOT IN (2, 3, 4, 5, 7, 10, 12, 21, 22, 24, 25))"); sql.AppendLine("AND (P.[Deleted] IS NULL)"); sql.AppendLine("AND ([ATP].[Deleted] IS NULL)"); if (requestType == EXObjectRequestType.Definition) { sql.AppendLine("AND ([ATP].[IsInstance] = 0)"); } sql.AppendLine("ORDER BY [Property Name]"); Dictionary <Guid, string> values = new Dictionary <Guid, string>(); using (SqlDataReader rdr = base.OpenDataReaderInLine(sql.ToString(), new List <SqlParameter>())) { if ((rdr != null) && (rdr.HasRows)) { while (rdr.Read()) { values.Add(rdr.GetGuid(0), rdr.GetString(1)); } } } return(values); }