Ejemplo n.º 1
0
        private static AU.AdminUnit CreateUnit(AU.AdminUnit fromUnit, string newName, string newCodeName)
        {
            AU.AdminUnit newUnit = new AU.AdminUnit();
            foreach (var item in fromUnit.Properties)
            {
                if (newUnit.Properties.ContainsKey(item.Definition.Name) == false)
                {
                    newUnit.Properties.Add(new SchemaPropertyValue(item.Definition));
                }

                newUnit.Properties.SetValue <string>(item.Definition.Name, item.StringValue);

                var ppt = newUnit.Properties[item.Definition.Name];
                if (ppt == null)
                {
                    throw new AUObjectException(string.Format("管理单元的属性:{0}不匹配", ppt.Definition.Name));
                }
                else
                {
                    ppt.StringValue = item.StringValue;
                }
            }

            newUnit.ID         = UuidHelper.NewUuidString();
            newUnit.AUSchemaID = fromUnit.AUSchemaID;
            newUnit.Name       = newName;
            newUnit.CodeName   = newCodeName;



            return(newUnit);
        }
        private void ImportOneUnit(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, Operations.IFacade exec, ImportContextWrapper wrapper, SchemaObjectBase parent, int totalSteps, AdminUnit unit)
        {
            int currentStep = 0;
            var scopes = (from m in objectSet.Membership where m.ContainerID == unit.ID && m.MemberSchemaType == AUCommon.SchemaAUAdminScope && m.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal join o in objectSet.Objects on m.ID equals o.ID where o.SchemaType == AUCommon.SchemaAUAdminScope && o.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal select (AUAdminScope)o).ToArray();
            var roles = (from m in objectSet.Membership where m.ContainerID == unit.ID && m.MemberSchemaType == AUCommon.SchemaAdminUnitRole && m.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal join o in objectSet.Objects on m.ID equals o.ID where o.SchemaType == AUCommon.SchemaAdminUnitRole && o.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal select (AURole)o).ToArray();
            try
            {
                currentStep++;
                wrapper.SetStatusAndLog(currentStep, totalSteps, "正在导入管理单元" + unit.GetQualifiedName());
                exec.AddAdminUnitWithMembers(unit, (AdminUnit)parent, roles, scopes);
                ImportRoleMembers(objectSet, exec, wrapper, totalSteps, unit, currentStep, roles);

                ImportConditions(objectSet, exec, wrapper, totalSteps, unit, currentStep, scopes);

                if (this.ImportSubUnits)
                {
                    wrapper.IncreaseLevel();
                    var subs = (from r in objectSet.Relations where r.ParentID == unit.ID && r.ChildSchemaType == AUCommon.SchemaAdminUnit && r.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal join o in objectSet.Objects on r.ID equals o.ID where o.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal && o.SchemaType == AUCommon.SchemaAdminUnit select (AdminUnit)o).ToArray();
                    int count = subs.Length;
                    foreach (AdminUnit s in subs)
                    {
                        ImportOneUnit(objectSet, exec, wrapper, unit, count, s);
                    }

                    wrapper.DecreaseLevel();
                }
            }
            catch (Exception ex)
            {
                wrapper.IncreaseError();
                wrapper.SetStatusAndLog(currentStep, totalSteps, string.Format("导入单元 {0} 失败,原因是:{1}", unit.GetQualifiedName(), ex.ToString()));
            }
        }
