/// <summary> /// Create a new instance of a AccessRequestOrganization class. /// </summary> /// <param name="accessRequest"></param> /// <param name="organization"></param> public PimsAccessRequestOrganization(PimsAccessRequest accessRequest, PimsOrganization organization) : this() { this.AccessRequest = accessRequest; this.AccessRequestId = accessRequest?.AccessRequestId ?? throw new ArgumentNullException(nameof(accessRequest)); this.Organization = organization; this.OrganizationId = organization?.OrganizationId ?? throw new ArgumentNullException(nameof(organization)); }
/// <summary> /// Approve the access request and grant the user a role and organization. /// </summary> /// <param name="accessRequest"></param> /// <exception type="KeyNotFoundException">Entity does not exist in the datasource.</exception> /// <returns></returns> public async Task <Entity.PimsAccessRequest> UpdateAccessRequestAsync(Entity.PimsAccessRequest update) { update.ThrowIfNull(nameof(update)); _user.ThrowIfNotAuthorized(Permissions.AdminUsers, Permissions.OrganizationAdmin); var accessRequest = _pimsRepository.AccessRequest.Get(update.AccessRequestId); var user = _pimsRepository.User.Get(accessRequest.UserId); if (update.AccessRequestStatusTypeCode == AccessRequestStatusTypes.APPROVED) { user.PimsUserRoles.Clear(); user.PimsUserRoles.Add(new Entity.PimsUserRole() { UserId = user.Id, RoleId = update.RoleId.Value }); await AppendToUserAsync(user); } update.User = user; update.Role = _pimsRepository.Role.Find(update.RoleId); return(_pimsRepository.AccessRequest.Update(update)); }
/// <summary> /// Create a new instance of an AccessRequest for the specified user. /// </summary> /// <param name="id"></param> /// <param name="user"></param> /// <param name="role"></param> /// <param name="organization"></param> /// <returns></returns> public static Entity.PimsAccessRequest CreateAccessRequest(long id, Entity.PimsUser user, Entity.PimsRole role, Entity.PimsOrganization organization) { user ??= EntityHelper.CreateUser("test"); role ??= EntityHelper.CreateRole("Real Estate Manager"); var accessRequest = new Entity.PimsAccessRequest() { AccessRequestId = id, UserId = user.Id, User = user, RoleId = role.Id, Role = role }; organization ??= EntityHelper.CreateOrganization(id, "test", EntityHelper.CreateOrganizationType("Type 1"), EntityHelper.CreateOrganizationIdentifierType("Identifier 1"), EntityHelper.CreateAddress(id)); accessRequest.PimsAccessRequestOrganizations.Add(new Entity.PimsAccessRequestOrganization() { AccessRequestId = id, AccessRequest = accessRequest, OrganizationId = organization.Id, Organization = organization }); return(accessRequest); }
/// <summary> /// Creates a new instance of an AccessRequestNotificationModel, initializes it with specified arguments. /// </summary> /// <param name="accessRequest"></param> /// <param name="options"></param> public AccessRequestNotificationModel(Entity.PimsAccessRequest accessRequest, PimsOptions options) { this.AccessRequest = accessRequest; this.Environment = new Entity.Models.EnvironmentModel(options.Environment.Uri, options.Environment.Name, options.Environment.Title); }
/// <summary> /// Creates a new instance of an AccessRequestNotificationModel, initializes it with specified arguments. /// </summary> /// <param name="accessRequest"></param> /// <param name="env"></param> public AccessRequestNotificationModel(Entity.PimsAccessRequest accessRequest, Entity.Models.EnvironmentModel env) { this.AccessRequest = accessRequest; this.Environment = env; }