Exemplo n.º 1
0
        public OkResult RegisterUserFeedback([FromBody] RegisterUserFeedbackRequest request)
        {
            var botId = GetBotId();

            if (!botId.HasValue)
            {
                throw new HttpStatusException(HttpStatusCode.BadRequest, "Invalid or missing botId in claim");
            }

            var report = _dbContext.Reports.FirstOrDefault(r => r.Id == request.ReportId);

            if (report?.DashboardId != botId)
            {
                throw new HttpStatusException(HttpStatusCode.BadRequest, "Bot is not authorized to submit feedback to this report");
            }

            if (string.IsNullOrWhiteSpace(request.Feedback))
            {
                throw new HttpStatusException(HttpStatusCode.BadRequest, "Feedback type must be provided");
            }

            var allowedFeedback = _dbContext.ReportAllowedFeedbacks
                                  .Include(raf => raf.Feedback)
                                  .FirstOrDefault(raf => request.Feedback.Equals(raf.Feedback.Name, StringComparison.OrdinalIgnoreCase));

            if (allowedFeedback == null)
            {
                throw new HttpStatusException(HttpStatusCode.BadRequest, "Feedback not allowed for report");
            }

            var user = _dbContext.GetOrCreateUser(request.UserId);

            if (user.UserScopes.All(us => us.ScopeName != Scopes.SCOPE_REVIEWER))
            {
                throw new HttpStatusException(HttpStatusCode.BadRequest, "User is not authorized as a reviewer");
            }

            var existingFeedback = _dbContext.ReportFeedbacks.FirstOrDefault(rf => rf.UserId == request.UserId && rf.ReportId == request.ReportId);

            if (existingFeedback == null)
            {
                _dbContext.ReportFeedbacks.Add(new DbReportFeedback
                {
                    FeedbackId = allowedFeedback.FeedbackId,
                    ReportId   = request.ReportId,
                    User       = user
                });
            }
            else
            {
                existingFeedback.FeedbackId = allowedFeedback.FeedbackId;
            }

            _dbContext.SaveChanges();

            return(Ok());
        }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="request"> (optional)</param>
 /// <returns>Task of void</returns>
 public async System.Threading.Tasks.Task BotRegisterUserFeedbackPostAsync(RegisterUserFeedbackRequest request = null)
 {
     await BotRegisterUserFeedbackPostAsyncWithHttpInfo(request);
 }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="request"> (optional)</param>
        /// <returns>Task of ApiResponse</returns>
        public async System.Threading.Tasks.Task <ApiResponse <Object> > BotRegisterUserFeedbackPostAsyncWithHttpInfo(RegisterUserFeedbackRequest request = null)
        {
            var    localVarPath         = "/Bot/RegisterUserFeedback";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json-patch+json",
                "application/json",
                "text/json",
                "application/_*+json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
            };
            String localVarHttpHeaderAccept    = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (request != null && request.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(request); // http body (model) parameter
            }
            else
            {
                localVarPostBody = request; // byte array
            }

            // authentication (oauth2) required
            // oauth required
            if (!String.IsNullOrEmpty(Configuration.AccessToken))
            {
                localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                       Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                       localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("BotRegisterUserFeedbackPost", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <Object>(localVarStatusCode,
                                            localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                            null));
        }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="request"> (optional)</param>
 /// <returns></returns>
 public void BotRegisterUserFeedbackPost(RegisterUserFeedbackRequest request = null)
 {
     BotRegisterUserFeedbackPostWithHttpInfo(request);
 }