コード例 #1
0
        public void Given_empty_args_Should_return_empty_string()
        {
            var description = LogString.WithDescription(new Dictionary <string, string> {
            });

            Assert.AreEqual(string.Empty, description);
        }
コード例 #2
0
        public void Given_args_Should_return_key_value_string()
        {
            var description = LogString.WithDescription(new Dictionary <string, string> {
                { "A", "a" }, { "B", "b" }
            });

            Assert.AreEqual("A:a, B:b", description);
        }
コード例 #3
0
        public async Task InviteUser(string email, Guid applicationId)
        {
            var user = await authService.CurrentUser();

            Guard.IsTrue(await hasApplicationPermission.ToWrite(user.Id, applicationId), new UnauthorizedException());

            var invitations = unitOfWork.Repository <Domain.Invitation, Guid>();
            var users       = unitOfWork.Repository <Domain.User, Guid>();

            var anyInvitationForThisEmail = await invitations.AnyAsync(Domain.Invitation.WithEmail(email).And(Domain.Invitation.WithApplication(applicationId)));

            Guard.IsFalse(anyInvitationForThisEmail, "You already invite this user");

            var applications = unitOfWork.Repository <Domain.Application, Guid>();
            var application  = await applications.GetById(applicationId);

            var invitationUrl = urlService.GetBaseUrl();


            //Check if the user exits
            var invitedUser = await users.FirstOrDefaultAsync(new DirectSpecification <Domain.User>(x => x.Account.Email == email), "Account");

            if (invitedUser != null)
            {
                application.GrantPermissionForUser(invitedUser, Domain.ApplicationPermissions.Admin);
                invitationUrl += $"/account/login";
            }
            else
            {
                var invitation = Domain.Invitation.NewInvitation(email, application);
                invitations.Insert(invitation);
                invitationUrl += $"/account/register?i={invitation.Token}&email={email}";
            }

            activityService.Log(
                LogString.WithName("Invitation", "sent"),
                LogString.WithDescription(new Dictionary <string, string> {
                { "Email", email }
            }), applicationId, user.Id);

            await unitOfWork.SaveAsync();

            await emailService.SendEmailAsync(new InvitationEmail(application.Name, invitationUrl, user.FullName) { To = email, Subject = $"{user.FullName} has invited you to join {application.Name}" });
        }
コード例 #4
0
        public async Task NewToggle(Guid applicationId, string key, string description, bool enable)
        {
            var userId = authService.CurrentUserId();

            Guard.IsTrue(await hasApplicationPermission.ToWrite(userId, applicationId), "You don't have permissions to create feature toggle");

            var applications = unitOfWork.Repository <Domain.Application, Guid>();
            var application  = await applications.FirstOrDefaultAsync(new DirectSpecification <Domain.Application>(x => x.Id == applicationId), "FeatureToggles,Environments.FeatureToggleValues");

            application.AddNewFeatureToggleForDefaultEnv(key, description, enable);

            activityService.Log(
                LogString.WithName("Feature toggle", "created"),
                LogString.WithDescription(new Dictionary <string, string> {
                { "Name", key }, { "Value", enable.ToString() }
            }), applicationId, userId);

            await unitOfWork.SaveAsync();
        }
コード例 #5
0
        public async Task RemoveFeatureToggle(Guid settingId)
        {
            var userId = authService.CurrentUserId();

            var featureToggles = unitOfWork.Repository <FeatureToggle, Guid>();
            var featureToggle  = await featureToggles.GetById(settingId);

            Guard.IsTrue(await hasApplicationPermission.ToWrite(userId, featureToggle.ApplicationId), "You don't have permissions to remove feature toggles");

            featureToggles.Delete(featureToggle);

            activityService.Log(
                LogString.WithName("Feature toggle", "deleted"),
                LogString.WithDescription(new Dictionary <string, string> {
                { "Name", featureToggle.Key }
            }), featureToggle.ApplicationId, userId);

            await unitOfWork.SaveAsync();
        }
