public AURoleMemberExecutor(AUOperationType opType, AUSchemaRole role, AdminUnit unit, SCUser[] users)
			: base(opType)
		{
			role.NullCheck("role");
			users.NullCheck("users");
			unit.NullCheck("unit");
			this.schemaRole = role;
			this.users = users;
			this.unit = unit;
		}
Exemplo n.º 2
0
		public void SchemaUserToXml()
		{
			SCUser user = SCObjectGenerator.PrepareUserObject();

			XElement userElem = new XElement("Root").AddChildElement("Object");

			user.ToXElement(userElem);

			Console.WriteLine(userElem.Parent.ToString());

			SCUser userDeserialized = new SCUser();

			userDeserialized.FromXElement(userElem);

			Assert.AreEqual(user.ID, userDeserialized.ID);
			Assert.AreEqual(user.Name, userDeserialized.Name);
			Assert.AreEqual(user.FirstName, userDeserialized.FirstName);
			Assert.AreEqual(user.LastName, userDeserialized.LastName);
		}
		private static SCRelationObject UpdateRelation(SCOrganization org, SCUser user)
		{
			SCOrganization root = SCOrganization.GetRoot();

			SCRelationObject orgRelation = new SCRelationObject(root, org);

			SCRelationObject relation = new SCRelationObject(org, user);

			SCActionContext.Current.DoActions(() =>
			{
				using (TransactionScope scope = TransactionScopeFactory.Create())
				{
					SchemaObjectAdapter.Instance.Update(org);
					SchemaRelationObjectAdapter.Instance.Update(orgRelation);
					SchemaObjectAdapter.Instance.Update(user);
					SchemaRelationObjectAdapter.Instance.Update(relation);

					scope.Complete();
				}
			});

			return relation;
		}
Exemplo n.º 4
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;
		}
Exemplo n.º 5
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;
		}
Exemplo n.º 6
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;
		}
Exemplo n.º 7
0
		public SchemaObjectBase UpdateUser(SCUser user)
		{
			SCObjectExecutor executor = new SCObjectExecutor(SCOperationType.UpdateUser, user) { NeedValidation = this.NeedValidationAndStatusCheck, NeedStatusCheck = this.NeedValidationAndStatusCheck };

			if (this._NeedCheckPermissions)
			{
				var defOrgRelation = (user.CurrentParentRelations.Find(m => m.Default)) ?? new SCRelationObject(SCOrganization.GetRoot(), user);
				CheckPermissions(SCOperationType.UpdateUser, user.Schema, "UpdateChildren", defOrgRelation.ParentID);
			}

			SchemaObjectBase result = null;

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

			return result;
		}
		public void RemoveUserFromRole(ClientGenericObject user, ClientAdminUnit unit, ClientAUSchemaRole role)
		{
			user.NullCheck("user"); unit.NullCheck("unit"); role.NullCheck("role");
			CheckIDProvided(user); CheckIDProvided(unit); CheckIDProvided(role);

			SCUser scUser = new SCUser()
			{
				ID = user.ID,
				Name = user.Properties.GetValue("Name", string.Empty),
				CodeName = user.Properties.GetValue("CodeName", string.Empty)
			};

			this.Facade.RemoveUserFromRole(scUser, (AdminUnit)unit.ToSchemaObject(), (AUSchemaRole)role.ToSchemaObject());
		}
Exemplo n.º 9
0
		public void RemoveUserFromRole(SCUser user, AdminUnit unit, AUSchemaRole role)
		{
			CheckUnitPermission(AUOperationType.RemoveUserFromRole, "EditRoleMembers", unit);

			SchemaObjectBase r = Adapters.AUSnapshotAdapter.Instance.LoadAURole(role.ID, unit.ID, true, DateTime.MinValue);
			if (r == null)
				throw new AUObjectValidationException("没有找到此管理单元的角色,请尝试重新添加此角色");

			AUMemberRelativeExecutor executor = new AUMemberRelativeExecutor(AUOperationType.RemoveUserFromRole, r, user)
			{
				OverrideExistedRelation = true,
				SaveTargetData = false,
				NeedStatusCheck = false,
				NeedContainerStatusCheck = this.NeedValidationAndStatusCheck,
			};

			executor.Relation.Status = SchemaObjectStatus.Deleted;

			SCMemberRelation result = null;

			ExecuteWithActions(AUOperationType.RemoveUserFromRole, () => SCActionContext.Current.DoActions(() => result = (SCMemberRelation)executor.Execute()));
		}
Exemplo n.º 10
0
		/// <summary>
		/// 解除某人的秘书关系
		/// </summary>
		/// <param name="secretary"></param>
		/// <param name="user"></param>
		/// <returns></returns>
		public SCSecretaryRelation RemoveSecretaryFromUser(SCUser secretary, SCUser user)
		{
			SCMemberRelativeExecutor executor = new SCMemberRelativeExecutor(SCOperationType.RemoveSecretaryFromUser, user, secretary) { OverrideExistedRelation = true, NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedContainerStatusCheck = this.NeedValidationAndStatusCheck };

			if (this._NeedCheckPermissions)
			{
				var hereParents = secretary.CurrentParentRelations;
				var thereParents = user.CurrentParentRelations;
				var hereIds = (from p in hereParents where p.Status == SchemaObjectStatus.Normal select p.ParentID).ToArray();
				var thereIds = (from p in thereParents where p.Status == SchemaObjectStatus.Normal select p.ParentID).ToArray();

				CheckPermissions(SCOperationType.RemoveSecretaryFromUser, SchemaDefine.GetSchema("Organizations"), "UpdateChildren", hereIds);
				CheckPermissions(SCOperationType.RemoveSecretaryFromUser, SchemaDefine.GetSchema("Organizations"), "UpdateChildren", thereIds);
			}
			executor.Relation.Status = SchemaObjectStatus.Deleted;

			SCSecretaryRelation result = null;

			ExecuteWithActions(SCOperationType.RemoveSecretaryFromUser, () => SCActionContext.Current.DoActions(() => result = (SCSecretaryRelation)executor.Execute()));

			return result;
		}
