public async Task <IActionResult> Delete(string projectId)
        {
            var projectFromStorage = await _projectsService.GetProjectAsync(projectId);

            if (projectFromStorage == null)
            {
                return(NotFound());
            }

            var authorization = await _authorizationService.AuthorizeAsync(User, projectFromStorage, Operations.Delete);

            if (!authorization.Succeeded)
            {
                return(Forbid());
            }

            var branches = await _branchesService.GetBranchesAsync(projectId);

            foreach (var branch in branches)
            {
                await _searchService.DeleteDocumentsAsync(projectId, branch.Name);
            }

            await _projectsService.DeleteProjectAsync(projectId);

            return(Ok());
        }
        public async Task <IActionResult> Get(string projectId)
        {
            var branches = await _branchesService.GetBranchesAsync(projectId);

            if (branches == null)
            {
                return(NotFound());
            }

            return(new ObjectResult(branches));
        }
Beispiel #3
0
        public void Resolve(GraphQLQuery graphQLQuery)
        {
            graphQLQuery.Field <ResponseListGraphType <BranchType> >(
                "branches",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "projectId", Description = "id of the project"
            }
                    ),
                resolve: context => {
                var projectId = context.GetArgument <string>("projectId");
                var list      = _branchesService.GetBranchesAsync(projectId).GetAwaiter().GetResult();

                return(Response(list));
            }
                );

            graphQLQuery.Field <ResponseGraphType <BranchType> >(
                "branch",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "projectId", Description = "id of the project"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "branchName", Description = "name of the branch"
            }
                    ),
                resolve: context => {
                var projectId  = context.GetArgument <string>("projectId");
                var branchName = context.GetArgument <string>("branchName");
                var branch     = _branchesService.GetBranchAsync(projectId, branchName).GetAwaiter().GetResult();

                if (branch == null)
                {
                    return(NotFoundError(branchName));
                }

                return(Response(branch));
            }
                );
        }
Beispiel #4
0
        public ProjectType(IBranchesService branchesService)
        {
            Field(x => x.Id).Description("The id of the project.");
            Field(x => x.Name, nullable: true).Description("The name of the project.");
            Field(x => x.Description, nullable: true).Description("The description of the project.");
            Field(x => x.DefaultBranch, nullable: true).Description("Project's default branch.");
            Field(x => x.Group).Description("The group of the project.");
            Field(x => x.ProjectSite).Description("The site of the project.");
            Field(x => x.AccessToken).Description("The access token of the project.");
            Field(x => x.IsAccessLimited).Description("The information about access to the project.");

            Field <ListGraphType <StringGraphType> >(
                "visibleBranches",
                resolve: context => context.Source.VisibleBranches
                );

            Field <ListGraphType <StringGraphType> >(
                "tags",
                resolve: context => context.Source.Tags
                );

            Field <ListGraphType <ContactPersonType> >(
                "contactPeople",
                resolve: context => context.Source.ContactPeople
                );

            Field <ListGraphType <EditLinkType> >(
                "editLinks",
                resolve: context => context.Source.EditLinks
                );

            Field <ListGraphType <BranchType> >(
                "branches",
                resolve: context => branchesService.GetBranchesAsync(context.Source.Id)
                );
        }
        public async Task UploadBranchAsync(string projectId, string branchName, string filePath)
        {
            var logs    = new StringBuilder();
            var logsDto = new LogsDto();

            try
            {
                LogInformation(logs, $"Starting uploading project ({projectId}/{branchName}). Temporary file name: {filePath}.");
                if (!File.Exists(filePath))
                {
                    LogInformation(logs, $"Uploading project stopped ({projectId}/{branchName}). File '{filePath}' not exists.");

                    logsDto.Message = logs.ToString();
                    await _logsService.AppendLogsAsync(projectId, logsDto);

                    return;
                }

                _httpContextHeaders.Headers = new Dictionary <string, StringValues>();
                _httpContextHeaders.Headers.Add("Authorization", $"SecureToken {_applicationParameters.SecureToken}");

                LogInformation(logs, $"Getting branches information ({projectId}/{branchName}).");
                var branches = await _branchService.GetBranchesAsync(projectId);

                LogInformation(logs, $"Branches information retrieved ({projectId}/{branchName}).");

                if (branchName != null && branches.Any(x => x.Name == branchName))
                {
                    LogInformation(logs, $"Deleting branch from storage ({projectId}/{branchName}).");
                    await _branchService.DeleteBranchAsync(projectId, branchName);

                    LogInformation(logs, $"Branch was deleted ({projectId}/{branchName}).");
                }

                LogInformation(logs, $"Uploading branch to storage ({projectId}/{branchName}).");
                LogInformation(logs, $"Reading temporary file ({projectId}/{branchName}) from path: '{filePath}'.");
                using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    LogInformation(logs, $"File '{filePath}' exists and was readed.");
                    await _documentsService.UploadBranchAsync(projectId, branchName, fileStream, logs);
                }
                LogInformation(logs, $"Branch uploaded ({projectId}/{branchName}).");

                LogInformation(logs, $"Getting project information ({projectId}/{branchName}).");
                var project = await _projectsService.GetProjectAsync(projectId);

                if (!project.IsAccessLimited)
                {
                    LogInformation(logs, $"Ordering index refresh ({projectId}/{branchName}).");
                    await _searchService.RefreshIndexAsync(projectId, branchName);

                    LogInformation(logs, $"Index refresh ordered ({projectId}/{branchName}).");
                }

                LogInformation(logs, $"Uploading project ({projectId}/{branchName}) finished successfully.");
            }
            catch (Exception exception)
            {
                LogError(logs, $"During uploadind exception occurs ({projectId}/{branchName}).");
                LogError(logs, $"Exception: {exception.ToString()}.");
                LogError(logs, $"Message: {exception.Message}.");
                LogError(logs, $"Stack trace: {exception.StackTrace}.");

                if (exception.InnerException != null)
                {
                    LogError(logs, $"Inner exception: {exception.InnerException.ToString()}.");
                    LogError(logs, $"Inner exception message: {exception.InnerException.Message}.");
                    LogError(logs, $"Inner exception stack trace: {exception.InnerException.StackTrace}.");
                }

                LogError(logs, $"Uploading project ({projectId}/{branchName}) failed.");
            }
            finally
            {
                LogInformation(logs, $"Deleting temporary file: '{filePath}'.");
                File.Delete(filePath);
                LogInformation(logs, $"Temporary file '{filePath}' was deleted.");
            }

            logsDto.Message = logs.ToString();
            await _logsService.AppendLogsAsync(projectId, logsDto);
        }
Beispiel #6
0
        public async Task <IList <BranchDto> > Get(string projectId)
        {
            var branches = await _branchesService.GetBranchesAsync(projectId);

            return(branches);
        }