public HttpResponseMessage Post(string entity, [FromBody] JObject value)
        {
            // Add
            try
            {
                var collection = entity;
                OpenContentModuleConfig module = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);

                var    manifest = module.Settings.Template.Manifest;
                string editRole = manifest.GetEditRole();

                IDataSource ds        = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource);
                var         dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID);
                dsContext.Collection = collection;
                if (!DnnPermissionsUtils.HasEditPermissions(module, editRole, -1))
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                }
                ds.Add(dsContext, value.Properties().First().Value as JObject);

                return(Request.CreateResponse(HttpStatusCode.OK, ""));
            }
            catch (Exception exc)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
Exemple #2
0
        protected bool IsEditAllowed(int createdByUser)
        {
            string editRole = _manifest.GetEditRole();

            return((IsEditMode || DnnPermissionsUtils.HasEditRole(_module, editRole, createdByUser)) && // edit Role can edit without being in edit mode
                   DnnPermissionsUtils.HasEditPermissions(_module, editRole, createdByUser));
        }
Exemple #3
0
        public HttpResponseMessage Put(string entity, string id, [FromBody] JObject value)
        {
            // update
            try
            {
                OpenContentModuleConfig module = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);

                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 (!DnnPermissionsUtils.HasEditPermissions(module, 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);
                }
                App.Services.CacheAdapter.SyncronizeCache(module);

                return(Request.CreateResponse(HttpStatusCode.OK, ""));
            }
            catch (Exception exc)
            {
                App.Services.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;
                OpenContentModuleConfig module = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);
                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 (!DnnPermissionsUtils.HasEditPermissions(module, 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)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
Exemple #5
0
        public HttpResponseMessage Delete(string entity, string id)
        {
            try
            {
                OpenContentModuleConfig module = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);
                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 (!DnnPermissionsUtils.HasEditPermissions(module, 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)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
Exemple #6
0
        public HttpResponseMessage Post(string entity, [FromBody] JObject value)
        {
            // Add
            try
            {
                OpenContentModuleConfig module = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);

                var    manifest = module.Settings.Template.Manifest;
                string editRole = manifest.GetEditRole();

                IDataSource ds        = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource);
                var         dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID);

                if (!DnnPermissionsUtils.HasEditPermissions(module, editRole, -1))
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                }
                ds.Add(dsContext, value.Properties().First().Value as JObject);

                var dsItem = ds.Get(dsContext, dsContext.Id);
                var res    = new JObject();
                res["meta"] = new JObject();
                var items = new JArray();
                if (dsItem != null)
                {
                    var collection = App.Config.DefaultCollection;
                    var mf         = new ModelFactorySingle(dsItem, module, collection);
                    var model      = mf.GetModelAsJson(false);
                    items.Add(model);
                    model["id"]          = dsContext.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));

                //return Request.CreateResponse(HttpStatusCode.OK, "");
            }
            catch (Exception exc)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
        public HttpResponseMessage Delete(JObject json)
        {
            try
            {
                var    module          = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);
                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 content = null;
                if (module.IsListMode())
                {
                    content = ds.Get(dsContext, json["id"].ToString());
                    if (content != null)
                    {
                        createdByUserid = content.CreatedByUserId;
                    }
                }
                else
                {
                    dsContext.Single = true;
                    content          = ds.Get(dsContext, null);
                    if (content != null)
                    {
                        createdByUserid = content.CreatedByUserId;
                    }
                }

                //todo: can't we do some of these checks at the beginning of this method to fail faster?
                if (!DnnPermissionsUtils.HasEditPermissions(module, editRole, createdByUserid))
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                }
                AddNotifyInfo(dsContext);
                if (content != null)
                {
                    ds.Delete(dsContext, content);
                }
                App.Services.CacheAdapter.SyncronizeCache(module);
                return(Request.CreateResponse(HttpStatusCode.OK, ""));
            }
            catch (Exception exc)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
        public HttpResponseMessage Version(string id, string ticks)
        {
            var    module = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);
            JToken json   = new JObject();

            try
            {
                int createdByUserid = -1;

                IDataSource ds        = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource);
                var         dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID);

                var dsItem = ds.Get(dsContext, id);
                if (dsItem != null)
                {
                    var version = ds.GetVersion(dsContext, dsItem, new DateTime(long.Parse(ticks)));
                    if (version != null)
                    {
                        json            = version;
                        createdByUserid = dsItem.CreatedByUserId;
                    }
                }

                string editRole = module.Settings.Template.Manifest.GetEditRole();
                //todo: can't we do some of these checks at the beginning of this method to fail faster?
                if (!DnnPermissionsUtils.HasEditPermissions(module, editRole, createdByUserid))
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                }
                return(Request.CreateResponse(HttpStatusCode.OK, json));
            }
            catch (Exception exc)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
        public HttpResponseMessage Add(UpdateRequest req)
        {
            try
            {
                var    module   = OpenContentModuleConfig.Create(req.ModuleId, req.TabId, PortalSettings);
                string editRole = module.Settings.Template.Manifest.GetEditRole();

                var dataSource = new OpenContentDataSource();

                if (module.IsListMode())
                {
                    if (!DnnPermissionsUtils.HasEditPermissions(module, editRole, -1))
                    {
                        App.Services.Logger.Warn($"Failed the HasEditPermissions() check");
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Failed the HasEditPermissions() check"));
                    }
                    var dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID);
                    dsContext.Collection = req.Collection;

                    JToken data = req.json;
                    data["Title"] = ActiveModule.ModuleTitle;
                    dataSource.Add(dsContext, data);
                    App.Services.CacheAdapter.SyncronizeCache(module);
                    return(Request.CreateResponse(HttpStatusCode.OK, ""));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "It's not a list mode module"));
                }
            }
            catch (Exception exc)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
        public HttpResponseMessage Action(SubmitDTO req)
        {
            try
            {
                var    module          = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);
                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 (req.id != null)
                    {
                        var itemId = req.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;
                    }
                }

                //todo: can't we do some of these checks at the beginning of this method to fail faster?
                if (!DnnPermissionsUtils.HasEditPermissions(module, editRole, createdByUserid))
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                }
                try
                {
                    var res = ds.Action(dsContext, req.action, dsItem, req.form);
                    return(Request.CreateResponse(HttpStatusCode.OK, new
                    {
                        isValid = true,
                        result = res
                    }));
                }
                catch (DataNotValidException ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, new
                    {
                        isValid = false,
                        validMessage = ex.Message
                    }));
                }
            }
            catch (Exception exc)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
        public HttpResponseMessage Update(JObject json)
        {
            try
            {
                var    module          = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);
                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 (json["id"] != null)
                    {
                        var itemId = json["id"].ToString();
                        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;
                    }
                }

                //todo: can't we do some of these checks at the beginning of this method to fail faster?
                if (!DnnPermissionsUtils.HasEditPermissions(module, editRole, createdByUserid))
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                }

                AddNotifyInfo(dsContext);
                try
                {
                    if (dsItem == null)
                    {
                        ds.Add(dsContext, json["form"] as JObject);
                    }
                    else
                    {
                        ds.Update(dsContext, dsItem, json["form"] as JObject);
                    }
                    App.Services.CacheAdapter.SyncronizeCache(module);
                }
                catch (DataNotValidException ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, new
                    {
                        isValid = false,
                        validMessage = ex.Message
                    }));
                }

                if (json["form"]["ModuleTitle"] != null && json["form"]["ModuleTitle"].Type == JTokenType.String)
                {
                    string moduleTitle = json["form"]["ModuleTitle"].ToString();
                    ActiveModule.UpdateModuleTitle(moduleTitle);
                }
                else if (json["form"]["ModuleTitle"] != null && json["form"]["ModuleTitle"].Type == JTokenType.Object)
                {
                    if (json["form"]["ModuleTitle"][DnnLanguageUtils.GetCurrentCultureCode()] != null)
                    {
                        string moduleTitle = json["form"]["ModuleTitle"][DnnLanguageUtils.GetCurrentCultureCode()].ToString();
                        ActiveModule.UpdateModuleTitle(moduleTitle);
                    }
                }
                return(Request.CreateResponse(HttpStatusCode.OK, new
                {
                    isValid = true
                }));
            }
            catch (Exception exc)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
        public HttpResponseMessage Edit(string id)
        {
            try
            {
                var         module    = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);
                IDataSource ds        = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource);
                var         dsContext = OpenContentUtils.CreateDataContext(module);
                IDataItem   dsItem    = null;
                if (module.IsListMode())
                {
                    if (!string.IsNullOrEmpty(id)) // not a new item
                    {
                        dsItem = ds.Get(dsContext, id);
                    }
                }
                else
                {
                    dsContext.Single = true;
                    dsItem           = ds.Get(dsContext, null);
                }
                int createdByUserid = -1;
                var json            = ds.GetAlpaca(dsContext, true, true, true);
                if (ds is IDataActions)
                {
                    var actions = ((IDataActions)ds).GetActions(dsContext, dsItem);
                    if (json["options"] == null)
                    {
                        json["options"] = new JObject();
                    }
                    if (json["options"]["form"] == null)
                    {
                        json["options"]["form"] = new JObject();
                    }
                    if (json["options"]["form"]["buttons"] == null)
                    {
                        json["options"]["form"]["buttons"] = new JObject();
                    }
                    var buttons    = json["options"]["form"]["buttons"] as JObject;
                    var newButtons = new JObject();
                    foreach (var act in actions)
                    {
                        var but = buttons[act.Name];
                        if (but == null)
                        {
                            but = new JObject();
                        }
                        but["after"]         = act.AfterExecute;
                        newButtons[act.Name] = but;
                    }
                    json["options"]["form"]["buttons"] = newButtons;
                }
                if (dsItem != null)
                {
                    json["data"] = dsItem.Data;
                    if (json["schema"]["properties"]["ModuleTitle"] is JObject)
                    {
                        if (json["data"]["ModuleTitle"] != null && json["data"]["ModuleTitle"].Type == JTokenType.String)
                        {
                            json["data"]["ModuleTitle"] = ActiveModule.ModuleTitle;
                        }
                        else if (json["data"]["ModuleTitle"] != null && json["data"]["ModuleTitle"].Type == JTokenType.Object)
                        {
                            json["data"]["ModuleTitle"][DnnLanguageUtils.GetCurrentCultureCode()] = ActiveModule.ModuleTitle;
                        }
                    }
                    var versions = ds.GetVersions(dsContext, dsItem);
                    if (versions != null)
                    {
                        json["versions"] = versions;
                    }
                    createdByUserid = dsItem.CreatedByUserId;
                }

                var context       = new JObject();
                var currentLocale = DnnLanguageUtils.GetCurrentLocale(PortalSettings.PortalId);
                context["culture"]                = currentLocale.Code; //todo why not use  DnnLanguageUtils.GetCurrentCultureCode() ???
                context["defaultCulture"]         = LocaleController.Instance.GetDefaultLocale(PortalSettings.PortalId).Code;
                context["numberDecimalSeparator"] = currentLocale.Culture.NumberFormat.NumberDecimalSeparator;
                context["rootUrl"]                = System.Web.VirtualPathUtility.ToAbsolute(string.Concat(System.Web.HttpRuntime.AppDomainAppVirtualPath, "/"));
                context["alpacaCulture"]          = AlpacaEngine.AlpacaCulture(currentLocale.Code);
                context["bootstrap"]              = App.Services.CreateGlobalSettingsRepository(PortalSettings.PortalId).GetEditLayout() != AlpacaLayoutEnum.DNN;
                context["horizontal"]             = App.Services.CreateGlobalSettingsRepository(PortalSettings.PortalId).GetEditLayout() == AlpacaLayoutEnum.BootstrapHorizontal;
                json["context"] = context;

                //todo: can't we do some of these checks at the beginning of this method to fail faster?
                if (!DnnPermissionsUtils.HasEditPermissions(module, module.Settings.Manifest.GetEditRole(), createdByUserid))
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, json));
            }
            catch (Exception exc)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
Exemple #13
0
        protected bool HasEditPermissions(int createdByUser)
        {
            string editRole = _manifest.GetEditRole();

            return(DnnPermissionsUtils.HasEditPermissions(_module, editRole, createdByUser));
        }
        public HttpResponseMessage Put(string entity, string id, [FromBody] JObject value)
        {
            // update
            try
            {
                var collection = entity;
                OpenContentModuleConfig module = OpenContentModuleConfig.Create(ActiveModule, PortalSettings);

                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 (!DnnPermissionsUtils.HasEditPermissions(module, 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);
                }
                App.Services.CacheAdapter.SyncronizeCache(module);

                //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)
            {
                App.Services.Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }