コード例 #1
0
        public void CanRemove_should_throw_exception_if_contributor_not_found()
        {
            var command = new RemoveContributor {
                ContributorId = "1"
            };

            Assert.Throws <DomainObjectNotFoundException>(() => GuardAppContributors.CanRemove(contributors_0, command));
        }
コード例 #2
0
ファイル: AppDomainObject.cs プロジェクト: llenroc/squidex
        public AppDomainObject RemoveContributor(RemoveContributor command)
        {
            ThrowIfNotCreated();

            RaiseEvent(SimpleMapper.Map(command, new AppContributorRemoved()));

            return(this);
        }
コード例 #3
0
        protected Task On(RemoveContributor command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <AppDomainObject>(context, a =>
            {
                GuardAppContributors.CanRemove(a.Snapshot.Contributors, command);

                a.RemoveContributor(command);
            }));
        }
コード例 #4
0
        public async Task <IActionResult> DeleteContributor(string app, string id)
        {
            var command = new RemoveContributor {
                ContributorId = id
            };

            var response = await InvokeCommandAsync(command);

            return(Ok(response));
        }
コード例 #5
0
        public AppDomainObject RemoveContributor(RemoveContributor command)
        {
            Guard.Valid(command, nameof(command), () => "Cannot remove contributor");

            ThrowIfNotCreated();

            RaiseEvent(SimpleMapper.Map(command, new AppContributorRemoved()));

            return(this);
        }
コード例 #6
0
        public async Task <IActionResult> DeleteMyself(string app)
        {
            var command = new RemoveContributor {
                ContributorId = UserId()
            };

            var response = await InvokeCommandAsync(command);

            return(Ok(response));
        }
コード例 #7
0
        public void CanRemove_should_throw_exception_if_contributor_is_only_owner()
        {
            var command = new RemoveContributor {
                ContributorId = "1"
            };

            var contributors_1 = contributors_0.Assign("1", AppContributorPermission.Owner);
            var contributors_2 = contributors_1.Assign("2", AppContributorPermission.Editor);

            Assert.Throws <ValidationException>(() => GuardAppContributors.CanRemove(contributors_2, command));
        }
コード例 #8
0
        public void CanRemove_should_not_throw_exception_if_contributor_not_only_owner()
        {
            var command = new RemoveContributor {
                ContributorId = "1"
            };

            contributors.Assign("1", AppContributorPermission.Owner);
            contributors.Assign("2", AppContributorPermission.Owner);

            GuardAppContributors.CanRemove(contributors, command);
        }
コード例 #9
0
        public void CanRemove_should_not_throw_exception_if_contributor_not_only_owner()
        {
            var command = new RemoveContributor {
                ContributorId = "1"
            };

            var contributors_1 = contributors_0.Assign("1", Role.Owner);
            var contributors_2 = contributors_1.Assign("2", Role.Owner);

            GuardAppContributors.CanRemove(contributors_2, command);
        }
コード例 #10
0
        public async Task <IActionResult> DeleteContributor(string appId, string contributorId)
        {
            var update = new RemoveContributor {
                ContributorId = contributorId, UserId = UserId
            };

            var app = await appStore.UpsertAsync(appId, update, HttpContext.RequestAborted);

            var response = await AppDetailsDto.FromDomainObjectAsync(app, UserId, userResolver);

            return(Ok(response));
        }
コード例 #11
0
        public void CanRemove_should_throw_exception_if_contributor_is_only_owner()
        {
            var command = new RemoveContributor {
                ContributorId = "1"
            };

            var contributors_1 = contributors_0.Assign("1", Role.Owner);
            var contributors_2 = contributors_1.Assign("2", Role.Editor);

            ValidationAssert.Throws(() => GuardAppContributors.CanRemove(contributors_2, command),
                                    new ValidationError("Cannot remove the only owner."));
        }
コード例 #12
0
        public async Task <ActionResult> RemoveContributorAsync([FromRoute] Guid backpackId, [FromRoute] Guid userId)
        {
            var sub = User.Claims.FirstOrDefault(c => c.Type == "sub")?.Value;

            var command = new RemoveContributor(sub, backpackId, userId);
            var result  = await _mediator.Send(command);

            if (result.IsFailure)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
コード例 #13
0
        public async Task Should_remove_from_user_index_on_remove_of_contributor()
        {
            var command = new RemoveContributor {
                AppId = appId, ContributorId = userId
            };

            var context =
                new CommandContext(command, commandBus)
                .Complete();

            await sut.HandleAsync(context);

            A.CallTo(() => indexByUser.RemoveAsync(appId.Id))
            .MustHaveHappened();
        }
コード例 #14
0
        public async Task RemoveContributor_should_create_events_and_update_state()
        {
            var command = new RemoveContributor {
                ContributorId = contributorId
            };

            await ExecuteCreateAsync();
            await ExecuteAssignContributorAsync();

            var result = await sut.ExecuteAsync(CreateCommand(command));

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.False(sut.Snapshot.Contributors.ContainsKey(contributorId));

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new AppContributorRemoved {
                ContributorId = contributorId
            })
                );
        }
コード例 #15
0
        public static void CanRemove(AppContributors contributors, RemoveContributor command)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(e =>
            {
                if (string.IsNullOrWhiteSpace(command.ContributorId))
                {
                    e(Not.Defined(nameof(command.ContributorId)), nameof(command.ContributorId));
                }

                var ownerIds = contributors.Where(x => x.Value == Role.Owner).Select(x => x.Key).ToList();

                if (ownerIds.Count == 1 && ownerIds.Contains(command.ContributorId))
                {
                    e(T.Get("apps.contributors.onlyOneOwner"));
                }
            });

            if (!contributors.ContainsKey(command.ContributorId))
            {
                throw new DomainObjectNotFoundException(command.ContributorId);
            }
        }
コード例 #16
0
        public static void CanRemove(AppContributors contributors, RemoveContributor command)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(() => "Cannot remove contributor.", e =>
            {
                if (string.IsNullOrWhiteSpace(command.ContributorId))
                {
                    e(Not.Defined("Contributor id"), nameof(command.ContributorId));
                }

                var ownerIds = contributors.Where(x => x.Value == Role.Owner).Select(x => x.Key).ToList();

                if (ownerIds.Count == 1 && ownerIds.Contains(command.ContributorId))
                {
                    e("Cannot remove the only owner.");
                }
            });

            if (!contributors.ContainsKey(command.ContributorId))
            {
                throw new DomainObjectNotFoundException(command.ContributorId, "Contributors", typeof(IAppEntity));
            }
        }
コード例 #17
0
        public static void CanRemove(AppContributors contributors, RemoveContributor command)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(() => "Cannot remove contributor.", error =>
            {
                if (string.IsNullOrWhiteSpace(command.ContributorId))
                {
                    error(new ValidationError("Contributor id not assigned.", nameof(command.ContributorId)));
                }

                var ownerIds = contributors.Where(x => x.Value == AppContributorPermission.Owner).Select(x => x.Key).ToList();

                if (ownerIds.Count == 1 && ownerIds.Contains(command.ContributorId))
                {
                    error(new ValidationError("Cannot remove the only owner.", nameof(command.ContributorId)));
                }
            });

            if (!contributors.ContainsKey(command.ContributorId))
            {
                throw new DomainObjectNotFoundException(command.ContributorId, "Contributors", typeof(AppDomainObject));
            }
        }
コード例 #18
0
 private void RemoveContributor(RemoveContributor command)
 {
     Raise(command, new AppContributorRemoved());
 }
コード例 #19
0
 private Task RemoveContributorAsync(RemoveContributor command)
 {
     return(Index(command.ContributorId).RemoveAsync(command.AppId));
 }
コード例 #20
0
 public void RemoveContributor(RemoveContributor command)
 {
     RaiseEvent(SimpleMapper.Map(command, new AppContributorRemoved()));
 }
コード例 #21
0
 protected Task On(RemoveContributor command, CommandContext context)
 {
     return(handler.UpdateAsync <AppDomainObject>(context, a => a.RemoveContributor(command)));
 }
コード例 #22
0
 private async Task RemoveContributorAsync(RemoveContributor command)
 {
     await Index(command.ContributorId).RemoveAsync(command.AggregateId);
 }
コード例 #23
0
 private static string GetUserId(RemoveContributor removeContributor)
 {
     return(removeContributor.ContributorId);
 }
コード例 #24
0
        public void CanRemove_should_throw_exception_if_contributor_id_is_null()
        {
            var command = new RemoveContributor();

            Assert.Throws <ValidationException>(() => GuardAppContributors.CanRemove(contributors_0, command));
        }