Beispiel #1
0
        public static async Task <IEnumerable <T> > GetScopedToOrganization <T>(
            Func <Task <IEnumerable <T> > > baseQuery,
            IOrganizationContext organizationContext,
            IJsonApiContext jsonApiContext

            )
        {
            if (organizationContext.SpecifiedOrganizationDoesNotExist)
            {
                return(Enumerable.Empty <T>().AsQueryable());
            }
            else
            {
                var query           = jsonApiContext.QuerySet;
                var orgIdToFilterBy = "";

                if (query == null)
                {
                    query = new QuerySet();
                    jsonApiContext.QuerySet = query;
                }

                if (organizationContext.HasOrganization)
                {
                    orgIdToFilterBy = organizationContext.OrganizationId.ToString();
                }

                query.Filters.Add(new JsonApiDotNetCore.Internal.Query.FilterQuery("organization-header", orgIdToFilterBy, "="));

                return(await baseQuery());
            }
        }
Beispiel #2
0
 public  ProjectLogic(IProjectDA projectDA, 
   IIdentity identity,
   IOrganizationContext organizationContext)
 {
   _projectDA = projectDA;
   _identity = identity;
 }
 public ProjectService(
     IBackgroundJobClient hangfireClient,
     IJsonApiContext jsonApiContext,
     IOrganizationContext organizationContext,
     ICurrentUserContext currentUserContext,
     UserRepository userRepository,
     IEntityRepository <Project> projectRepository,
     CurrentUserRepository currentUserRepository,
     GroupRepository groupRepository,
     IEntityRepository <Organization> organizationRepository,
     IEntityRepository <UserRole> userRolesRepository,
     IEntityRepository <Author> authorRepository,
     ILoggerFactory loggerFactory) : base(jsonApiContext, projectRepository, loggerFactory)
 {
     OrganizationContext    = organizationContext;
     HangfireClient         = hangfireClient;
     JsonApiContext         = jsonApiContext;
     CurrentUserContext     = currentUserContext;
     UserRepository         = userRepository;
     GroupRepository        = groupRepository;
     OrganizationRepository = organizationRepository;
     UserRolesRepository    = userRolesRepository;
     AuthorRepository       = authorRepository;
     ProjectRepository      = (ProjectRepository)projectRepository;
     CurrentUserRepository  = currentUserRepository;
 }
Beispiel #4
0
 public ProductService(
     IJsonApiContext jsonApiContext,
     IOrganizationContext organizationContext,
     IEntityRepository <Product, Guid> productRepository,
     UserRepository userRepository,
     ProjectRepository projectRepository,
     ICurrentUserContext currentUserContext,
     IEntityRepository <ProductDefinition> productDefinitionRepository,
     IEntityRepository <WorkflowDefinition> workflowDefinitionRepository,
     IEntityRepository <Store> storeRepository,
     IEntityRepository <UserRole> userRolesRepository,
     IEntityRepository <ProductPublication> productPublicationsRepository,
     IBackgroundJobClient hangfireClient,
     ILoggerFactory loggerFactory) : base(jsonApiContext, productRepository, loggerFactory)
 {
     ProductRepository            = productRepository;
     ProductDefinitionRepository  = productDefinitionRepository;
     WorkflowDefinitionRepository = workflowDefinitionRepository;
     StoreRepository               = storeRepository;
     UserRolesRepository           = userRolesRepository;
     ProductPublicationsRepository = productPublicationsRepository;
     HangfireClient      = hangfireClient;
     UserRepository      = userRepository;
     ProjectRepository   = projectRepository;
     CurrentUserContext  = currentUserContext;
     OrganizationContext = organizationContext;
     JsonApiContext      = jsonApiContext;
 }
Beispiel #5
0
 public GroupRepository(
     ILoggerFactory loggerFactory,
     IJsonApiContext jsonApiContext,
     IOrganizationContext organizationContext,
     IDbContextResolver contextResolver
     ) : base(loggerFactory, jsonApiContext, contextResolver)
 {
     this.OrganizationContext = organizationContext;
 }
 public GroupsController(
     IJsonApiContext jsonApiContext,
     IResourceService <Group> resourceService,
     ICurrentUserContext currentUserContext,
     IOrganizationContext organizationContext,
     OrganizationService organizationService,
     UserService userService)
     : base(jsonApiContext, resourceService, currentUserContext, organizationService, userService)
 {
     this.OrganizationContext = organizationContext;
 }
