コード例 #1
0
        public async Task <OrganizationUser> SaveUserAsync(OrganizationUser user, IEnumerable <SubvaultUser> subvaults)
        {
            if (user.Id.Equals(default(Guid)))
            {
                throw new BadRequestException("Invite the user first.");
            }

            await _organizationUserRepository.ReplaceAsync(user);

            var orgSubvaults = await _subvaultRepository.GetManyByOrganizationIdAsync(user.OrganizationId);

            var currentUserSubvaults = await _subvaultUserRepository.GetManyByOrganizationUserIdAsync(user.Id);

            // Let's make sure all these belong to this user and organization.
            var filteredSubvaults = subvaults.Where(s =>
                                                    orgSubvaults.Any(os => os.Id == s.SubvaultId) &&
                                                    (s.Id == default(Guid) || currentUserSubvaults.Any(cs => cs.Id == s.Id)));

            var subvaultsToDelete = currentUserSubvaults.Where(cs => !subvaults.Any(s => s.Id == cs.Id));

            foreach (var subvault in filteredSubvaults)
            {
                await _subvaultUserRepository.UpsertAsync(subvault);
            }

            foreach (var subvault in subvaultsToDelete)
            {
                await _subvaultUserRepository.DeleteAsync(subvault);
            }

            return(user);
        }
コード例 #2
0
        public async Task Delete(string orgId, string id)
        {
            var user = await _subvaultUserRepository.GetByIdAsync(new Guid(id));

            if (user == null)
            {
                throw new NotFoundException();
            }

            // TODO: permission check
            await _subvaultUserRepository.DeleteAsync(user);
        }
コード例 #3
0
        public async Task Delete(string orgId, string id)
        {
            var user = await _subvaultUserRepository.GetByIdAsync(new Guid(id));

            if (user == null)
            {
                throw new NotFoundException();
            }

            var subvault = await _subvaultRepository.GetByIdAsync(user.SubvaultId);

            if (subvault == null || !_currentContext.OrganizationAdmin(subvault.OrganizationId))
            {
                throw new NotFoundException();
            }

            await _subvaultUserRepository.DeleteAsync(user);
        }
コード例 #4
0
        private async Task SaveUserSubvaultsAsync(OrganizationUser user, IEnumerable <SubvaultUser> subvaults, bool newUser)
        {
            if (subvaults == null)
            {
                subvaults = new List <SubvaultUser>();
            }

            var orgSubvaults = await _subvaultRepository.GetManyByOrganizationIdAsync(user.OrganizationId);

            var currentUserSubvaults = newUser ? null : await _subvaultUserRepository.GetManyByOrganizationUserIdAsync(user.Id);

            // Let's make sure all these belong to this user and organization.
            var filteredSubvaults = subvaults.Where(s => orgSubvaults.Any(os => os.Id == s.SubvaultId));

            foreach (var subvault in filteredSubvaults)
            {
                var existingSubvaultUser = currentUserSubvaults?.FirstOrDefault(cs => cs.SubvaultId == subvault.SubvaultId);
                if (existingSubvaultUser != null)
                {
                    subvault.Id           = existingSubvaultUser.Id;
                    subvault.CreationDate = existingSubvaultUser.CreationDate;
                }

                subvault.OrganizationUserId = user.Id;
                await _subvaultUserRepository.UpsertAsync(subvault);
            }

            if (!newUser)
            {
                var subvaultsToDelete = currentUserSubvaults.Where(cs =>
                                                                   !filteredSubvaults.Any(s => s.SubvaultId == cs.SubvaultId));
                foreach (var subvault in subvaultsToDelete)
                {
                    await _subvaultUserRepository.DeleteAsync(subvault);
                }
            }
        }