Пример #1
0
        public ActionResult Settings()
        {
            if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Yout have to be an Administrator to edit ContentTypePermission settings!")))
            {
                return(new HttpUnauthorizedResult());
            }
            var model        = _contentTypePermissionSettingsService.ReadSettings();
            var listconttype = _contentDefinitionService.GetTypes().Select(x => new SelectListItem()
            {
                Text = x.DisplayName, Value = x.Name
            }).ToList();

            listconttype.Insert(0, new SelectListItem {
                Text = " ", Value = " "
            });

            ViewData["ListContentTypes"] = new SelectList(listconttype, "Value", "Text");
            //_orchardServices..ContentManager.GetContentTypeDefinitions()
            var tmplistpermissions = _roleService.GetInstalledPermissions();
            List <SelectListItem> listpermissions = new List <SelectListItem>();

            foreach (IEnumerable <Permission> sad in tmplistpermissions.Values)
            {
                foreach (Permission perm in sad)
                {
                    listpermissions.Add(new SelectListItem {
                        Text = perm.Name, Value = perm.Name
                    });
                }
            }
            listpermissions.Insert(0, new SelectListItem {
                Text = "", Value = ""
            });
            ViewData["ListPermissions"] = new SelectList(listpermissions.OrderBy(x => x.Text), "Value", "Text");
            // var listpermissions = _permissionProvider.GetPermissions();
            //  listpermissions.Select(x => new SelectListItem() { Text = x.Name, Value = x.Name });

            //    IDictionary<string, IEnumerable<Orchard.Security.Permissions.Permission>>



            //  .Select(x => new SelectListItem() { Text = x.Key, Value = x.Key });

            //_orchardServices.ContentManager.GetContentTypeDefinitions().Select(x => x.Name).ToList();

            //  var listpermissions = _contentDefinitionService.GetTypes().Select(x => new SelectListItem() { Text = x.DisplayName, Value = x.Name });
            //_orchardServices..ContentManager.GetContentTypeDefinitions()

            //      ViewData["ListContentTypes"] = new SelectList(listconttype, "Value", "Text");

            ContentTypePermissionRecord cpr = new ContentTypePermissionRecord();

            cpr.Id = 0;
            model.ListContPermission.Add(cpr);
            return(View(model));
        }
Пример #2
0
        protected override void Exporting(ContentTypePermissionSettingsPart part, ExportContentContext context)
        {
            var root     = context.Element(part.PartDefinition.Name);
            var settings = _contentTypePermissionSettingsService.ReadSettings();

            foreach (var perm in settings.ListContPermission)
            {
                XElement permission = new XElement("Permission");
                permission.SetAttributeValue("ContentType", perm.ContentType);
                permission.SetAttributeValue("PostPermission", perm.PostPermission);
                permission.SetAttributeValue("GetPermission", perm.GetPermission);
                permission.SetAttributeValue("DeletePermission", perm.DeletePermission);
                permission.SetAttributeValue("PublishPermission", perm.PublishPermission);
                root.Add(permission);
            }
        }
Пример #3
0
        public bool HasPermission(string ContentType, Methods method, IContent mycontent = null)
        {
            bool haspermission = false;
            List <ContentTypePermissionRecord> settings = _contentTypePermissionSettingsService.ReadSettings().ListContPermission.Where(x => x.ContentType == ContentType).ToList();

            if (settings != null && settings.Count > 0)
            {
                // test if exist one record in permission setting that enable user
                foreach (ContentTypePermissionRecord ctpr in settings)
                {
                    switch (method)
                    {
                    case Methods.Get:
                        if (TestPermission(ctpr.GetPermission, mycontent))
                        {
                            return(true);
                        }
                        break;

                    case Methods.Post:
                        if (TestPermission(ctpr.PostPermission, mycontent))
                        {
                            return(true);
                        }
                        break;

                    case Methods.Publish:
                        if (TestPermission(ctpr.PublishPermission, mycontent))
                        {
                            return(true);
                        }
                        break;

                    case Methods.Delete:
                        if (TestPermission(ctpr.DeletePermission, mycontent))
                        {
                            return(true);
                        }
                        break;
                    }
                }
            }
            else
            {
                // test generic permission for contenttype
                switch (method)
                {
                case Methods.Get:
                    return(TestPermission("ViewContent", mycontent));

                case Methods.Post:
                    return(TestPermission("EditContent", mycontent));

                case Methods.Publish:
                    return(TestPermission("PublishContent", mycontent));

                case Methods.Delete:
                    return(TestPermission("DeleteContent", mycontent));
                }
            }

            return(haspermission);
        }