Ejemplo n.º 1
0
        public AppContributorsController(ICommandBus commandBus, IAppPlansProvider appPlansProvider, IUserResolver userResolver)
            : base(commandBus)
        {
            this.appPlansProvider = appPlansProvider;

            this.userResolver = userResolver;
        }
Ejemplo n.º 2
0
        public AppApiFilter(IAppProvider appProvider, IAppPlansProvider appPlanProvider, IUsageTracker usageTracker)
        {
            this.appProvider     = appProvider;
            this.appPlanProvider = appPlanProvider;

            this.usageTracker = usageTracker;
        }
Ejemplo n.º 3
0
        public static void CanChangePlan(ChangePlan command, IAppEntity app, IAppPlansProvider appPlans)
        {
            Guard.NotNull(command, nameof(command));

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

                if (appPlans.GetPlan(command.PlanId) == null)
                {
                    e(T.Get("apps.plans.notFound"), nameof(command.PlanId));
                }

                var plan = app.Plan;

                if (!string.IsNullOrWhiteSpace(command.PlanId) && plan != null && !plan.Owner.Equals(command.Actor))
                {
                    e(T.Get("apps.plans.notPlanOwner"));
                }
            });
        }
Ejemplo n.º 4
0
 public ApiCostsFilter(IAppLogStore appLogStore, IAppPlansProvider appPlansProvider, IClock clock, IUsageTracker usageTracker)
 {
     this.appLogStore      = appLogStore;
     this.appPlansProvider = appPlansProvider;
     this.clock            = clock;
     this.usageTracker     = usageTracker;
 }
Ejemplo n.º 5
0
        public static AppDto FromApp(IAppEntity app, string userId, bool isFrontend, IAppPlansProvider plans, Resources resources)
        {
            var permissions = GetPermissions(app, userId, isFrontend);

            var result = SimpleMapper.Map(app, new AppDto());

            result.Permissions = permissions.ToIds();

            result.SetPlan(app, plans, resources, permissions);
            result.SetImage(app, resources);

            if (app.Contributors.TryGetValue(userId, out var roleName) && app.Roles.TryGet(app.Name, roleName, isFrontend, out var role))
            {
                result.RoleProperties = role.Properties;
            }
            else
            {
                result.RoleProperties = JsonValue.Object();
            }

            if (resources.Includes(P.ForApp(P.AppContents, app.Name), permissions))
            {
                result.CanAccessContent = true;
            }

            return(result.CreateLinks(resources, permissions));
        }
Ejemplo n.º 6
0
        public static void CanChangePlan(ChangePlan command, AppPlan plan, IAppPlansProvider appPlans)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(() => "Cannot change plan.", e =>
            {
                if (string.IsNullOrWhiteSpace(command.PlanId))
                {
                    e(Not.Defined("Plan id"), nameof(command.PlanId));
                    return;
                }

                if (appPlans.GetPlan(command.PlanId) == null)
                {
                    e("A plan with this id does not exist.", nameof(command.PlanId));
                }

                if (!string.IsNullOrWhiteSpace(command.PlanId) && plan != null && !plan.Owner.Equals(command.Actor))
                {
                    e("Plan can only changed from the user who configured the plan initially.");
                }

                if (string.Equals(command.PlanId, plan?.PlanId, StringComparison.OrdinalIgnoreCase))
                {
                    e("App has already this plan.");
                }
            });
        }
Ejemplo n.º 7
0
        public static void CanChangePlan(ChangePlan command, AppPlan plan, IAppPlansProvider appPlans)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(() => "Cannot change plan.", error =>
            {
                if (string.IsNullOrWhiteSpace(command.PlanId))
                {
                    error(new ValidationError("PlanId is not defined.", nameof(command.PlanId)));
                }
                else if (appPlans.GetPlan(command.PlanId) == null)
                {
                    error(new ValidationError("Plan id not available.", nameof(command.PlanId)));
                }

                if (!string.IsNullOrWhiteSpace(command.PlanId) && plan != null && !plan.Owner.Equals(command.Actor))
                {
                    error(new ValidationError("Plan can only be changed from current user."));
                }

                if (string.Equals(command.PlanId, plan?.PlanId, StringComparison.OrdinalIgnoreCase))
                {
                    error(new ValidationError("App has already this plan."));
                }
            });
        }
