Esempio n. 1
0
        public SchemaObjectBase DeleteOrganization(SCOrganization org, SCOrganization parent, bool deletedByContainer)
        {
            if (parent == null)
            {
                parent = (SCOrganization)org.CurrentParents.FirstOrDefault();
            }

            (parent != null).FalseThrow("不能找到ID为{0}的父对象", org.ID);

            CheckOrganizationChildrenPermissions(SCOperationType.DeleteOrganization, "DeleteChildren", parent);

            SCOrganizationRelativeExecutor executor
                = new SCOrganizationRelativeExecutor(SCOperationType.DeleteOrganization, parent, org)
                {
                NeedValidation = false, NeedDeleteRelations = true, SaveTargetData = true, OverrideExistedRelation = true, NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck
                };

            executor.Relation.Status = SchemaObjectStatus.Deleted;
            org.Status = deletedByContainer ? SchemaObjectStatus.DeletedByContainer : SchemaObjectStatus.Deleted;;

            SchemaObjectBase result = null;

            ExecuteWithActions(SCOperationType.DeleteOrganization, () => SCActionContext.Current.DoActions(() => result = (SchemaObjectBase)executor.Execute()));

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 设置用户的默认组织
        /// </summary>
        /// <param name="user"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public SCRelationObject SetUserDefaultOrganization(SCUser user, SCOrganization parent)
        {
            SCOrganizationRelativeExecutor executor =
                new SCOrganizationRelativeExecutor(SCOperationType.SetUserDefaultOrganization, parent, user)
            {
                OverrideExistedRelation = true, OverrideDefault = true, NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck
            };

            SCRelationObject result = executor.Relation;

            if (executor.RelationExisted)
            {
                if (this._NeedCheckPermissions)
                {
                    var currentDefault = user.CurrentParentRelations.Where(r => r.Default && r.Status == SchemaObjectStatus.Normal).FirstOrDefault();
                    if (currentDefault != null)
                    {
                        CheckPermissions(SCOperationType.SetUserDefaultOrganization, SchemaDefine.GetSchema("Organizations"), "UpdateChildren", currentDefault.ParentID);
                    }

                    CheckPermissions(SCOperationType.SetUserDefaultOrganization, SchemaDefine.GetSchema("Organizations"), "UpdateChildren", executor.Relation.ParentID);
                }

                executor.Relation.Default = true;
                ExecuteWithActions(SCOperationType.SetUserDefaultOrganization, () => SCActionContext.Current.DoActions(() => result = (SCRelationObject)executor.Execute()));
            }

            return(result);
        }
Esempio n. 3
0
        public SchemaObjectBase AddUser(SCUser user, SCOrganization parent)
        {
            SCObjectExecutor executor = null;

            if (parent == null)
            {
                if (this._NeedCheckPermissions)
                {
                    CheckSupervisorPermissions(SCOperationType.AddUser);
                }

                executor = new SCObjectExecutor(SCOperationType.AddUser, user)
                {
                    NeedValidation = this.NeedValidationAndStatusCheck
                };
            }
            else
            {
                if (this._NeedCheckPermissions)
                {
                    CheckPermissions(SCOperationType.AddUser, parent.Schema, "AddChildren", parent.ID);
                }

                executor = new SCOrganizationRelativeExecutor(SCOperationType.AddUser, parent, user)
                {
                    SaveTargetData = true, NeedValidation = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck
                };
            }

            SchemaObjectBase result = null;

            ExecuteWithActions(SCOperationType.AddUser, () => SCActionContext.Current.DoActions(() => result = (SchemaObjectBase)executor.Execute()));

            return(result);
        }
Esempio n. 4
0
        public SchemaObjectBase DeleteUser(SCUser user, SCOrganization parent, bool deletedByContainer)
        {
            SchemaObjectStatus targetStatus = deletedByContainer ? SchemaObjectStatus.DeletedByContainer : SchemaObjectStatus.Deleted;
            SCOperationType    op           = SCOperationType.None;

            SCExecutorBase executor = null;

            if (parent == null)
            {
                op = SCOperationType.DeleteUser;

                if (this._NeedCheckPermissions)
                {
                    CheckPermissions(op, SchemaDefine.GetSchema("Organizations"), "DeleteChildren", user.OwnerID);
                }

                user.Status = targetStatus;

                executor = new SCObjectExecutor(op, user)
                {
                    NeedDeleteRelations = true, NeedValidation = false, NeedDeleteMemberRelations = this.NeedValidationAndStatusCheck, NeedStatusCheck = this.NeedValidationAndStatusCheck
                };
            }
            else
            {
                op = SCOperationType.RemoveUserFromOrganization;

                if (this._NeedCheckPermissions)
                {
                    CheckPermissions(op, parent.Schema, "DeleteChildren", parent.ID);
                }

                executor = new SCOrganizationRelativeExecutor(op, parent, user)
                {
                    OverrideExistedRelation = true, NeedValidation = false, NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck
                };

                if (((SCOrganizationRelativeExecutor)executor).Relation != null)
                {
                    ((SCOrganizationRelativeExecutor)executor).Relation.Status = targetStatus;
                }
            }

            SchemaObjectBase result = null;

            ExecuteWithActions(op, () => SCActionContext.Current.DoActions(() => result = (SchemaObjectBase)executor.Execute()));

            return(result);
        }
Esempio n. 5
0
        public SCRelationObject AddOrganization(SCOrganization org, SCOrganization parent)
        {
            SCOrganizationRelativeExecutor executor =
                new SCOrganizationRelativeExecutor(SCOperationType.AddOrganization, parent, org)
            {
                SaveTargetData = true, NeedValidation = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck, NeedDuplicateRelationCheck = this.NeedValidationAndStatusCheck
            };

            CheckPermissions(SCOperationType.AddOrganization, parent.Schema, "AddChildren", parent.ID);

            SCRelationObject result = null;

            ExecuteWithActions(SCOperationType.AddOrganization, () => SCActionContext.Current.DoActions(() => result = (SCRelationObject)executor.Execute()));

            return(result);
        }
Esempio n. 6
0
        public SchemaObjectBase AddGroup(SCGroup group, SCOrganization parent)
        {
            SCOrganizationRelativeExecutor executor =
                new SCOrganizationRelativeExecutor(SCOperationType.AddGroup, parent, group)
            {
                SaveTargetData = true, NeedValidation = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck, NeedDuplicateRelationCheck = this.NeedValidationAndStatusCheck
            };

            if (this._NeedCheckPermissions)
            {
                CheckPermissions(SCOperationType.AddGroup, parent.Schema, "AddChildren", parent.ID);
            }

            SCRelationObject result = null;

            ExecuteWithActions(SCOperationType.AddGroup, () => SCActionContext.Current.DoActions(() => result = (SCRelationObject)executor.Execute()));

            return(result);
        }
Esempio n. 7
0
        public SCRelationObject AddUserToOrganization(SCUser user, SCOrganization parent)
        {
            user.NullCheck("user");
            parent.NullCheck("parent");

            SCOrganizationRelativeExecutor executor =
                new SCOrganizationRelativeExecutor(SCOperationType.AddUserToOrganization, parent, user)
            {
                NeedValidation = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck
            };

            if (this._NeedCheckPermissions)
            {
                CheckPermissions(SCOperationType.AddUserToOrganization, parent.Schema, "AddChildren", parent.ID);
            }

            SCRelationObject result = null;

            ExecuteWithActions(SCOperationType.AddUserToOrganization, () => SCActionContext.Current.DoActions(() => result = (SCRelationObject)executor.Execute()));

            return(result);
        }
		public SchemaObjectBase AddGroup(SCGroup group, SCOrganization parent)
		{
			SCOrganizationRelativeExecutor executor =
				new SCOrganizationRelativeExecutor(SCOperationType.AddGroup, parent, group) { SaveTargetData = true, NeedValidation = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck, NeedDuplicateRelationCheck = this.NeedValidationAndStatusCheck };

			if (this._NeedCheckPermissions)
				CheckPermissions(SCOperationType.AddGroup, parent.Schema, "AddChildren", parent.ID);

			SCRelationObject result = null;

			ExecuteWithActions(SCOperationType.AddGroup, () => SCActionContext.Current.DoActions(() => result = (SCRelationObject)executor.Execute()));

			return result;
		}
		public SchemaObjectBase DeleteOrganization(SCOrganization org, SCOrganization parent, bool deletedByContainer)
		{
			if (parent == null)
				parent = (SCOrganization)org.CurrentParents.FirstOrDefault();

			(parent != null).FalseThrow("不能找到ID为{0}的父对象", org.ID);

			CheckOrganizationChildrenPermissions(SCOperationType.DeleteOrganization, "DeleteChildren", parent);

			SCOrganizationRelativeExecutor executor
				= new SCOrganizationRelativeExecutor(SCOperationType.DeleteOrganization, parent, org) { NeedValidation = false, NeedDeleteRelations = true, SaveTargetData = true, OverrideExistedRelation = true, NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck };

			executor.Relation.Status = SchemaObjectStatus.Deleted;
			org.Status = deletedByContainer ? SchemaObjectStatus.DeletedByContainer : SchemaObjectStatus.Deleted; ;

			SchemaObjectBase result = null;

			ExecuteWithActions(SCOperationType.DeleteOrganization, () => SCActionContext.Current.DoActions(() => result = (SchemaObjectBase)executor.Execute()));

			return result;
		}
		public SCRelationObject AddUserToOrganization(SCUser user, SCOrganization parent)
		{
			user.NullCheck("user");
			parent.NullCheck("parent");

			SCOrganizationRelativeExecutor executor =
				new SCOrganizationRelativeExecutor(SCOperationType.AddUserToOrganization, parent, user) { NeedValidation = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck };

			if (this._NeedCheckPermissions)
				CheckPermissions(SCOperationType.AddUserToOrganization, parent.Schema, "AddChildren", parent.ID);

			SCRelationObject result = null;

			ExecuteWithActions(SCOperationType.AddUserToOrganization, () => SCActionContext.Current.DoActions(() => result = (SCRelationObject)executor.Execute()));

			return result;
		}
		/// <summary>
		/// 设置用户的默认组织
		/// </summary>
		/// <param name="user"></param>
		/// <param name="parent"></param>
		/// <returns></returns>
		public SCRelationObject SetUserDefaultOrganization(SCUser user, SCOrganization parent)
		{
			SCOrganizationRelativeExecutor executor =
				new SCOrganizationRelativeExecutor(SCOperationType.SetUserDefaultOrganization, parent, user) { OverrideExistedRelation = true, OverrideDefault = true, NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck };

			SCRelationObject result = executor.Relation;

			if (executor.RelationExisted)
			{
				if (this._NeedCheckPermissions)
				{
					var currentDefault = user.CurrentParentRelations.Where(r => r.Default && r.Status == SchemaObjectStatus.Normal).FirstOrDefault();
					if (currentDefault != null)
					{
						CheckPermissions(SCOperationType.SetUserDefaultOrganization, SchemaDefine.GetSchema("Organizations"), "UpdateChildren", currentDefault.ParentID);
					}

					CheckPermissions(SCOperationType.SetUserDefaultOrganization, SchemaDefine.GetSchema("Organizations"), "UpdateChildren", executor.Relation.ParentID);
				}

				executor.Relation.Default = true;
				ExecuteWithActions(SCOperationType.SetUserDefaultOrganization, () => SCActionContext.Current.DoActions(() => result = (SCRelationObject)executor.Execute()));
			}

			return result;
		}
		public SchemaObjectBase DeleteUser(SCUser user, SCOrganization parent, bool deletedByContainer)
		{
			SchemaObjectStatus targetStatus = deletedByContainer ? SchemaObjectStatus.DeletedByContainer : SchemaObjectStatus.Deleted;
			SCOperationType op = SCOperationType.None;

			SCExecutorBase executor = null;

			if (parent == null)
			{
				op = SCOperationType.DeleteUser;

				if (this._NeedCheckPermissions)
					CheckPermissions(op, SchemaDefine.GetSchema("Organizations"), "DeleteChildren", user.OwnerID);

				user.Status = targetStatus;

				executor = new SCObjectExecutor(op, user) { NeedDeleteRelations = true, NeedValidation = false, NeedDeleteMemberRelations = this.NeedValidationAndStatusCheck, NeedStatusCheck = this.NeedValidationAndStatusCheck };
			}
			else
			{
				op = SCOperationType.RemoveUserFromOrganization;

				if (this._NeedCheckPermissions)
					CheckPermissions(op, parent.Schema, "DeleteChildren", parent.ID);

				executor = new SCOrganizationRelativeExecutor(op, parent, user) { OverrideExistedRelation = true, NeedValidation = false, NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck };

				if (((SCOrganizationRelativeExecutor)executor).Relation != null)
					((SCOrganizationRelativeExecutor)executor).Relation.Status = targetStatus;
			}

			SchemaObjectBase result = null;

			ExecuteWithActions(op, () => SCActionContext.Current.DoActions(() => result = (SchemaObjectBase)executor.Execute()));

			return result;
		}
		public SchemaObjectBase AddUser(SCUser user, SCOrganization parent)
		{
			SCObjectExecutor executor = null;

			if (parent == null)
			{
				if (this._NeedCheckPermissions)
					CheckSupervisorPermissions(SCOperationType.AddUser);

				executor = new SCObjectExecutor(SCOperationType.AddUser, user) { NeedValidation = this.NeedValidationAndStatusCheck };
			}
			else
			{
				if (this._NeedCheckPermissions)
					CheckPermissions(SCOperationType.AddUser, parent.Schema, "AddChildren", parent.ID);

				executor = new SCOrganizationRelativeExecutor(SCOperationType.AddUser, parent, user) { SaveTargetData = true, NeedValidation = this.NeedValidationAndStatusCheck, NeedParentStatusCheck = this.NeedValidationAndStatusCheck };
			}

			SchemaObjectBase result = null;

			ExecuteWithActions(SCOperationType.AddUser, () => SCActionContext.Current.DoActions(() => result = (SchemaObjectBase)executor.Execute()));

			return result;
		}