Esempio n. 1
0
        /// <summary>
        /// Gets a Project, even if archived.
        ///    Return project even if null. This is called internally from TFA,
        ///      so don't want to throw exception other GetProjects do. Note that no UserUid available.
        ///
        /// Others are called from UI so can throw exception.
        /// </summary>
        public static async Task <ProjectDatabaseModel> GetProjectAndReturn(string projectUid,
                                                                            ILogger log, IServiceExceptionHandler serviceExceptionHandler, ICwsProjectClient cwsProjectClient, IHeaderDictionary customHeaders)
        {
            var project = await cwsProjectClient.GetMyProject(new Guid(projectUid), null, customHeaders : customHeaders);

            if (project == null)
            {
                log.LogInformation($"{nameof(GetProjectAndReturn)} Project projectUid: {projectUid} not retrieved");
                return(null);
            }
            log.LogInformation($"{nameof(GetProjectAndReturn)} Project projectUid: {projectUid} project retrieved {JsonConvert.SerializeObject(project)}");
            return(ConvertCwsToWorksOSProject(project, log));
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a Project and checks customerUid
        ///   Includes any project, regardless of archived state.
        ///   Temporary Note that this will return nothing if user doesn't have ADMIN role
        ///       WM team may change this behaviour in future
        /// </summary>
        public static async Task <ProjectDatabaseModel> GetProject(Guid projectUid, Guid customerUid, Guid userUid,
                                                                   ILogger log, IServiceExceptionHandler serviceExceptionHandler, ICwsProjectClient cwsProjectClient, IHeaderDictionary customHeaders)
        {
            var project = await cwsProjectClient.GetMyProject(projectUid, userUid, customHeaders);

            if (project == null)
            {
                log.LogWarning($"Project not found: {projectUid}");
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.Forbidden, 1);
                return(null);
            }

            if (!string.Equals(project.AccountId, customerUid.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                log.LogWarning($"Customer doesn't have access to projectUid: {projectUid}");
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.Forbidden, 1);
            }

            log.LogInformation($"Project projectUid: {projectUid} retrieved");
            return(ConvertCwsToWorksOSProject(project, log));
        }