protected void btnEnableGetCurrentPerson_Click(object sender, EventArgs e) { RestAction getCurrentUserAction = new RestActionService(new RockContext()).Queryable().Where(a => a.Path == "api/People/GetCurrentPerson").First(); Rock.Security.Authorization.AllowAllUsers(getCurrentUserAction, Authorization.VIEW); MarkAuthUnBlocked(); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> public void BindGrid() { int controllerId = int.MinValue; if (int.TryParse(PageParameter("controller"), out controllerId)) { var service = new RestActionService(new RockContext()); var sortProperty = gActions.SortProperty; IQueryable <RestAction> qry = service.Queryable() .Where(a => a.ControllerId == controllerId); if (sortProperty != null) { qry = qry.Sort(sortProperty); } else { qry = qry.OrderBy(c => c.Method); } gActions.DataSource = qry.ToList(); gActions.DataBind(); } }
private static int LoadByApiId2(string apiId, RockContext rockContext) { var RestActionService = new RestActionService(rockContext); return(RestActionService .Queryable().AsNoTracking() .Where(a => a.ApiId == apiId) .Select(c => c.Id) .FirstOrDefault()); }
private static int LoadByGuid2(Guid guid, RockContext rockContext) { var RestActionService = new RestActionService(rockContext); return(RestActionService .Queryable().AsNoTracking() .Where(c => c.Guid.Equals(guid)) .Select(c => c.Id) .FirstOrDefault()); }
private static RestActionCache LoadById2(int id, RockContext rockContext) { var restActionService = new RestActionService(rockContext); var restActionModel = restActionService.Get(id); if (restActionModel != null) { return(new RestActionCache(restActionModel)); } return(null); }
private void SaveRestAction() { var controllerActionId = hfControllerActionId.Value.AsInteger(); var rockContext = new RockContext(); var restAction = new RestActionService(rockContext).Get(controllerActionId); if (restAction != null) { restAction.CacheControlHeaderSettings = cpActionCacheSettings.CurrentCacheability.ToJson(); rockContext.SaveChanges(); } modalActionSettings.Hide(); BindGrid(); }
/// <summary> /// Queries the database by id with context. /// </summary> /// <param name="apiId">The API identifier.</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> private static RestActionCache QueryDbByApiIdWithContext(string apiId, RockContext rockContext) { var service = new RestActionService(rockContext); var entity = service.Queryable().AsNoTracking() .FirstOrDefault(a => a.ApiId == apiId); if (entity == null) { return(null); } var value = new RestActionCache(); value.SetFromEntity(entity); return(value); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { RestAction getCurrentUserAction = new RestActionService(new RockContext()).Queryable().Where(a => a.Path == "api/People/GetCurrentPerson").First(); bool isUnBlocked = getCurrentUserAction.IsAuthorized(Authorization.VIEW, null); if (isUnBlocked) { MarkAuthUnBlocked(); } else { MarkAuthBlocked(getCurrentUserAction); } } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { var service = new RestActionService(new RockContext()); var restAction = service.Get(PageParameter("RestActionId").AsInteger()); if (restAction != null) { var config = GlobalConfiguration.Configuration; var explorer = config.Services.GetApiExplorer(); var controllerActions = explorer.ApiDescriptions.Where(a => (a.ActionDescriptor.ControllerDescriptor.ControllerName == restAction.Controller.Name)); var apiDescription = controllerActions.FirstOrDefault(a => a.ID == restAction.ApiId); if (apiDescription != null) { hfUrl.Value = this.ResolveUrl("~/" + apiDescription.RelativePath); lUrlPreview.Text = apiDescription.HttpMethod.ToString().ToUpper() + " " + hfUrl.Value; btnDELETE.Visible = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Delete; btnGET.Visible = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Get; rblLoadAttributes.Visible = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Get; btnPUT.Visible = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Put; btnPOST.Visible = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Post; tbPayload.Visible = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Post || apiDescription.HttpMethod == System.Net.Http.HttpMethod.Put; foreach (var param in apiDescription.ParameterDescriptions) { if (param.Source == System.Web.Http.Description.ApiParameterSource.FromUri) { lstParameterValues.Value += param.Name + "|"; } } } else { // todo warning } } } }
private void ShowActionSettingsEdit(int controllerActionId) { var restAction = new RestActionService(new RockContext()).Get(controllerActionId); if (restAction.Method == "GET") { modalActionSettings.SubTitle = restAction.Path; hfControllerActionId.Value = controllerActionId.ToString(); var cacheHeader = restAction.CacheControlHeader; if (cacheHeader == null) { cacheHeader = new Rock.Utility.RockCacheability { RockCacheablityType = Rock.Utility.RockCacheablityType.NoCache }; } cpActionCacheSettings.CurrentCacheability = cacheHeader; modalActionSettings.Show(); } }