Ejemplo n.º 8
0
        public static AppDto FromApp(IAppEntity app, string userId, bool isFrontend, IAppPlansProvider plans, Resources resources)
        {
            var result = SimpleMapper.Map(app, new AppDto
            {
                PlanName = plans.GetPlanForApp(app).Plan.Name
            });

            var permissions = PermissionSet.Empty;

            var isContributor = false;

            if (app.Contributors.TryGetValue(userId, out var roleName) && app.Roles.TryGet(app.Name, roleName, isFrontend, out var role))
            {
                isContributor = true;

                result.RoleProperties = role.Properties;
                result.Permissions    = permissions.ToIds();

                permissions = role.Permissions;
            }

            if (resources.Includes(Shared.Permissions.ForApp(Shared.Permissions.AppContents, app.Name), permissions))
            {
                result.CanAccessContent = true;
            }

            if (resources.IsAllowed(Shared.Permissions.AppPlansChange, app.Name, additional: permissions))
            {
                result.PlanUpgrade = plans.GetPlanUpgradeForApp(app)?.Name;
            }

            return(result.CreateLinks(app, resources, permissions, isContributor));
        }
Ejemplo n.º 9
0
 public AppPlansController(ICommandBus commandBus,
                           IAppPlansProvider appPlansProvider,
                           IAppPlanBillingManager appPlansBillingManager)
     : base(commandBus)
 {
     this.appPlansProvider       = appPlansProvider;
     this.appPlansBillingManager = appPlansBillingManager;
 }
Ejemplo n.º 10
0
 public AppsController(ICommandBus commandBus,
                       IAppProvider appProvider,
                       IAppPlansProvider appPlansProvider)
     : base(commandBus)
 {
     this.appProvider      = appProvider;
     this.appPlansProvider = appPlansProvider;
 }
Ejemplo n.º 11
0
 public AppsController(ICommandBus commandBus,
                       IAppRepository appRepository,
                       IAppPlansProvider appPlansProvider)
     : base(commandBus)
 {
     this.appRepository    = appRepository;
     this.appPlansProvider = appPlansProvider;
 }
Ejemplo n.º 12
0
        private void SetPlan(IAppEntity app, IAppPlansProvider plans, ApiController controller)
        {
            if (controller.HasPermission(AllPermissions.AppPlansChange, app.Name))
            {
                PlanUpgrade = plans.GetPlanUpgradeForApp(app)?.Name;
            }

            PlanName = plans.GetPlanForApp(app)?.Name;
        }
Ejemplo n.º 13
0
        private void SetPlan(IAppEntity app, IAppPlansProvider plans, Resources resources, PermissionSet permissions)
        {
            if (resources.IsAllowed(P.AppPlansChange, app.Name, additional: permissions))
            {
                PlanUpgrade = plans.GetPlanUpgradeForApp(app)?.Name;
            }

            PlanName = plans.GetPlanForApp(app).Plan.Name;
        }
Ejemplo n.º 14
0
        public ApiCostsFilter(IAppPlansProvider appPlansProvider, IApiUsageTracker usageTracker)
        {
            Guard.NotNull(appPlansProvider);
            Guard.NotNull(usageTracker);

            this.appPlansProvider = appPlansProvider;

            this.usageTracker = usageTracker;
        }
Ejemplo n.º 15
0
        public UsageGate(IAppPlansProvider appPlansProvider, IApiUsageTracker apiUsageTracker, IGrainFactory grainFactory)
        {
            Guard.NotNull(apiUsageTracker, nameof(apiUsageTracker));
            Guard.NotNull(appPlansProvider, nameof(appPlansProvider));
            Guard.NotNull(grainFactory, nameof(grainFactory));

            this.appPlansProvider = appPlansProvider;
            this.apiUsageTracker  = apiUsageTracker;
            this.grainFactory     = grainFactory;
        }
