private async Task <IEnumerable <UserTargeting> > GetRules(Guid environmentId)
        {
            var rules    = unitOfWork.Repository <UserTargeting, Guid>();
            var envRules = await rules.GetAsync(UserTargeting.ByEnvironment(environmentId), "FeatureToggle,TargetRule");

            return(envRules);
        }
Exemple #2
0
        public async Task <UserTargeting> GetTarget(Guid id)
        {
            var userId         = authService.CurrentUserId();
            var userTargetings = unitOfWork.Repository <UserTargeting, Guid>();

            var target = await userTargetings.FirstOrDefaultAsync(UserTargeting.ById(id), "FeatureToggle,TargetRule");

            Guard.IsTrue(await hasEnvironmentPermission.ToRead(userId, target.EnvironmentId));
            return(target);
        }
Exemple #3
0
        public async Task <IEnumerable <UserTargeting> > GetTargets(Guid environmentId)
        {
            var userId = authService.CurrentUserId();

            Guard.IsTrue(await hasEnvironmentPermission.ToRead(userId, environmentId));

            var userTargetings = unitOfWork.Repository <UserTargeting, Guid>();

            return(await userTargetings.GetAsync(UserTargeting.ByEnvironment(environmentId), "FeatureToggle,TargetRule"));
        }
Exemple #4
0
        public void Given_a_0_Percent_Should_Not_Be_Traget()
        {
            var userTargetting = new UserTargeting
            {
                EnvironmentId = System.Guid.Empty
            };
            var target = TargetPercentage.New(0, userTargetting);

            Assert.IsFalse(target.IsTarget(new TargetUser("12345678")));
        }
Exemple #5
0
        public async Task UpdatePerPercent(Guid id, int percent)
        {
            var userId         = authService.CurrentUserId();
            var userTargetings = unitOfWork.Repository <UserTargeting, Guid>();
            var target         = await userTargetings.FirstOrDefaultAsync(UserTargeting.ById(id), "TargetRule");

            Guard.IsTrue(await hasEnvironmentPermission.ToWrite(userId, target.EnvironmentId), "You don't have permissions to update");

            (target.TargetRule as TargetPercentage).Percent.SetNumber(percent);

            await unitOfWork.SaveAsync();
        }
Exemple #6
0
        public async Task UpdatePerUser(Guid id, string property, string valuesList, TargetOption option)
        {
            var userId         = authService.CurrentUserId();
            var userTargetings = unitOfWork.Repository <UserTargeting, Guid>();
            var userTarget     = await userTargetings.FirstOrDefaultAsync(UserTargeting.ById(id), "TargetRule");

            Guard.IsTrue(await hasEnvironmentPermission.ToWrite(userId, userTarget.EnvironmentId), "You don't have permissions to update");

            (userTarget.TargetRule as TargetSpecificUsers).Update(property, option, valuesList);

            await unitOfWork.SaveAsync();
        }
        public void Should_be_target()
        {
            var userTargetting = new UserTargeting
            {
                EnvironmentId = System.Guid.Empty
            };
            var target = TargetSpecificUsers.New(userTargetting, "country", TargetOption.IsIn, "es,pl");
            var user   = new TargetUser("1234556");

            user.Add("country", "es");
            var isTarget = target.IsTarget(user);

            Assert.IsTrue(isTarget);
        }
Exemple #8
0
        public async Task CreatePerPercent(Guid applicationId, Guid environmentId, Guid featureToggleId, int percent)
        {
            var userId = authService.CurrentUserId();

            Guard.IsTrue(await hasEnvironmentPermission.ToWrite(userId, environmentId), "You don't have permissions to create");

            var userTargetings = unitOfWork.Repository <UserTargeting, Guid>();


            Guard.IsFalse(await userTargetings.AnyAsync(UserTargeting.ByEnvironment(environmentId).And(UserTargeting.ByToggle(featureToggleId))), "Already exists a rule for this environment and this feature toggle");

            var target = UserTargeting.PerPercent(environmentId, featureToggleId, percent);

            userTargetings.Insert(target);

            await unitOfWork.SaveAsync();
        }