Beispiel #7
0
 public OrganizationMembershipsController(
     IJsonApiContext jsonApiContext,
     OrganizationMembershipService organizationMembershipService,
     ICurrentUserContext currentUserContext,
     IOrganizationContext organizationContext,
     OrganizationService organizationService,
     UserService userService)
     : base(jsonApiContext, organizationMembershipService, currentUserContext, organizationService, userService)
 {
     this.organizationMembershipService = organizationMembershipService;
 }
 public UserRepository(
     ILoggerFactory loggerFactory,
     IJsonApiContext jsonApiContext,
     IOrganizationContext organizationContext,
     ICurrentUserContext currentUserContext,
     IDbContextResolver contextResolver
     ) : base(loggerFactory, jsonApiContext, contextResolver)
 {
     this.OrganizationContext = organizationContext;
     this.CurrentUserContext  = currentUserContext;
 }
 public UpdateForm(
     UserRepository userRepository,
     GroupRepository groupRepository,
     IOrganizationContext organizationContext,
     IEntityRepository <UserRole> userRolesRepository,
     ICurrentUserContext currentUserContext) : base(userRepository, userRolesRepository, currentUserContext)
 {
     UserRepository      = userRepository;
     GroupRepository     = groupRepository;
     OrganizationContext = organizationContext;
     CurrentUserContext  = currentUserContext;
 }
 public UserRepository(
     ILoggerFactory loggerFactory,
     IJsonApiContext jsonApiContext,
     IOrganizationContext organizationContext,
     ICurrentUserContext currentUserContext,
     CurrentUserRepository currentUserRepository,
     EntityHooksService <User> statusUpdateService,
     IDbContextResolver contextResolver
     ) : base(loggerFactory, jsonApiContext, currentUserRepository, statusUpdateService, contextResolver)
 {
     this.OrganizationContext = organizationContext;
     this.CurrentUserContext  = currentUserContext;
 }
 public OrganizationStoreService(
     IJsonApiContext jsonApiContext,
     IEntityRepository <OrganizationStore> organizationStoreRepository,
     CurrentUserRepository currentUserRepository,
     IOrganizationContext organizationContext,
     ILoggerFactory loggerFactory)
     : base(jsonApiContext, organizationStoreRepository, loggerFactory)
 {
     this.OrganizationContext         = organizationContext;
     this.organizationStoreRepository = organizationStoreRepository;
     this.CurrentUserRepository       = currentUserRepository;
     this.JsonApiContext = jsonApiContext;
 }
 public UserTaskService(
     IJsonApiContext jsonApiContext,
     IEntityRepository <UserTask> userTaskRepository,
     CurrentUserRepository currentUserRepository,
     IOrganizationContext organizationContext,
     ILoggerFactory loggerFactory)
     : base(jsonApiContext, userTaskRepository, loggerFactory)
 {
     this.OrganizationContext   = organizationContext;
     this.UserTaskRepository    = userTaskRepository;
     this.CurrentUserRepository = currentUserRepository;
     this.JsonApiContext        = jsonApiContext;
 }
Beispiel #13
0
 public ProductRepository(
     IOrganizationContext organizationContext,
     ICurrentUserContext currentUserContext,
     UserRepository userRepository,
     ILoggerFactory loggerFactory,
     CurrentUserRepository currentUserRepository,
     IJsonApiContext jsonApiContext,
     IDbContextResolver contextResolver
     ) : base(loggerFactory, jsonApiContext, currentUserRepository, contextResolver)
 {
     this.OrganizationContext = organizationContext;
     this.CurrentUserContext  = currentUserContext;
     this.UserRepository      = userRepository;
 }
 public UpdateForm(UserRepository userRepository,
                   IEntityRepository <Product, Guid> productRepository,
                   IEntityRepository <ProductDefinition> productDefinitionRepository,
                   IEntityRepository <Store> storeRepository,
                   IEntityRepository <UserRole> userRolesRepository,
                   ProjectRepository projectRepository,
                   IOrganizationContext organizationContext,
                   ICurrentUserContext currentUserContext) : base(userRepository, userRolesRepository, currentUserContext)
 {
     ProductRepository           = productRepository;
     ProjectRepository           = projectRepository;
     ProductDefinitionRepository = productDefinitionRepository;
     StoreRepository             = storeRepository;
     OrganizationContext         = organizationContext;
 }
