public IEnumerable <dynamic> Get(string schemaName, string tableName, [FromUri] object[] primaryKeys) { try { var repository = new FormRepository(schemaName, tableName, this.MetaUser.Tenant, this.MetaUser.LoginId, this.MetaUser.UserId); return(repository.Get(primaryKeys)); } catch (UnauthorizedException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (DataAccessException ex) { throw new HttpResponseException(new HttpResponseMessage { Content = new StringContent(ex.Message), StatusCode = HttpStatusCode.InternalServerError }); } #if !DEBUG catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } #endif }
public bool IsAuthorized(Guid formId, string email, AuthorizationType authorizationType, EndpointType endpointType) { //Check the base case. The creator of the form can do everything. var form = formRepository.Get(formId).Result; var user = userRepository.Search().Where(e => e.Email == email).ToList(); if (form.UserId == user[0].Id) { return(true); } //Otherwise check the who is authorized to do what on this form. var credentials = formUserAuthorizationRepository.Search().Where(e => e.FormId == formId && e.AspNetUser.Email == email).ToList(); if (credentials.Count() > 0) { if (endpointType == EndpointType.Form) { if (authorizationType == AuthorizationType.IsCreate) { return(credentials[0].IsCreateForm); } else if (authorizationType == AuthorizationType.IsRead) { return(credentials[0].IsReadForm); } else if (authorizationType == AuthorizationType.IsUpdate) { return(credentials[0].IsUpdateForm); } else { return(credentials[0].IsDeleteForm); } } else { if (authorizationType == AuthorizationType.IsCreate) { return(credentials[0].IsCreateData); } else if (authorizationType == AuthorizationType.IsRead) { return(credentials[0].IsReadData); } else if (authorizationType == AuthorizationType.IsUpdate) { return(credentials[0].IsUpdateData); } else { return(credentials[0].IsDeleteData); } } } else { return(false); } }
public FormDefinition Get(int id) { FormDefinition form = FormRepository.Get(id); if (form != null && !ProjectService.CanUserRead(form.ProjectID)) { return(null); } return(form); }
public async Task <IHttpActionResult> Get(Guid id) { FormViewModel model = null; try { var record = await repository.Get(id); if (!authorizationService.IsAuthorized(record.Id, user.Email, AuthorizationService.AuthorizationType.IsRead, AuthorizationService.EndpointType.Form)) { return(Content(HttpStatusCode.Forbidden, "You are not authorized to perform this action.")); } model = record.ToViewModel(); return(Content(HttpStatusCode.OK, model)); } catch (Exception ex) { Console.WriteLine(ex); return(Content(HttpStatusCode.InternalServerError, ex)); } }
private void PopulateFormData() { DateTime from; if (!DateTime.TryParse(txtFrom.Text, out from)) { warnFrom.Text = Constants.Texts.Warning.IncorrectDateFromat; return; } DateTime to; if (!DateTime.TryParse(txtTo.Text, out to)) { warnTo.Text = Constants.Texts.Warning.IncorrectDateFromat;; return; } // If passed in "3/17/2015"; covert it to "3/17/2015 23:59:59" if (to.Hour == 0 && to.Minute == 0 && to.Second == 0) { to = to.Add(new TimeSpan(23, 59, 59)); } var formData = _formRepository.Get(new Sitecore.Data.ID(this.ItemID), from, to); if (formData.Any()) { BindTableHeader(formData); BindTableRows(formData); foreach (var form in formData) { IEnumerable <IField> fileds = form.Field; } } }