Example #1
0
        public void ResponseReceivedForNewUserGroup_PublishesCorrectEvent()
        {
            var suitableParents = new[] { new UserGroupDto {
                                              Id = Guid.NewGuid()
                                          } };
            var userGroup = new UserGroupDto {
                Name = "some group", ParentId = suitableParents[0].Id
            };

            Presenter.BindingModel.Populate(suitableParents, userGroup);
            var newId = Guid.NewGuid();

            RequestDispatcherStub.SetResponsesToReturn(new SaveUserGroupResponse {
                NewUserGroupId = newId
            });

            Presenter.PersistChanges();
            RequestDispatcherStub.ReturnResponses();

            var publishedEvent = EventAggregatorStub.GetPublishedEvents <UserGroupChangedEvent>()[0];

            Assert.AreEqual(newId, publishedEvent.Id);
            Assert.AreEqual(userGroup.Name, publishedEvent.Name);
            Assert.AreEqual(userGroup.ParentId.Value, publishedEvent.ParentId.Value);
            Assert.IsTrue(publishedEvent.IsNew);
        }
        private void AddOrUpdateGroup(UserGroupDto group, UserGroup2AppDto section)
        {
            //I don't even think this situation can happen but if it could, we'd want the section added to the latest group check if this is a new group
            if (group == null && section != null)
            {
                AddSection(section);
            }

            //this can be null since we are doing a left join
            if (group == null || group.Alias.IsNullOrWhiteSpace())
            {
                return;
            }

            //check if this is a new group
            var latestGroup = _currentUser.UserGroupDtos.Count > 0
                ? _currentUser.UserGroupDtos[_currentUser.UserGroupDtos.Count - 1]
                : null;

            if (latestGroup == null || latestGroup.Id != group.Id)
            {
                //add the current (new) group
                _currentUser.UserGroupDtos.Add(group);
            }

            AddSection(section);
        }
Example #3
0
        public ActionResult UserGroupRolesIndex()
        {
            UserGroupRolesModel model = new UserGroupRolesModel();

            UserGroupServiceReference.UserGroupServiceClient UGClient = null;
            try
            {
                string usergroupid = "";
                if (!string.IsNullOrEmpty(Request.QueryString["usergroupid"]))
                {
                    UGClient    = new UserGroupServiceClient();
                    usergroupid = Request.QueryString["usergroupid"];
                    UserGroupDto Usergroupdto = UGClient.GetById(Convert.ToInt32(usergroupid));
                    UGClient.Close();
                    model.UserGroupName = Usergroupdto.UserGroupName;
                    model.RoleGroupList = GetRoleGroupList(usergroupid);
                }

                string usertype = "";
                if (!string.IsNullOrEmpty(Request.QueryString["userType"]))
                {
                    usertype = Request.QueryString["userType"];
                }
            }
            catch (Exception ex)
            {
                return(View("ErrorPage"));
            }

            return(View("UserGroupRoles", model));
        }
Example #4
0
        public bool LeaveGroup(UserGroupDto userGroup)
        {
            var userGroupToRemove = _dbContext.UserGroups.Find(new object[] { userGroup.UserId, userGroup.GroupId });

            if (userGroupToRemove == null)
            {
                return(false);
            }

            _dbContext.UserGroups.Remove(userGroupToRemove);

            // check if it was last user in this group
            var countOfRemainingGroupMembers = _dbContext.UserGroups.Where(ug => ug.GroupId == userGroup.GroupId).Count();

            if (countOfRemainingGroupMembers == 1)
            {
                // delete empty group
                var groupToRemove = _dbContext.Groups.Find(userGroup.GroupId);
                _dbContext.Groups.Remove(groupToRemove);
            }

            if (_dbContext.SaveChanges() == 0)
            {
                return(false);
            }

            return(true);
        }
Example #5
0
 public DataTable FindByColumn( )
 {
     dt         = UserGroupDto.Data();
     dr         = dt.NewRow();
     dr["Name"] = "";
     return(dao.FindByColumn(dt));
 }
        public void Delete(UserGroupDto dto)
        {
            var obj    = Mapper.Map <UserGroup>(dto);
            var result = Db.UserGroup.Find(obj.UserGroupId);

            base.Delete(result);
        }
Example #7
0
        public virtual void CreateUserGroupWithRolePermissions()
        {
            var userGroupDto = new UserGroupDto
            {
                UserGroupName = "General Manager",
                Description   = "General Manager Description",
                CAId          = 0,
                IsActive      = true,
                IsDeleted     = false,
                AllowEdit     = true,
                AllowDelete   = true,
                CreatedBy     = -1,
                ModifiedBy    = -1
            };

            var ugRolePermissionDto = new UserGroupRolePermissionDto
            {
                AllowAdd    = true,
                AllowDelete = true,
                AllowEdit   = true,
                AllowPrint  = true,
                AllowView   = true
            };

            RoleDto roleDto = this.RoleService.GetById(10);

            ugRolePermissionDto.PermissionForRole = roleDto;
            userGroupDto.RolePermissionsInUserGroup.Add(ugRolePermissionDto);
            this.UserGroupInstance = this.UserGroupService.Create(userGroupDto, CurrentUserInstance.UserName);
            Assert.IsFalse(this.UserGroupInstance.UserGroupId == 0, "User Group Id should have been updated");
            Assert.AreEqual(this.UserGroupInstance.UserGroupName, userGroupDto.UserGroupName, "User Group Name are different");
        }
Example #8
0
    public void Run(Object source, EventArgs e)
    {
        // Get the reference of the application and context server classes
        HttpApplication application = (HttpApplication)source;
        HttpContext     context     = application.Context;

        // Get the current identity of the windows users
        var identity = WindowsIdentity.GetCurrent();
        var user     = identity.Name.Split("\\".ToCharArray());

        LdapSsoServiceClient ldapSsoServiceClient = new LdapSsoServiceClient();

        // Execute the service call to authenticate user
        AuthenticationResult result = ldapSsoServiceClient.AuthenticateUser(user[1], string.Empty);

        // Return the appropriate staus code - 200 - Success,  403 - Forbidden
        if (result != AuthenticationResult.SUCCESS)
        {
            HttpContext.Current.Response.Redirect("http://localhost:6011/Account/Index");
            HttpContext.Current.Response.StatusCode = 403;
        }
        else
        {
            // Execute the service call and get the user groups
            UserGroupDto userGroups = ldapSsoServiceClient.GetUserGroups(user[1]);

            // Persists the information in the session variables
            context.Items.Add("LoggedInUser", identity.Name);
            context.Items.Add("UserGroups", userGroups.GroupNames);

            HttpContext.Current.Response.StatusCode = 200;
        }
    }
Example #9
0
        public void TestUpdate()
        {
            // given:
            UserGroup userGroupToUpdate = UserGroupCreator.Create();

            string           expectedAdditionalInformations = "Keine";
            string           expectedName            = "die firma";
            int              expectedAcceptedBalance = -20;
            UserGroupDto     userGroupDtoForUpdate   = new UserGroupDto(expectedAdditionalInformations, expectedName, expectedAcceptedBalance);
            User             changedBy        = UserCreator.Create("changed by");
            DateTime         changedAt        = new DateTime(2016, 12, 22);
            EntityChangedDto entityChangedDto = new EntityChangedDto(changedBy, changedAt);

            // when:
            userGroupToUpdate.Update(userGroupDtoForUpdate, entityChangedDto);
            UserGroupDao.FlushAndClear();
            UserGroup actualBrokerPool = UserGroupDao.Get(userGroupToUpdate.Id);

            // then:
            actualBrokerPool.GetDto().ShouldBeEquivalentTo(userGroupDtoForUpdate);
            actualBrokerPool.AdditionalInformations.ShouldBeEquivalentTo(expectedAdditionalInformations);
            actualBrokerPool.BalanceOverdraftLimit.ShouldBeEquivalentTo(expectedAcceptedBalance);
            actualBrokerPool.ChangedAt.Should().Be(changedAt);
            actualBrokerPool.ChangedBy.Should().Be(changedBy);
            actualBrokerPool.Name.ShouldBeEquivalentTo(expectedName);
        }
Example #10
0
        public virtual void AssignRoletoUserGroup()
        {
            RoleDto      roleDto = this.RoleService.GetById(9);
            UserGroupDto ugDto   = this.UserGroupService.GetById(2);
            var          ugrpDto = new UserGroupRolePermissionDto
            {
                PermissionForUserGroup = new List <UserGroupDto>
                {
                    new UserGroupDto
                    {
                        UserGroupId = ugDto.UserGroupId
                    }
                },
                PermissionForRole = roleDto,
                AllowAdd          = false,
                AllowEdit         = false,
                AllowView         = false,
                AllowPrint        = false,
                AllowDelete       = false
            };

            ugDto.RolePermissionsInUserGroup.Clear();
            ugDto.RolePermissionsInUserGroup.Add(ugrpDto);
            this.UserGroupInstance = this.UserGroupService.Update(ugDto, CurrentUserInstance.UserName);
            Assert.IsTrue(this.UserGroupInstance.RolePermissionsInUserGroup[0].UserGroupRolePermissionId != 0, "UserGroupRolePermissionId should have been updated");
        }
Example #11
0
        public void TestSaveAndLoad()
        {
            // given:
            string expectedAdditionalInformations = "Keine";
            string expectedName    = "die firma";
            int    acceptedBalance = -10;

            UserGroupDto userGroupDto = new UserGroupDto(expectedAdditionalInformations, expectedName, acceptedBalance);

            DateTime         createdAt        = new DateTime(2016, 12, 12);
            User             createdBy        = UserCreator.Create();
            EntityCreatedDto entityCreatedDto = new EntityCreatedDto(createdBy, createdAt);
            UserGroup        userGroup        = new UserGroup(userGroupDto, entityCreatedDto);

            // when:
            userGroup = UserGroupDao.Save(userGroup);
            UserGroupDao.FlushAndClear();
            UserGroup actualBrokerPool = UserGroupDao.Get(userGroup.Id);

            // then:
            actualBrokerPool.GetDto().ShouldBeEquivalentTo(userGroupDto);
            actualBrokerPool.AdditionalInformations.ShouldBeEquivalentTo(expectedAdditionalInformations);
            actualBrokerPool.ChangedAt.Should().Be(null);
            actualBrokerPool.ChangedBy.Should().BeNull();
            actualBrokerPool.CreatedAt.ShouldBeEquivalentTo(createdAt);
            actualBrokerPool.CreatedBy.ShouldBeEquivalentTo(createdBy);
            actualBrokerPool.Name.ShouldBeEquivalentTo(expectedName);
            actualBrokerPool.BalanceOverdraftLimit.ShouldBeEquivalentTo(acceptedBalance);
        }
Example #12
0
        public async Task <UserGroupDto> PutUserGroup(int id, UserGroupDto model)
        {
            var url    = CRMApiUri + "/UserGroup/" + id;
            var result = await PutRequestToApi(url, model);

            return(result);
        }
Example #13
0
        public async Task <UserGroupDto> PostUserGroup(UserGroupDto model)
        {
            var url    = CRMApiUri + "/UserGroup";
            var result = await PostRequestToApi(url, model);

            return(result);
        }
Example #14
0
        public IActionResult AddMemberToGroup(UserGroupDto userToAdd)
        {
            var user      = _mapper.Map <UserGroup>(userToAdd);
            var addedUser = _groupRepo.AddUser(user);

            return(Ok(addedUser));
        }
Example #15
0
        public bool Action(string USERGROUP_OID, string Name, string Desc, string UserLogin, bool rowState, PAction action)
        {
            /*
             * [USERGROUP_OID],
             * [Name],
             * [Desc],
             * [CREATE_BY],
             * [CREATE_DATE],
             * [UPDATE_BY],
             * [UPDATE_DATE],
             * [ROW_STATE]*/
            dt = UserGroupDto.Data();
            dr = dt.NewRow();
            dr["USERGROUP_OID"] = USERGROUP_OID;
            dr["Name"]          = Name;
            dr["Desc"]          = Desc;
            dr["CREATE_BY"]     = UserLogin;
            dr["CREATE_DATE"]   = "";
            dr["UPDATE_BY"]     = UserLogin;
            dr["UPDATE_DATE"]   = "";
            dr["ROW_STATE"]     = rowState?"1":"0";
            dt.Rows.Add(dr);
            switch (action)
            {
            case  PAction.Add: isCan = Add(); break;

            case PAction.Update: isCan = Update(); break;

            case PAction.Delete: isCan = Delete(); break;
            }
            return(isCan);
        }
Example #16
0
 /// <summary>
 ///     Aktualisiert die Daten.
 /// </summary>
 /// <param name="userGroupDto">
 ///     <see cref="UserGroupDto" />
 /// </param>
 /// <param name="entityChangedDto">
 ///     <see cref="EntityChangedDto" />
 /// </param>
 public virtual void Update(UserGroupDto userGroupDto, EntityChangedDto entityChangedDto)
 {
     Require.NotNull(userGroupDto, nameof(userGroupDto));
     Require.NotNull(entityChangedDto, nameof(entityChangedDto));
     Update(userGroupDto);
     Update(entityChangedDto);
 }
Example #17
0
        public async Task <UserGroupDto> EnsureUserGroupExists(string capabilityName)
        {
            UserGroupDto userGroup = null;

            try
            {
                var existingUserGroups = await _slackFacade.GetUserGroups();

                var userGroupHandle = UserGroupHandle.Create(capabilityName);

                var userGroupFromSlack = existingUserGroups?.SingleOrDefault(grp => grp.Handle == userGroupHandle);

                if (userGroupFromSlack != null)
                {
                    return(userGroupFromSlack);
                }


                var response = await _slackFacade.CreateUserGroup(
                    name : $"{capabilityName} user group",
                    handle : userGroupHandle,
                    description : $"User group for capability {capabilityName}.");

                userGroup = response.UserGroup;
            }
            catch (SlackFacadeException ex)
            {
                _logger.LogError($"Issue with Slack API: {ex} : {ex.Message}");
            }

            return(userGroup);
        }
Example #18
0
        public static UserGroupDto UserGroupToUserGroupDto(UserGroup userGroup)
        {
            UserGroupDto ugDto = new UserGroupDto();

            /// mapper
            return(ugDto);
        }
Example #19
0
        public ActionResult GetUserGroupsView()
        {
            UserGroupModel         model  = new UserGroupModel();
            UserGroupServiceClient client = null;

            try
            {
                var UsergroupId = Request.QueryString["usergroupid"];
                client = new UserGroupServiceClient();
                UserGroupDto ugdto = client.GetById(UsergroupId != null ? Convert.ToInt32(UsergroupId) : 0);
                client.Close();
                model.UserGroupId   = ugdto.UserGroupId;
                model.UserGroupName = ugdto.UserGroupName;
                model.Description   = ugdto.Description;
                model.IsActive      = ugdto.IsActive;
                model.AllowEdit     = ugdto.AllowEdit;
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Error"));
            }
            finally
            {
                if (client != null && client.State == System.ServiceModel.CommunicationState.Opened)
                {
                    client.Close();
                }
            }
            return(View("UserGroupsView", model));
        }
Example #20
0
        public async Task <BaseEntity> SaveAndReturnEntityAsync(UserGroupDto entityDto)
        {
            var entity = _mapper.Map <UserGroup>(entityDto);
            var result = await _repository.SaveAndReturnEntityAsync(entity);

            return(result);
        }
Example #21
0
 private static IReadOnlyUserGroup ToReadOnlyGroup(UserGroupDto group)
 {
     return(new ReadOnlyUserGroup(group.Id, group.Name, group.Icon,
                                  group.StartContentId, group.StartMediaId, group.Alias,
                                  group.UserGroup2AppDtos.Select(x => x.AppAlias).ToArray(),
                                  group.DefaultPermissions == null ? Enumerable.Empty <string>() : group.DefaultPermissions.ToCharArray().Select(x => x.ToString())));
 }
Example #22
0
    public static UserGroupDto BuildDto(IUserGroup entity)
    {
        var dto = new UserGroupDto
        {
            Alias = entity.Alias,
            DefaultPermissions = entity.Permissions == null ? string.Empty : string.Join(string.Empty, entity.Permissions),
            Name = entity.Name,
            UserGroup2AppDtos = new List <UserGroup2AppDto>(),
            CreateDate        = entity.CreateDate,
            UpdateDate        = entity.UpdateDate,
            Icon           = entity.Icon,
            StartMediaId   = entity.StartMediaId,
            StartContentId = entity.StartContentId,
        };

        foreach (var app in entity.AllowedSections)
        {
            var appDto = new UserGroup2AppDto {
                AppAlias = app
            };
            if (entity.HasIdentity)
            {
                appDto.UserGroupId = entity.Id;
            }

            dto.UserGroup2AppDtos.Add(appDto);
        }

        if (entity.HasIdentity)
        {
            dto.Id = short.Parse(entity.Id.ToString());
        }

        return(dto);
    }
        public void Create(string securityToken, UserGroupDto userGroup)
        {
            try
            {
                var session  = CheckSession(securityToken);
                var existent = Read(securityToken, userGroup.IdUser, userGroup.IdGroup);
                if (existent != null)
                {
                    if (!existent.DateInclusionApproval.HasValue)
                    {
                        throw new FileSharingException(FileSharingException.USER_GROUP_ALREADY_REQUESTED,
                                                       "The user " + userGroup.IdUser + " has already a request to the group " + userGroup.IdGroup);
                    }
                    else
                    {
                        throw new FileSharingException(FileSharingException.USER_GROUP_ALREADY_MEMBER,
                                                       "The user " + userGroup.IdUser + " is already member of the group " + userGroup.IdGroup);
                    }
                }

                var userGroupDom = Mapper.Map <UserGroup>(userGroup);

                userGroupDom = _dao.Create(userGroupDom);
                Audit(session.IdUser, userGroup.IdGroup.ToString(), typeof(UserGroup).Name, ActionDto.Create, "User add to group: " + userGroupDom);
            }
            catch (FileSharingException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new FileSharingException(FileSharingException.ERROR_FILESHARING_SERVER, e.Message, e);
            }
        }
Example #24
0
    public static IUserGroup BuildEntity(IShortStringHelper shortStringHelper, UserGroupDto dto)
    {
        var userGroup = new UserGroup(
            shortStringHelper,
            dto.UserCount,
            dto.Alias,
            dto.Name,
            dto.DefaultPermissions.IsNullOrWhiteSpace() ? Enumerable.Empty <string>() : dto.DefaultPermissions !.ToCharArray().Select(x => x.ToString(CultureInfo.InvariantCulture)).ToList(),
            dto.Icon);

        try
        {
            userGroup.DisableChangeTracking();
            userGroup.Id             = dto.Id;
            userGroup.CreateDate     = dto.CreateDate;
            userGroup.UpdateDate     = dto.UpdateDate;
            userGroup.StartContentId = dto.StartContentId;
            userGroup.StartMediaId   = dto.StartMediaId;
            if (dto.UserGroup2AppDtos != null)
            {
                foreach (UserGroup2AppDto app in dto.UserGroup2AppDtos)
                {
                    userGroup.AddAllowedSection(app.AppAlias);
                }
            }

            userGroup.ResetDirtyProperties(false);
            return(userGroup);
        }
        finally
        {
            userGroup.EnableChangeTracking();
        }
    }
Example #25
0
        public IHttpActionResult RemoveGroupFromUser(UserGroupDto model)
        {
            groupService.RemoveGroupFromUser(model.GroupK, model.UserK);
            groupService.SaveChanges();

            return(Ok());
        }
Example #26
0
        protected void AddRecommendation_Click(object sender, EventArgs e)
        {
            if (SessionManager.IsUserAuthenticated(Context))
            {
                ICollection <long> groupsIds = new List <long>();
                string             comment   = textEntry.Text;
                foreach (GridViewRow row in groupsList.Rows)
                {
                    CheckBox cb = (CheckBox)row.FindControl("Sel");
                    if (cb != null && cb.Checked)
                    {
                        String       s         = row.Cells[0].Text;
                        UserGroupDto userGroup = userService.FindGroupsByName(s);
                        groupsIds.Add(userGroup.groupId);
                    }
                }

                userService.AddRecommendation(eventId, groupsIds, usrId, comment);
                Response.Redirect("MyGroups.aspx");
            }
            else
            {
                Response.Redirect("Authentication.aspx");
            }
        }
Example #27
0
        public IActionResult RequestGroupUnion(long id)
        {
            try
            {
                UserDto user;
                using (var srv = ServicesFactory.User)
                    user = srv.Read(SecurityToken);

                var result = new UserGroupDto
                {
                    IdGroup = id,
                    IdUser  = user.Id,
                    DateInclusionRequest = DateTime.Now
                };

                using (var srv = ServicesFactory.UserGroup)
                    srv.Create(SecurityToken, result);
            }
            catch (FileSharingException e)
            {
                _logger.LogError(e.Message);
                return(BadRequest(_localizer[e.Code].Value));
            }
            return(Ok());
        }
Example #28
0
        private static UserGroupDto ToUserGroupDto(UserGroupEntity group)
        {
            UserGroupDto userGroupDto = new UserGroupDto();

            userGroupDto.Id   = group.Id;
            userGroupDto.Name = group.Name;
            return(userGroupDto);
        }
Example #29
0
        public void TestEqualsAndGetHashCodeFromDto()
        {
            // given:
            UserGroupDto firstDto  = new UserGroupDto("Keine", "der Name 1", -10);
            UserGroupDto secondDto = new UserGroupDto(null, "der name 2", -20);

            // when, then:
            DtoAssert.TestEqualsAndGetHashCode(firstDto, secondDto);
        }
Example #30
0
        public async Task <IActionResult> Put(int id, [FromBody] UserGroupDto userGroup)
        {
            if (id == 0 || userGroup.Id == 0)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Id needs to be greater than 0."));
            }

            return(await SaveAndReturnEntityAsync(async() => await _userGroupService.SaveAndReturnEntityAsync(userGroup)));
        }