Ejemplo n.º 16
0
        public static AppDto FromApp(IAppEntity app, string subject, IAppPlansProvider plans)
        {
            var response = SimpleMapper.Map(app, new AppDto());

            response.Permission = app.Contributors[subject];

            response.PlanName    = plans.GetPlanForApp(app)?.Name;
            response.PlanUpgrade = plans.GetPlanUpgradeForApp(app)?.Name;

            return(response);
        }
Ejemplo n.º 17
0
        public UsageGate(IAppPlansProvider appPlansProvider, IApiUsageTracker apiUsageTracker, IGrainFactory grainFactory)
        {
            Guard.NotNull(apiUsageTracker, nameof(apiUsageTracker));
            Guard.NotNull(appPlansProvider, nameof(appPlansProvider));
            Guard.NotNull(grainFactory, nameof(grainFactory));

            this.appPlansProvider = appPlansProvider;
            this.apiUsageTracker  = apiUsageTracker;

            usageLimitNotifier = grainFactory.GetGrain <IUsageNotifierGrain>(SingleGrain.Id);
        }
Ejemplo n.º 18
0
        public static ContributorsDto FromApp(IAppEntity app, IAppPlansProvider plans)
        {
            var plan = plans.GetPlanForApp(app);

            var contributors = app.Contributors.Select(x => new ContributorDto {
                ContributorId = x.Key, Permission = x.Value
            }).ToArray();

            return(new ContributorsDto {
                Contributors = contributors, MaxContributors = plan.MaxContributors
            });
        }
Ejemplo n.º 19
0
 public AppsController(ICommandBus commandBus,
                       IAssetStore assetStore,
                       IAssetThumbnailGenerator assetThumbnailGenerator,
                       IAppProvider appProvider,
                       IAppPlansProvider appPlansProvider)
     : base(commandBus)
 {
     this.assetStore = assetStore;
     this.assetThumbnailGenerator = assetThumbnailGenerator;
     this.appProvider             = appProvider;
     this.appPlansProvider        = appPlansProvider;
 }
Ejemplo n.º 20
0
 public AppDomainObject(IPersistenceFactory <State> persistence, ISemanticLog log,
                        InitialSettings initialPatterns,
                        IAppPlansProvider appPlansProvider,
                        IAppPlanBillingManager appPlansBillingManager,
                        IUserResolver userResolver)
     : base(persistence, log)
 {
     this.userResolver           = userResolver;
     this.appPlansProvider       = appPlansProvider;
     this.appPlansBillingManager = appPlansBillingManager;
     this.initialSettings        = initialPatterns;
 }
Ejemplo n.º 21
0
        public UsagesController(
            ICommandBus commandBus,
            IUsageTracker usageTracker,
            IAppPlansProvider appPlanProvider,
            IAssetUsageTracker assetStatsRepository)
            : base(commandBus)
        {
            this.usageTracker = usageTracker;

            this.appPlanProvider      = appPlanProvider;
            this.assetStatsRepository = assetStatsRepository;
        }
Ejemplo n.º 22
0
        public static AppCreatedDto FromResult(EntityCreatedResult <Guid> result, IAppPlansProvider apps)
        {
            var response = new AppCreatedDto
            {
                Id          = result.IdOrValue.ToString(),
                Permission  = AppContributorPermission.Owner,
                PlanName    = apps.GetPlan(null)?.Name,
                PlanUpgrade = apps.GetPlanUpgrade(null)?.Name,
                Version     = result.Version
            };

            return(response);
        }
Ejemplo n.º 23
0
 public AssetsController(
     ICommandBus commandBus,
     IAssetQueryService assetQuery,
     IAssetUsageTracker assetStatsRepository,
     IAppPlansProvider appPlansProvider,
     ITagService tagService)
     : base(commandBus)
 {
     this.assetQuery           = assetQuery;
     this.assetStatsRepository = assetStatsRepository;
     this.appPlansProvider     = appPlansProvider;
     this.tagService           = tagService;
 }
