private void IndexModule(LuceneController lc, OpenContentModuleInfo module) { OpenContentUtils.CheckOpenContentSettings(module); if (module.IsListMode() && !module.Settings.IsOtherModule) { IndexModuleData(lc, module.ViewModule.ModuleID, module.Settings); } }
public HttpResponseMessage Put(string entity, string id, [FromBody] JObject value) { // update try { OpenContentModuleInfo module = new OpenContentModuleInfo(ActiveModule); string editRole = module.Settings.Template.Manifest.GetEditRole(); int createdByUserid = -1; IDataSource ds = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource); var dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID); IDataItem dsItem = null; if (module.IsListMode()) { if (id != null) { var itemId = id; dsItem = ds.Get(dsContext, itemId); if (dsItem != null) { createdByUserid = dsItem.CreatedByUserId; } } } else { dsContext.Single = true; dsItem = ds.Get(dsContext, null); if (dsItem != null) { createdByUserid = dsItem.CreatedByUserId; } } if (!OpenContentUtils.HasEditPermissions(PortalSettings, ActiveModule, editRole, createdByUserid)) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } if (dsItem == null) { ds.Add(dsContext, value.Properties().First().Value as JObject); } else { ds.Update(dsContext, dsItem, value.Properties().First().Value as JObject); } return(Request.CreateResponse(HttpStatusCode.OK, "")); } catch (Exception exc) { Log.Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
public HttpResponseMessage Put(string entity, string id, string memberAction, [FromBody] JObject value) { // action try { var collection = entity; OpenContentModuleInfo module = new OpenContentModuleInfo(ActiveModule); string editRole = module.Settings.Template.Manifest.GetEditRole(); int createdByUserid = -1; IDataSource ds = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource); var dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID); dsContext.Collection = collection; IDataItem dsItem = null; if (module.IsListMode()) { if (id != null) { var itemId = id; dsItem = ds.Get(dsContext, itemId); if (dsItem != null) { createdByUserid = dsItem.CreatedByUserId; } } } else { dsContext.Single = true; dsItem = ds.Get(dsContext, null); //dsItem = ctrl.GetFirstContent(module.ModuleID); if (dsItem != null) { createdByUserid = dsItem.CreatedByUserId; } } if (!OpenContentUtils.HasEditPermissions(PortalSettings, ActiveModule, editRole, createdByUserid)) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } //var indexConfig = OpenContentUtils.GetIndexConfig(settings.Template.Key.TemplateDir); JToken res = null; if (dsItem != null) { res = ds.Action(dsContext, memberAction, dsItem, value); } return(Request.CreateResponse(HttpStatusCode.OK, res)); } catch (Exception exc) { Log.Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
public HttpResponseMessage Delete(string entity, string id) { try { OpenContentModuleInfo module = new OpenContentModuleInfo(ActiveModule); string editRole = module.Settings.Template.Manifest.GetEditRole(); int createdByUserid = -1; IDataSource ds = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource); var dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID); IDataItem dsItem = null; if (module.IsListMode()) { if (id != null) { var itemId = id; dsItem = ds.Get(dsContext, itemId); if (dsItem != null) { createdByUserid = dsItem.CreatedByUserId; } } } else { dsContext.Single = true; dsItem = ds.Get(dsContext, null); if (dsItem != null) { createdByUserid = dsItem.CreatedByUserId; } } if (!OpenContentUtils.HasEditPermissions(PortalSettings, ActiveModule, editRole, createdByUserid)) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } //var indexConfig = OpenContentUtils.GetIndexConfig(settings.Template.Key.TemplateDir); if (dsItem != null) { ds.Delete(dsContext, dsItem); } return(Request.CreateResponse(HttpStatusCode.OK, "")); } catch (Exception exc) { Log.Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
public HttpResponseMessage List(RequestDTO req) { try { OpenContentModuleInfo module = new OpenContentModuleInfo(ActiveModule); JObject reqOptions = null; if (!string.IsNullOrEmpty(req.options)) { reqOptions = JObject.Parse(req.options); } if (module.IsListMode()) { var indexConfig = OpenContentUtils.GetIndexConfig(module.Settings.Template); QueryBuilder queryBuilder = new QueryBuilder(indexConfig); bool isEditable = ActiveModule.CheckIfEditable(PortalSettings); queryBuilder.Build(module.Settings.Query, !isEditable, UserInfo.UserID, DnnLanguageUtils.GetCurrentCultureCode(), UserInfo.Social.Roles); JplistQueryBuilder.MergeJpListQuery(indexConfig, queryBuilder.Select, req.StatusLst, DnnLanguageUtils.GetCurrentCultureCode()); IDataItems dsItems; if (queryBuilder.DefaultNoResults && queryBuilder.Select.IsQueryEmpty) { dsItems = new DefaultDataItems() { Items = new List <DefaultDataItem>(), Total = 0 }; } else { IDataSource ds = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource); var dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID, false, reqOptions); dsItems = ds.GetAll(dsContext, queryBuilder.Select); } var mf = new ModelFactoryMultiple(dsItems.Items, module, PortalSettings); mf.Options = reqOptions; var model = mf.GetModelAsJson(false, req.onlyItems); //model["luceneQuery"] = dsItems.DebugInfo; if (LogContext.IsLogActive) { LogContext.Log(ActiveModule.ModuleID, "RequestContext", "IsEditable", isEditable); LogContext.Log(ActiveModule.ModuleID, "RequestContext", "UserRoles", PortalSettings.UserInfo.Social.Roles.Select(r => r.RoleName)); LogContext.Log(ActiveModule.ModuleID, "RequestContext", "CurrentUserId", PortalSettings.UserId); var logKey = "Query"; LogContext.Log(ActiveModule.ModuleID, logKey, "select", queryBuilder.Select); LogContext.Log(ActiveModule.ModuleID, logKey, "debuginfo", dsItems.DebugInfo); LogContext.Log(ActiveModule.ModuleID, logKey, "model", model); model["Logs"] = JToken.FromObject(LogContext.Current.ModuleLogs(ActiveModule.ModuleID)); } var res = new ResultDTO() { data = model, count = dsItems.Total }; return(Request.CreateResponse(HttpStatusCode.OK, res)); } else { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "not supported because not in multi items template ")); } } catch (Exception exc) { Log.Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
public HttpResponseMessage Get(string entity, int pageIndex, int pageSize, string filter = null, string sort = null) { try { var collection = entity; //if (entity == "items") collection = AppConfig.DEFAULT_COLLECTION; // backward compatibility RestSelect restSelect = new RestSelect() { PageIndex = pageIndex, PageSize = pageSize }; if (!string.IsNullOrEmpty(filter)) { restSelect.Query = JsonConvert.DeserializeObject <RestGroup>(filter); } if (!string.IsNullOrEmpty(sort)) { restSelect.Sort = JsonConvert.DeserializeObject <List <RestSort> >(sort); } ModuleInfo activeModule = ActiveModule; OpenContentSettings settings = activeModule.OpenContentSettings(); OpenContentModuleInfo module = new OpenContentModuleInfo(ActiveModule); JObject reqOptions = null; if (module.IsListMode()) { var indexConfig = OpenContentUtils.GetIndexConfig(settings.TemplateDir, collection); QueryBuilder queryBuilder = new QueryBuilder(indexConfig); bool isEditable = ActiveModule.CheckIfEditable(PortalSettings); queryBuilder.Build(settings.Query, !isEditable, UserInfo.UserID, DnnLanguageUtils.GetCurrentCultureCode(), UserInfo.Social.Roles); RestQueryBuilder.MergeQuery(indexConfig, queryBuilder.Select, restSelect, DnnLanguageUtils.GetCurrentCultureCode()); IDataItems dsItems; if (queryBuilder.DefaultNoResults && queryBuilder.Select.IsQueryEmpty) { dsItems = new DefaultDataItems() { Items = new List <DefaultDataItem>(), Total = 0 }; } else { IDataSource ds = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource); var dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID, false, reqOptions); dsContext.Collection = collection; dsItems = ds.GetAll(dsContext, queryBuilder.Select); } var mf = new ModelFactoryMultiple(dsItems.Items, module, PortalSettings, collection); mf.Options = reqOptions; var model = mf.GetModelAsJson(false); var res = new JObject(); res["meta"] = new JObject(); if (LogContext.IsLogActive) { var logKey = "Query"; LogContext.Log(activeModule.ModuleID, logKey, "select", queryBuilder.Select); LogContext.Log(activeModule.ModuleID, logKey, "debuginfo", dsItems.DebugInfo); LogContext.Log(activeModule.ModuleID, logKey, "model", model); res["meta"]["logs"] = JToken.FromObject(LogContext.Current.ModuleLogs(activeModule.ModuleID)); if (restSelect != null) { //res["meta"]["select"] = JObject.FromObject(restSelect); } } foreach (var item in model["Items"] as JArray) { item["id"] = item["Context"]["Id"]; JsonUtils.IdJson(item); } res[entity] = model[collection]; res["meta"]["total"] = dsItems.Total; return(Request.CreateResponse(HttpStatusCode.OK, res)); } else { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "not supported because not in multi items template ")); } } catch (Exception exc) { Log.Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
public HttpResponseMessage Get(string entity, string id) { try { //if (entity == "items") var collection = AppConfig.DEFAULT_COLLECTION; OpenContentModuleInfo module = new OpenContentModuleInfo(ActiveModule); JObject reqOptions = null; //if (!string.IsNullOrEmpty(req.options)) //{ // reqOptions = JObject.Parse(req.options); //} //string editRole = manifest.GetEditRole(); if (module.IsListMode()) { var indexConfig = OpenContentUtils.GetIndexConfig(module.Settings.TemplateDir, collection); //bool isEditable = ActiveModule.CheckIfEditable(PortalSettings); IDataSource ds = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource); var dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID, false, reqOptions); dsContext.Collection = collection; var dsItem = ds.Get(dsContext, id); var res = new JObject(); res["meta"] = new JObject(); var items = new JArray(); if (dsItem != null) { var mf = new ModelFactorySingle(dsItem, module, PortalSettings, collection); string raison = ""; if (!OpenContentUtils.HaveViewPermissions(dsItem, PortalSettings.UserInfo, indexConfig, out raison)) { Exceptions.ProcessHttpException(new HttpException(404, "No detail view permissions for id=" + id + " (" + raison + ")")); //throw new UnauthorizedAccessException("No detail view permissions for id " + info.DetailItemId); } mf.Options = reqOptions; var model = mf.GetModelAsJson(false); items.Add(model); model["id"] = dsItem.Id; res["meta"]["total"] = dsItem == null ? 0 : 1; JsonUtils.IdJson(model); if (LogContext.IsLogActive) { var logKey = "Query"; LogContext.Log(module.ViewModule.ModuleID, logKey, "model", model); res["meta"]["logs"] = JToken.FromObject(LogContext.Current.ModuleLogs(module.ViewModule.ModuleID)); } } res[entity] = items; return(Request.CreateResponse(HttpStatusCode.OK, res)); } else { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "not supported because not in multi items template ")); } } catch (Exception exc) { Log.Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
public HttpResponseMessage Put(string entity, string id, [FromBody] JObject value) { // update try { var collection = entity; OpenContentModuleInfo module = new OpenContentModuleInfo(ActiveModule); string editRole = module.Settings.Template.Manifest.GetEditRole(); int createdByUserid = -1; IDataSource ds = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource); var dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID); dsContext.Collection = collection; IDataItem dsItem = null; if (module.IsListMode()) { if (id != null) { var itemId = id; dsItem = ds.Get(dsContext, itemId); if (dsItem != null) { createdByUserid = dsItem.CreatedByUserId; } } } else { dsContext.Single = true; dsItem = ds.Get(dsContext, null); if (dsItem != null) { createdByUserid = dsItem.CreatedByUserId; } } if (!OpenContentUtils.HasEditPermissions(PortalSettings, ActiveModule, editRole, createdByUserid)) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } //var indexConfig = OpenContentUtils.GetIndexConfig(settings.Template.Key.TemplateDir); if (dsItem == null) { ds.Add(dsContext, value.Properties().First().Value as JObject); } else { ds.Update(dsContext, dsItem, value.Properties().First().Value as JObject); } //if (json["form"]["ModuleTitle"] != null && json["form"]["ModuleTitle"].Type == JTokenType.String) //{ // string moduleTitle = json["form"]["ModuleTitle"].ToString(); // OpenContentUtils.UpdateModuleTitle(ActiveModule, moduleTitle); //} //else if (json["form"]["ModuleTitle"] != null && json["form"]["ModuleTitle"].Type == JTokenType.Object) //{ // if (json["form"]["ModuleTitle"][DnnUtils.GetCurrentCultureCode()] != null) // { // string moduleTitle = json["form"]["ModuleTitle"][DnnUtils.GetCurrentCultureCode()].ToString(); // OpenContentUtils.UpdateModuleTitle(ActiveModule, moduleTitle); // } //} return(Request.CreateResponse(HttpStatusCode.OK, "")); } catch (Exception exc) { Log.Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }