Esempio n. 1
0
        public virtual async Task <Result> ValidateUser(string id)
        {
            IBaseSpecification <AppUserEntity, AppUserEntity> userExistsSpecification = SpecificationBuilder
                                                                                        .Create <AppUserEntity>()
                                                                                        .WithId(id)
                                                                                        .Build();

            bool userExist = await _userDAO.Exist(userExistsSpecification);

            if (!userExist)
            {
                _logger.LogError($"No user. UserId {id}");
                return(Result.Fail(USER_NOT_FOUND));
            }

            IBaseSpecification <GroupUserEntity, GroupUserEntity> userAlreadyInGroupSpecification = SpecificationBuilder
                                                                                                    .Create <GroupUserEntity>()
                                                                                                    .Where(x => x.UserId == id)
                                                                                                    .Build();

            bool userAlreadyInGroup = await _groupUserDAO.Exist(userAlreadyInGroupSpecification);

            if (userAlreadyInGroup)
            {
                _logger.LogError($"User is already in a group. UserId {id}");
                return(Result.Fail(USER_IS_ALREADY_IN_GROUP));
            }

            return(Result.Ok());
        }
Esempio n. 2
0
        private async Task <Result> GroupRoleExists(string groupRoleId)
        {
            IBaseSpecification <RoleEntity, RoleEntity> specification = SpecificationBuilder
                                                                        .Create <RoleEntity>()
                                                                        .Where(x => x.Id == groupRoleId)
                                                                        .Where(x => x.Type == Data.Enums.Entity.RoleTypes.Group)
                                                                        .Build();

            bool groupRoleExists = await _roleDAO.Exist(specification);

            if (!groupRoleExists)
            {
                _logger.LogError($"No GroupRole. RoleId {groupRoleId}");
                return(Result.Fail(GROUP_ROLE_NOT_FOUND));
            }

            return(Result.Ok());
        }
Esempio n. 3
0
        public async Task <Result> Any(IBaseSpecification <GroupUserEntity, GroupUserEntity> specification)
        {
            specification = ApplayGroupUserFilter(specification);

            bool exists = await _groupUserDAO.Exist(specification);

            if (!exists)
            {
                _logger.LogError($"GroupUser not found");
                return(Result.Fail(NO_GROUP_USER));
            }

            return(Result.Ok());
        }
Esempio n. 4
0
        public async Task <Result> Any(IBaseSpecification <GroupEntity, GroupEntity> specification)
        {
            ApplayGroupFilter(specification);

            bool exists = await _groupDAO.Exist(specification);

            if (!exists)
            {
                _logger.LogError($"Group not found");
                return(Result.Fail(GROUP_NOT_FOUND));
            }

            return(Result.Ok());
        }
Esempio n. 5
0
        public virtual async Task <Result> ValidateGroup(string groupId)
        {
            IBaseSpecification <GroupEntity, GroupEntity> specification = SpecificationBuilder
                                                                          .Create <GroupEntity>()
                                                                          .WithId(groupId)
                                                                          .Build();

            bool exists = await _groupDAO.Exist(specification);

            if (!exists)
            {
                _logger.LogError($"No group. GroupId {groupId}");
                return(Result.Fail(GROUP_NOT_FOUND));
            }

            return(Result.Ok());
        }
Esempio n. 6
0
        private async Task <Result> UserAlreadyExist(string email)
        {
            IBaseSpecification <AppUserEntity, AppUserEntity> specification = SpecificationBuilder
                                                                              .Create <AppUserEntity>()
                                                                              .Where(x => x.NormalizedEmail == email.ToUpper())
                                                                              .Build();

            bool userExist = await _userDAO.Exist(specification);

            if (userExist)
            {
                _logger.LogError($"User with the same email already exists");
                //return Result.Fail(USER_WITH_SAME_EMAIL_ALREADY_EXIST); //TODO: dont expose all users to everybody
                return(Result.Fail(FAILED_TO_ADD_INVITE));
            }

            return(Result.Ok());
        }
Esempio n. 7
0
        public async Task <Result <IdStringModel> > AddAsync(AddGroupRequest addGroup)
        {
            ValidationResult validationResult = _addGroupValidator.Validate(addGroup);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning($"Invalid AddGroupRequest model");
                return(Result.Fail <IdStringModel>(validationResult.ToResultError()));
            }

            addGroup.Name = addGroup.Name.Trim();

            IBaseSpecification <GroupEntity, GroupEntity> groupExistSpecification = SpecificationBuilder
                                                                                    .Create <GroupEntity>()
                                                                                    .WithName(addGroup.Name)
                                                                                    .Build();

            bool groupExist = await _groupDAO.Exist(groupExistSpecification);

            if (groupExist)
            {
                _logger.LogError($"Group with the same name already exist. GroupName {addGroup.Name}");
                return(Result.Fail <IdStringModel>(GROUP_WITH_NAME_ALREADY_EXIST));
            }

            GroupEntity group = new GroupEntity(
                name: addGroup.Name);

            bool addResult = await _groupDAO.Add(group);

            if (!addResult)
            {
                _logger.LogError($"Failed to add group");
                return(Result.Fail <IdStringModel>(FAILED_TO_ADD_GROUP));
            }

            IdStringModel idStringModel = new IdStringModel(
                id: group.Id);

            return(Result.Ok(idStringModel));
        }
Esempio n. 8
0
        private async Task <Result> InviteAlreadyExits(string email)
        {
            DateTimeOffset now = DateTimeOffset.UtcNow;

            IBaseSpecification <InviteEntity, InviteEntity> specification = SpecificationBuilder
                                                                            .Create <InviteEntity>()
                                                                            .Where(x => x.Email.ToUpper() == email.ToUpper())
                                                                            .Where(x => x.Status == Data.Enums.Entity.InviteStatuses.Pending)
                                                                            .Where(x => x.ExpiresAt > now)
                                                                            .Build();

            bool inviteExists = await _inviteDAO.Exist(specification);

            if (inviteExists)
            {
                _logger.LogError($"Valid invite already exists");
                return(Result.Fail(INVITE_ALREADY_EXISTS));
            }

            return(Result.Ok());
        }
Esempio n. 9
0
        public async Task <CommonUtils.Result.Result> UserExists(BaseRegisterRequest baseRegisterRequest)
        {
            string username = baseRegisterRequest.Username;

            if (_identityUIEndpoints.UseEmailAsUsername)
            {
                username = baseRegisterRequest.Email;
            }

            IBaseSpecification <AppUserEntity, AppUserEntity> specification = SpecificationBuilder
                                                                              .Create <AppUserEntity>()
                                                                              .WithUsername(username)
                                                                              .Build();

            bool userExists = await _userDAO.Exist(specification);

            if (!userExists)
            {
                return(CommonUtils.Result.Result.Fail(USER_NOT_FOUND));
            }

            return(CommonUtils.Result.Result.Ok());
        }
Esempio n. 10
0
        public virtual async Task <Result> RoleIsValid(string roleId)
        {
            if (roleId == null)
            {
                _logger.LogInformation($"Adding GroupUser without role");
                return(Result.Ok());
            }

            IBaseSpecification <RoleEntity, RoleEntity> specification = SpecificationBuilder
                                                                        .Create <RoleEntity>()
                                                                        .Where(x => x.Id == roleId)
                                                                        .Where(x => x.Type == Data.Enums.Entity.RoleTypes.Group)
                                                                        .Build();

            bool roleExists = await _roleDAO.Exist(specification);

            if (!roleExists)
            {
                _logger.LogError($"No GroupRole. RoleId {roleId}");
                return(Result.Fail(GROUP_ROLE_NOT_FOUND));
            }

            return(Result.Ok());
        }