Ejemplo n.º 24
0
 public AssetsController(
     ICommandBus commandBus,
     IAssetRepository assetRepository,
     IAssetStatsRepository assetStatsRepository,
     IAppPlansProvider appPlanProvider,
     IOptions <AssetConfig> assetsConfig)
     : base(commandBus)
 {
     this.assetsConfig         = assetsConfig.Value;
     this.assetRepository      = assetRepository;
     this.assetStatsRepository = assetStatsRepository;
     this.appPlanProvider      = appPlanProvider;
 }
Ejemplo n.º 25
0
        public ApiCostsFilter(IAppLogStore appLogStore, IAppPlansProvider appPlansProvider, IUsageTracker usageTracker, IClock clock)
        {
            Guard.NotNull(appLogStore);
            Guard.NotNull(appPlansProvider);
            Guard.NotNull(usageTracker);
            Guard.NotNull(clock);

            this.appLogStore      = appLogStore;
            this.appPlansProvider = appPlansProvider;

            this.usageTracker = usageTracker;

            this.clock = clock;
        }
Ejemplo n.º 26
0
        public static AppPlansDto FromDomain(IAppEntity app, IAppPlansProvider plans, bool hasPortal)
        {
            var(_, planId) = plans.GetPlanForApp(app);

            var result = new AppPlansDto
            {
                CurrentPlanId = planId,
                Plans         = plans.GetAvailablePlans().Select(PlanDto.FromDomain).ToArray(),
                PlanOwner     = app.Plan?.Owner.Identifier,
                HasPortal     = hasPortal
            };

            return(result);
        }
Ejemplo n.º 27
0
        public static AppPlansDto FromApp(IAppEntity app, IAppPlansProvider plans, bool hasPortal)
        {
            var planId = app.Plan?.PlanId;

            var response = new AppPlansDto
            {
                CurrentPlanId = planId,
                Plans         = plans.GetAvailablePlans().Select(PlanDto.FromPlan).ToArray(),
                PlanOwner     = app.Plan?.Owner.Identifier,
                HasPortal     = hasPortal
            };

            return(response);
        }
Ejemplo n.º 28
0
 public AssetsController(
     ICommandBus commandBus,
     IAssetQueryService assetQuery,
     IAssetStatsRepository assetStatsRepository,
     IAppPlansProvider appPlanProvider,
     IOptions <AssetConfig> assetsConfig,
     ITagService tagService)
     : base(commandBus)
 {
     this.assetsConfig         = assetsConfig.Value;
     this.assetQuery           = assetQuery;
     this.assetStatsRepository = assetStatsRepository;
     this.appPlanProvider      = appPlanProvider;
     this.tagService           = tagService;
 }
Ejemplo n.º 29
0
        public AppDomainObject(IStore <DomainId> store, ISemanticLog log,
                               InitialPatterns initialPatterns,
                               IAppPlansProvider appPlansProvider,
                               IAppPlanBillingManager appPlansBillingManager,
                               IUserResolver userResolver)
            : base(store, log)
        {
            Guard.NotNull(initialPatterns, nameof(initialPatterns));
            Guard.NotNull(userResolver, nameof(userResolver));
            Guard.NotNull(appPlansProvider, nameof(appPlansProvider));
            Guard.NotNull(appPlansBillingManager, nameof(appPlansBillingManager));

            this.userResolver           = userResolver;
            this.appPlansProvider       = appPlansProvider;
            this.appPlansBillingManager = appPlansBillingManager;
            this.initialPatterns        = initialPatterns;
        }
Ejemplo n.º 30
0
 public AssetsController(
     ICommandBus commandBus,
     IAssetQueryService assetQuery,
     IAssetUsageTracker assetStatsRepository,
     IAppPlansProvider appPlansProvider,
     IOptions <AssetOptions> assetOptions,
     IOptions <MyContentsControllerOptions> controllerOptions,
     ITagService tagService)
     : base(commandBus)
 {
     this.assetOptions         = assetOptions.Value;
     this.assetQuery           = assetQuery;
     this.assetStatsRepository = assetStatsRepository;
     this.appPlansProvider     = appPlansProvider;
     this.controllerOptions    = controllerOptions.Value;
     this.tagService           = tagService;
 }