Beispiel #15
0
 public GroupService(
     IJsonApiContext jsonApiContext,
     IOrganizationContext organizationContext,
     ICurrentUserContext currentUserContext,
     UserRepository userRepository,
     IEntityRepository<Group> groupRepository,
     IEntityRepository<UserRole> userRolesRepository,
     ILoggerFactory loggerFactory) : base(jsonApiContext, groupRepository, loggerFactory)
 {
     OrganizationContext = organizationContext;
     JsonApiContext = jsonApiContext;
     CurrentUserContext = currentUserContext;
     UserRepository = userRepository;
     UserRolesRepository = userRolesRepository;
     GroupRepository = (GroupRepository)groupRepository;
 }
Beispiel #16
0
 public UserService(
     IBackgroundJobClient hangfireClient,
     IJsonApiContext jsonApiContext,
     IOrganizationContext organizationContext,
     ICurrentUserContext currentUserContext,
     UserRepository userRepository,
     CurrentUserRepository currentUserRepository,
     IEntityRepository <User> entityRepository,
     IEntityRepository <UserRole> userRolesRepository,
     ILoggerFactory loggerFactory) : base(jsonApiContext, entityRepository, loggerFactory)
 {
     this.EntityRepository = (UserRepository)entityRepository;
     HangfireClient        = hangfireClient;
     JsonApiContext        = jsonApiContext;
     OrganizationContext   = organizationContext;
     CurrentUserContext    = currentUserContext;
     UserRepository        = userRepository;
     CurrentUserRepository = currentUserRepository;
     UserRolesRepository   = userRolesRepository;
 }
Beispiel #17
0
    public override async Task <ICommandResult> HandleAsync(ICommand command, IAsyncCollector <ICommand> commandQueue, IDurableOrchestrationContext orchestrationContext, ILogger log)
    {
        if (command is null)
        {
            throw new ArgumentNullException(nameof(command));
        }

        var commandResult = command.CreateResult();

        try
        {
            if (CanHandle(command))
            {
                var containerDocument = (IContainerDocument)command.Payload;

                using var loggerFactory  = new PassthroughLoggerFactory(log);
                using var serviceManager = CreateServiceManager();

                var broadcastMessage = new BroadcastMessage()
                {
                    Action    = commandResult.CommandAction.ToString().ToLowerInvariant(),
                    Timestamp = commandResult.LastUpdatedTime.GetValueOrDefault(DateTime.UtcNow),
                    Items     = GetItems(containerDocument)
                };

                var broadcastPayload = TeamCloudSerialize.SerializeObject(broadcastMessage);

                await foreach (var hubName in ResolveHubNamesAsync(containerDocument))
                {
                    var hubContext = await serviceManager
                                     .CreateHubContextAsync(hubName, CancellationToken.None)
                                     .ConfigureAwait(false);

                    var negotiation = await hubContext
                                      .NegotiateAsync()
                                      .ConfigureAwait(false);

                    await hubContext.Clients.All
                    .SendAsync(command.CommandAction.ToString(), broadcastMessage)
                    .ConfigureAwait(false);
                }
            }
            else
            {
                throw new NotImplementedException($"Missing orchestrator command handler implementation ICommandHandler<{command.GetTypeName(prettyPrint: true)}> at {GetType()}");
            }
        }
        catch (Exception exc)
        {
            commandResult.Errors.Add(exc);
        }

        return(commandResult);

        async IAsyncEnumerable <string> ResolveHubNamesAsync(object commandResultPayload)
        {
            yield return(commandResultPayload switch
            {
                IProjectContext projectContext => projectContext.GetHubName(),
                IOrganizationContext organizationContext => organizationContext.GetHubName(),
                Organization organization => organization.GetHubName(),
                _ => throw new NotSupportedException($"Unable to resolve hub name for command result payload of type '{commandResultPayload?.GetType()}'.")
            });

            if (commandResultPayload is User user)
            {
                foreach (var membership in user.ProjectMemberships)
                {
                    var project = await projectRepository
                                  .GetAsync(user.Organization, membership.ProjectId)
                                  .ConfigureAwait(false);

                    yield return(project.GetHubName());
                }
            }
        }
Beispiel #18
0
 public OrganizationRepository(IOrganizationContext context)
 {
     _context = context;
 }
Beispiel #19
0
 public static string GetHubName(this IOrganizationContext organizationContext)
 => organizationContext is null ? throw new ArgumentNullException(nameof(organizationContext)) : GetHubName(organizationContext.Organization);