コード例 #6
0
        public async Task <Guid> CreateApplication(string name)
        {
            var user = await authService.CurrentUser();

            var application = Domain.Application.New(user, name);

            var applications = unitOfWork.Repository <Domain.Application, Guid>();

            applications.Insert(application);

            activity.Log(
                LogString.WithName("Application", "created"),
                LogString.WithDescription(new Dictionary <string, string> {
                { "Name", name }
            }), application.Id, user.Id);

            await unitOfWork.SaveAsync();

            return(application.Id);
        }
コード例 #7
0
        public async Task DeleteApplication(Guid id, string applicationName)
        {
            var userId = authService.CurrentUserId();

            Guard.IsTrue(await hasApplicationPermission.ToDelete(userId, id), "Does not have permission for delete the application. Contact with the owner of this application");

            var applications = unitOfWork.Repository <Domain.Application, Guid>();
            var application  = await applications.GetById(id);

            Guard.IsTrue(application.Name == applicationName, "The application name is not correct");

            applications.Delete(application);

            activity.Log(
                LogString.WithName("Application", "deleted"),
                LogString.WithDescription(new Dictionary <string, string> {
                { "Name", applicationName }
            }), application.Id, userId);

            await unitOfWork.SaveAsync();
        }
コード例 #8
0
        public async Task DeleteEnvironment(Guid environmentId)
        {
            var userId       = authService.CurrentUserId();
            var environments = unitOfWork.Repository <Domain.ApplicationEnvironment, Guid>();

            var environment = await environments.GetById(environmentId, "Application.Environments");

            Guard.IsTrue(await hasApplicationPermission.ToWrite(userId, environment.ApplicationId), "Invalid permissions for remove environments");

            var application = environment.Application;

            application.RemoveEnvironment(environment);

            activityService.Log(
                LogString.WithName("Environment", "deleted"),
                LogString.WithDescription(new Dictionary <string, string> {
                { "Name", environment.Name }
            }), environment.ApplicationId, userId);

            await unitOfWork.SaveAsync();
        }
コード例 #9
0
        public async Task <Guid> CreateEnvironment(string name, Guid applicationId)
        {
            var userId = authService.CurrentUserId();

            Guard.IsTrue(await hasApplicationPermission.ToWrite(userId, applicationId), "Invalid permissions for create environments");

            var applications = unitOfWork.Repository <Application, Guid>();
            var application  = await applications.FirstOrDefaultAsync(new DirectSpecification <Domain.Application>(x => x.Id == applicationId), "Environments");

            var env = application.AddEnvironment(name);

            activityService.Log(
                LogString.WithName("Environment", "created"),
                LogString.WithDescription(new Dictionary <string, string> {
                { "Name", name }
            }), applicationId, userId);

            await unitOfWork.SaveAsync();

            return(env.Id);
        }
コード例 #10
0
        public async Task EditToggle(Guid environmentId, Guid featureId, bool enable)
        {
            var userId        = authService.CurrentUserId();
            var environments  = unitOfWork.Repository <Domain.ApplicationEnvironment, Guid>();
            var features      = unitOfWork.Repository <FeatureToggle, Guid>();
            var featureToggle = await features.GetByIdAsync(featureId);

            var environment = await environments.GetById(environmentId, "Application.FeatureToggles,FeatureToggleValues");

            Guard.IsNotNull(featureToggle, "Invalid feature toggle");
            Guard.IsTrue(await hasApplicationPermission.ToWrite(userId, environment.ApplicationId), "You don't have permissions to edit feature toggles");

            environment.AddOrEditFeatureToggleValue(featureId, enable);
            activityService.Log(
                LogString.WithName("Feature toggle", "edited"),
                LogString.WithDescription(new Dictionary <string, string> {
                { "Name", featureToggle.Key }, { "Value", enable.ToString() }, { "Environment", environment.Name }
            }), environment.ApplicationId, userId);

            await unitOfWork.SaveAsync();
        }