Ejemplo n.º 3
0
        private static void CopyRoleMembers(AU.AdminUnit fromUnit, bool copyRoleMembers, AU.AdminUnit newUnit, StepContext context)
        {
            if (copyRoleMembers)
            {
                var    roles       = AU.Adapters.AUSnapshotAdapter.Instance.LoadAURoles(new string[] { fromUnit.ID }, true, DateTime.MinValue);
                var    schemaRoles = AU.Adapters.AUSnapshotAdapter.Instance.LoadAUSchemaRoles(fromUnit.AUSchemaID, true, DateTime.MinValue);
                double allCount    = roles.Count;
                foreach (AU.AURole r in roles)
                {
                    var schemaRole = schemaRoles[r.SchemaRoleID];
                    if (schemaRole == null)
                    {
                        throw new AUObjectException(string.Format("未能找到对应角色{0}的管理架构角色{1}", r.ID, r.SchemaRoleID));
                    }

                    context.Logger.WriteLine(ProcessProgress.Current.StatusText = string.Format("正在设置管理单元角色 {0} 成员", schemaRole.Name));
                    ProcessProgress.Current.Response();
                    var targetRole = AU.Adapters.AUSnapshotAdapter.Instance.LoadAURole(r.SchemaRoleID, newUnit.ID, true, DateTime.MinValue);

                    if (targetRole != null)
                    {
                        var usersIDs = AU.AUCommon.DoDbProcess(() => PC.Adapters.SCMemberRelationAdapter.Instance.LoadByContainerID(r.ID, "Users")).FilterByStatus(SchemaObjectStatusFilterTypes.Normal).ToIDArray();

                        var users = (from p in usersIDs select new PC.SCUser()
                        {
                            ID = p, Name = "Demo", CodeName = "Demo"
                        }).ToArray();

                        AU.Operations.Facade.InstanceWithPermissions.ReplaceUsersInRole(users, newUnit, DbUtil.GetEffectiveObject <AU.AUSchemaRole>(targetRole.SchemaRoleID));
                        context.Logger.Write("已经添加{0}个人员\r\n", users.Length);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private void AddUnitToTree(AU.AdminUnit item, MCS.Web.WebControls.DeluxeTreeNodeCollection treeNodes)
 {
     treeNodes.Add(new MCS.Web.WebControls.DeluxeTreeNode(item.Name, item.ID)
     {
         NodeOpenImg           = ControlResources.OULogoUrl,
         NodeCloseImg          = ControlResources.OULogoUrl,
         CssClass              = "au-catenode",
         ChildNodesLoadingType = ChildNodesLoadingTypeDefine.LazyLoading,
         ExtendedData          = "AU"
     });
 }
 private void ImportConditions(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, Operations.IFacade exec, ImportContextWrapper wrapper, int totalSteps, AdminUnit unit, int currentStep, AUAdminScope[] scopes)
 {
     if (this.IncludeScopeConditions)
     {
         wrapper.SetStatusAndLog(currentStep, totalSteps, "正在导入管理单元管理范围条件" + unit.GetQualifiedName());
         foreach (AUAdminScope sc in scopes)
         {
             var conditions = (from c in objectSet.Conditions where c.OwnerID == sc.ID select c);
             foreach (var c in conditions)
             {
                 DBTimePointActionContext.Current.DoActions(() => exec.UpdateScopeCondition(sc, c));
             }
         }
     }
 }
Ejemplo n.º 6
0
        private static AU.AUSchemaRole DoAction(AU.AdminUnit unit, UploadProgressStatus status, StringBuilder output, AU.AUSchemaRole currentRole, Dictionary <string, object> item)
        {
            string roleID, schemaRoleID, userID;
            int    type;

            try
            {
                roleID       = (string)item["RoleID"];
                schemaRoleID = (string)item["SchemaRoleID"];
                userID       = (string)item["UserID"];
                type         = (int)item["Type"];

                if (currentRole == null || currentRole.ID != roleID)
                {
                    currentRole = DbUtil.GetEffectiveObject <AU.AUSchemaRole>(schemaRoleID);
                }

                status.StatusText = string.Format("正在向角色{0}{1}用户{2}", roleID, type == 0 ? "添加" : "删除", userID);
                output.AppendLine(status.StatusText);


                if (type == 0)
                {
                    AU.Operations.Facade.InstanceWithPermissions.AddUserToRole(new PC.SCUser()
                    {
                        ID = userID
                    }, unit, currentRole);
                }
                else
                {
                    AU.Operations.Facade.InstanceWithPermissions.RemoveUserFromRole(new PC.SCUser()
                    {
                        ID = userID, CodeName = "abc", Name = "abc"
                    }, unit, currentRole);
                }
            }
            catch (Exception ex)
            {
                status.StatusText = ex.Message;
                output.AppendLine(ex.ToString());
            }
            return(currentRole);
        }
Ejemplo n.º 7
0
		private static void ValidateName(string name, string codeName, ValidationResult result, AUSchema schema, SchemaObjectBase targetUnit)
		{
			var actualParent = (SchemaObjectBase)targetUnit ?? schema;

			var adminUnit = new AdminUnit()
			{
				ID = UuidHelper.NewUuidString(),
				CodeName = codeName,
				Name = name,
				AUSchemaID = schema.ID
			};

			var validationObjResult = adminUnit.Validate();
			result.ObjectValidationResult = validationObjResult.ResultCount > 0 ? ToMessage(validationObjResult.First()) : "通过";
			result.Passed &= validationObjResult.ResultCount == 0;

			if (result.Passed)
			{
				SCRelationObject relation = new SCRelationObject(actualParent, adminUnit);
				var existedObj = AU.Adapters.AUSnapshotAdapter.Instance.LoadAUByChildName(name, actualParent.ID, AUCommon.SchemaAdminUnit, true, DateTime.MinValue);
				result.NameValidationResult = existedObj.Count > 0 ? "此名称已经被占用,请使用其他名称" : "通过";
				result.Passed &= existedObj.Count == 0;
			}
		}
Ejemplo n.º 8
0
 protected override void OnIDChanged()
 {
     base.OnIDChanged();
     owner = null;
 }
Ejemplo n.º 9
0
 private void ImportConditions(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, Operations.IFacade exec, ImportContextWrapper wrapper, int totalSteps, AdminUnit unit, int currentStep, AUAdminScope[] scopes)
 {
     if (this.IncludeScopeConditions)
     {
         wrapper.SetStatusAndLog(currentStep, totalSteps, "正在导入管理单元管理范围条件" + unit.GetQualifiedName());
         foreach (AUAdminScope sc in scopes)
         {
             var conditions = (from c in objectSet.Conditions where c.OwnerID == sc.ID select c);
             foreach (var c in conditions)
             {
                 DBTimePointActionContext.Current.DoActions(() => exec.UpdateScopeCondition(sc, c));
             }
         }
     }
 }
Ejemplo n.º 10
0
        private void ImportOneUnit(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, Operations.IFacade exec, ImportContextWrapper wrapper, SchemaObjectBase parent, int totalSteps, AdminUnit unit)
        {
            int currentStep = 0;
            var scopes      = (from m in objectSet.Membership where m.ContainerID == unit.ID && m.MemberSchemaType == AUCommon.SchemaAUAdminScope && m.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal join o in objectSet.Objects on m.ID equals o.ID where o.SchemaType == AUCommon.SchemaAUAdminScope && o.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal select(AUAdminScope) o).ToArray();
            var roles       = (from m in objectSet.Membership where m.ContainerID == unit.ID && m.MemberSchemaType == AUCommon.SchemaAdminUnitRole && m.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal join o in objectSet.Objects on m.ID equals o.ID where o.SchemaType == AUCommon.SchemaAdminUnitRole && o.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal select(AURole) o).ToArray();

            try
            {
                currentStep++;
                wrapper.SetStatusAndLog(currentStep, totalSteps, "正在导入管理单元" + unit.GetQualifiedName());
                exec.AddAdminUnitWithMembers(unit, (AdminUnit)parent, roles, scopes);
                ImportRoleMembers(objectSet, exec, wrapper, totalSteps, unit, currentStep, roles);

                ImportConditions(objectSet, exec, wrapper, totalSteps, unit, currentStep, scopes);

                if (this.ImportSubUnits)
                {
                    wrapper.IncreaseLevel();
                    var subs  = (from r in objectSet.Relations where r.ParentID == unit.ID && r.ChildSchemaType == AUCommon.SchemaAdminUnit && r.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal join o in objectSet.Objects on r.ID equals o.ID where o.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal && o.SchemaType == AUCommon.SchemaAdminUnit select(AdminUnit) o).ToArray();
                    int count = subs.Length;
                    foreach (AdminUnit s in subs)
                    {
                        ImportOneUnit(objectSet, exec, wrapper, unit, count, s);
                    }

                    wrapper.DecreaseLevel();
                }
            }
            catch (Exception ex)
            {
                wrapper.IncreaseError();
                wrapper.SetStatusAndLog(currentStep, totalSteps, string.Format("导入单元 {0} 失败,原因是:{1}", unit.GetQualifiedName(), ex.ToString()));
            }
        }
Ejemplo n.º 11
0
 private void ImportRoleMembers(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, Operations.IFacade exec, ImportContextWrapper wrapper, int totalSteps, AdminUnit unit, int currentStep, AURole[] roles)
 {
     if (this.IncludeRoleMembers)
     {
         wrapper.SetStatusAndLog(currentStep, totalSteps, "正在替换管理单元角色成员" + unit.GetQualifiedName());
         foreach (AURole role in roles)
         {
             var userIDS    = (from c in objectSet.Membership where c.ContainerID == role.ID && c.MemberSchemaType == "Users" && c.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal select c.ID).ToArray();
             var users      = MCS.Library.OGUPermission.OguMechanismFactory.GetMechanism().GetObjects <IUser>(SearchOUIDType.Guid, userIDS);
             var scUsers    = (from u in users select new SCUser()
             {
             }).ToArray();
             var schemaRole = AUCommon.DoDbProcess <AUSchemaRole>(() => (AUSchemaRole)PC.Adapters.SchemaObjectAdapter.Instance.Load(role.SchemaRoleID));
             exec.ReplaceUsersInRole(scUsers, unit, schemaRole);
         }
     }
 }
Ejemplo n.º 12
0
        private static void DoCopyUnit(StepContext context, AU.AdminUnit fromUnit, AU.AdminUnit targetParent, string newName, string newCodeName, bool copyRoleMembers, bool copyScopeMembers, bool copyScopeConditions)
        {
            AU.AdminUnit newUnit = CreateUnit(fromUnit, newName, newCodeName);

            int totalSteps = 1;

            if (copyRoleMembers)
            {
                totalSteps++;
            }
            if (copyScopeConditions)
            {
                totalSteps++;
            }
            if (copyScopeMembers)
            {
                totalSteps++;
            }

            context.TotalSteps  = totalSteps;
            context.PassedSteps = 0;
            context.Div         = 100.0 / totalSteps;

            ProcessProgress.Current.MinStep     = 1;
            ProcessProgress.Current.CurrentStep = 1;
            ProcessProgress.Current.MaxStep     = 100;

            context.Logger.WriteLine(ProcessProgress.Current.StatusText = "正在添加管理单元");

            AU.Operations.Facade.InstanceWithPermissions.AddAdminUnit(newUnit, targetParent);
            context.ResetInnerSteps();
            context.PassedSteps++;
            context.Response();

            CopyRoleMembers(fromUnit, copyRoleMembers, newUnit, context);
            context.PassedSteps++;
            context.ResetInnerSteps();
            context.Response();

            if (copyScopeMembers || copyScopeConditions)
            {
                var srcScopes = fromUnit.GetNormalScopes();
                var scopes    = newUnit.GetNormalScopes();

                if (copyScopeMembers)
                {
                    foreach (AU.AUAdminScope srcScope in srcScopes)
                    {
                        var targetScope = scopes.GetScope(srcScope.ScopeSchemaType);
                        if (targetScope != null)
                        {
                            CopyMembers(copyScopeMembers, srcScope, targetScope, context);
                        }
                    }
                    context.PassedSteps++;
                    context.ResetInnerSteps();
                    context.Response();
                }

                if (copyScopeConditions)
                {
                    foreach (AU.AUAdminScope srcScope in srcScopes)
                    {
                        var targetScope = scopes.GetScope(srcScope.ScopeSchemaType);
                        if (targetScope != null)
                        {
                            CopyConditions(copyScopeConditions, srcScope, targetScope, context);
                            context.PassedSteps++;
                            context.ResetInnerSteps();
                            context.Response();
                        }
                    }
                    context.PassedSteps++;
                    context.ResetInnerSteps();
                }
            }
        }
 private void ImportRoleMembers(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, Operations.IFacade exec, ImportContextWrapper wrapper, int totalSteps, AdminUnit unit, int currentStep, AURole[] roles)
 {
     if (this.IncludeRoleMembers)
     {
         wrapper.SetStatusAndLog(currentStep, totalSteps, "正在替换管理单元角色成员" + unit.GetQualifiedName());
         foreach (AURole role in roles)
         {
             var userIDS = (from c in objectSet.Membership where c.ContainerID == role.ID && c.MemberSchemaType == "Users" && c.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal select c.ID).ToArray();
             var users = MCS.Library.OGUPermission.OguMechanismFactory.GetMechanism().GetObjects<IUser>(SearchOUIDType.Guid, userIDS);
             var scUsers = (from u in users select new SCUser() { }).ToArray();
             var schemaRole = AUCommon.DoDbProcess<AUSchemaRole>(() => (AUSchemaRole)PC.Adapters.SchemaObjectAdapter.Instance.Load(role.SchemaRoleID));
             exec.ReplaceUsersInRole(scUsers, unit, schemaRole);
         }
     }
 }
Ejemplo n.º 14
0
		private static bool CheckAddSubPermission(AUSchema schema, AdminUnit targetUnit)
		{
			bool result = false;

			result = AU.AUPermissionHelper.IsSupervisor(DeluxePrincipal.Current);
			if (result == false)
			{
				if (string.IsNullOrEmpty(schema.MasterRole) == false)
				{
					result = DeluxePrincipal.Current.IsInRole(schema.MasterRole);

					if (result == false && targetUnit != null)
					{
						var permissions = AU.Adapters.AUAclAdapter.Instance.LoadCurrentContainerAndPermissions(DeluxeIdentity.CurrentUser.ID, new string[] { targetUnit.ID });

						result = Util.ContainsPermission(permissions, targetUnit.ID, "AddSubUnit");
					}
				}
			}

			return result;
		}
		private void DeterminPermission(AUSchema schema, AdminUnit unit)
		{
			bool editEnabled = TimePointContext.Current.UseCurrentTime;
			if (editEnabled)
			{
				if (Util.SuperVisiorMode == false)
				{
					if (string.IsNullOrEmpty(schema.MasterRole) == false)
					{
						editEnabled = DeluxePrincipal.Current.IsInRole(schema.MasterRole);

						if (editEnabled == false)
						{
							var permissions = AU.Adapters.AUAclAdapter.Instance.LoadCurrentContainerAndPermissions(DeluxeIdentity.CurrentUser.ID, new string[] { unit.ID });

							editEnabled = Util.ContainsPermission(permissions, unit.ID, "EditAdminScope"); ;
						}
					}
				}
			}

			this.EditEnabled = editEnabled;
		}
Ejemplo n.º 16
0
		private static AU.AdminUnit CreateUnit(AU.AdminUnit fromUnit, string newName, string newCodeName)
		{
			AU.AdminUnit newUnit = new AU.AdminUnit();
			foreach (var item in fromUnit.Properties)
			{
				if (newUnit.Properties.ContainsKey(item.Definition.Name) == false)
					newUnit.Properties.Add(new SchemaPropertyValue(item.Definition));

				newUnit.Properties.SetValue<string>(item.Definition.Name, item.StringValue);

				var ppt = newUnit.Properties[item.Definition.Name];
				if (ppt == null)
					throw new AUObjectException(string.Format("管理单元的属性:{0}不匹配", ppt.Definition.Name));
				else
					ppt.StringValue = item.StringValue;
			}

			newUnit.ID = UuidHelper.NewUuidString();
			newUnit.AUSchemaID = fromUnit.AUSchemaID;
			newUnit.Name = newName;
			newUnit.CodeName = newCodeName;



			return newUnit;
		}
Ejemplo n.º 17
0
		protected override void OnIDChanged()
		{
			base.OnIDChanged();
			owner = null;
		}