Exemplo n.º 11
0
			public virtual void DoAdd(SCUser otherUser, SCUser self)
			{
				if (otherUser.ID == self.ID)
					throw new HttpException("不能指定自身为秘书");
				this.executor.AddSecretaryToUser(self, otherUser);
			}
Exemplo n.º 12
0
			public virtual void DoRemove(SCUser otherUser, SCUser self)
			{
				if (otherUser.ID == self.ID)
					throw new HttpException("不能指定自身为秘书");
				this.executor.RemoveSecretaryFromUser(self, otherUser);
			}
Exemplo n.º 13
0
 private void GetUserCallback(SCUser user)
 {
     console.text = user.ToString();
 }
		public void ReplaceUsersInRole(ClientGenericObject[] users, ClientAdminUnit unit, ClientAUSchemaRole role)
		{
			users.NullCheck("users"); unit.NullCheck("unit"); role.NullCheck("role");
			 CheckIDProvided(unit); CheckIDProvided(role);
			SCUser[] scUsers = new SCUser[users.Length];
			for (int i = users.Length - 1; i >= 0; i--)
				scUsers[i] = (SCUser)users[i].ToSchemaObject();

			this.Facade.ReplaceUsersInRole(scUsers, (AdminUnit)unit.ToSchemaObject(), (AUSchemaRole)role.ToSchemaObject());
		}
Exemplo n.º 15
0
		public SCMemberRelation AddUserToGroup(SCUser user, SCGroup group)
		{
			SCMemberRelativeExecutor executor = new SCMemberRelativeExecutor(SCOperationType.AddUserToGroup, group, user) { NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedContainerStatusCheck = this.NeedValidationAndStatusCheck };

			if (this._NeedCheckPermissions)
				CheckOrganizationChildrenPermissions(SCOperationType.AddUserToGroup, "EditMembersOfGroups", group);

			SCMemberRelation result = null;

			ExecuteWithActions(SCOperationType.AddUserToGroup, () => SCActionContext.Current.DoActions(() => result = (SCMemberRelation)executor.Execute()));

			return result;
		}
Exemplo n.º 16
0
		public SCMemberRelation RemoveUserFromGroup(SCUser user, SCGroup group)
		{
			SCMemberRelativeExecutor executor = new SCMemberRelativeExecutor(SCOperationType.RemoveUserFromGroup, group, user) { OverrideExistedRelation = true, NeedStatusCheck = this.NeedValidationAndStatusCheck, NeedContainerStatusCheck = this.NeedValidationAndStatusCheck };

			if (this._NeedCheckPermissions)
				CheckOrganizationChildrenPermissions(SCOperationType.RemoveUserFromGroup, "EditMembersOfGroups", group);

			executor.Relation.Status = SchemaObjectStatus.Deleted;

			SCMemberRelation result = null;

			ExecuteWithActions(SCOperationType.RemoveUserFromGroup, () => SCActionContext.Current.DoActions(() => result = (SCMemberRelation)executor.Execute()));

			return result;
		}
Exemplo n.º 17
0
			public override void DoRemove(SCUser otherUser, SCUser self)
			{
				base.DoRemove(self, otherUser);
			}
Exemplo n.º 18
0
			public override void DoAdd(SCUser otherUser, SCUser self)
			{
				base.DoAdd(self, otherUser);
			}
Exemplo n.º 19
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;
		}
Exemplo n.º 20
0
		public void ReplaceUsersInRole(SCUser[] users, AdminUnit unit, AUSchemaRole role)
		{
			CheckUnitPermission(AUOperationType.RemoveUserFromRole, "EditRoleMembers", unit);

			AURoleMemberExecutor executor = new AURoleMemberExecutor(AUOperationType.RemoveUserFromRole, role, unit, users)
			{
				NeedStatusCheck = this.NeedValidationAndStatusCheck,
				NeedContainerStatusCheck = this.NeedValidationAndStatusCheck
			};

			ExecuteWithActions(AUOperationType.RemoveUserFromRole, () => SCActionContext.Current.DoActions(() => executor.Execute()));
		}
		public void AddUserToRole(ClientGenericObject user, ClientAdminUnit unit, ClientAUSchemaRole role)
		{
			user.NullCheck("user"); unit.NullCheck("unit"); role.NullCheck("role");
			CheckIDProvided(user); CheckIDProvided(unit); CheckIDProvided(role);

			if (string.IsNullOrEmpty(user.ID))
				throw new ArgumentException("user的ID必须不为null", "user");

			SCUser scUser = new SCUser()
			{
				ID = user.ID,
				Name = user.Properties.GetValue("Name", string.Empty),
				CodeName = user.Properties.GetValue("CodeName", string.Empty)
			};

			this.Facade.AddUserToRole(scUser, (AdminUnit)unit.ToSchemaObject(), (AUSchemaRole)role.ToSchemaObject());
		}