private static Dictionary <string, object> CreateAce(SnAccessControlEntry entry)
        {
            var perms = new Dictionary <string, object>();

            foreach (var perm in entry.Permissions)
            {
                if (perm.Allow || perm.Deny)
                {
                    perms.Add(perm.Name, new Dictionary <string, object>
                    {
                        { "value", perm.Allow ? "allow" : "deny" },
                        { "from", perm.AllowFrom ?? perm.DenyFrom },
                        { "identity", entry.Identity.Path }
                    });
                }
                else
                {
                    perms.Add(perm.Name, null);
                }
            }
            var ace = new Dictionary <string, object>
            {
                { "identity", PermissionQuery.GetIdentity(entry) },
                { "propagates", entry.Propagates },
                { "permissions", perms }
            };

            return(ace);
        }
        protected void ButtonAddSelected_Click(object sender, EventArgs e)
        {
            if (ListEntries.SelectedIndex < 0)
            {
                return;
            }

            var acl     = this.Acl.Entries.ToList();
            var aceList = new List <SnAccessControlEntry>();
            var index   = 0;

            foreach (ListItem item in ListEntries.Items)
            {
                if (!item.Selected)
                {
                    continue;
                }

                var propagates = CheckBoxLocalOnly == null ? true : !CheckBoxLocalOnly.Checked;
                var identityId = NodeHead.Get(item.Value).Id;
                var ace        = SnAccessControlEntry.CreateEmpty(identityId, propagates);

                if (_customEntryIds != null && !_customEntryIds.Contains(identityId))
                {
                    _customEntryIds.Add(identityId);
                }

                // add to new entries
                aceList.Add(ace);

                // insert into the top of old entries
                acl.Insert(index++, ace);
            }

            this.Acl.Entries = acl;

            // clear this to refresh
            PermissionIds = null;

            this.Isi.AddToAceVisiblityList(aceList);
            RebuildEntryIdList();

            // hide select panel
            this.Isi.Visible = false;
            RefreshAddEntryPanel();

            RefreshListView();
        }
Exemple #3
0
        private static Dictionary <string, object> CreateAce(SnAccessControlEntry entry)
        {
            string ancestor    = null;
            var    isInherited = true;
            var    perms       = new Dictionary <string, object>();

            foreach (var perm in entry.Permissions)
            {
                if (perm.Allow || perm.Deny)
                {
                    var from = GetSafeAncestorPath(perm.AllowFrom ?? perm.DenyFrom);
                    if (from != null && from.Length > (ancestor?.Length ?? 0))
                    {
                        ancestor = from;
                    }
                    if (from == null)
                    {
                        isInherited = false;
                    }

                    perms.Add(perm.Name, new Dictionary <string, object>
                    {
                        { "value", perm.Allow ? "allow" : "deny" },
                        { "from", from },
                    });
                }
                else
                {
                    perms.Add(perm.Name, null);
                }
            }

            var ace = new Dictionary <string, object>
            {
                { "identity", PermissionQuery.GetIdentity(entry) },
                { "ancestor", ancestor },
                { "inherited", isInherited },
                { "propagates", entry.Propagates },
                { "permissions", perms }
            };

            return(ace);
        }
        protected void ButtonAddSelected_Click(object sender, EventArgs e)
        {
            if (ListEntries.SelectedIndex < 0)
            {
                return;
            }

            var acl     = this.Acl.Entries.ToList();
            var aceList = new List <SnAccessControlEntry>();
            var index   = 0;

            foreach (ListItem item in ListEntries.Items)
            {
                if (!item.Selected)
                {
                    continue;
                }

                var node = Node.LoadNode(item.Value);
                var ace  = SnAccessControlEntry.CreateEmpty(node.Id, true);

                //add to new entries
                aceList.Add(ace);

                //insert into the top of old entries
                acl.Insert(index++, ace);
            }

            this.Acl.Entries = acl;

            //clear this to refresh
            PermissionIds = null;

            this.Isi.AddToAceVisiblityList(aceList);
            RebuildEntryIdList();

            //hide select panel
            this.Isi.Visible = false;
            RefreshAddEntryPanel();

            RefreshListView();
        }
 internal static object GetIdentity(SnAccessControlEntry entry)
 {
     return(GetIdentity(Node.LoadNode(entry.Identity.Path)));
 }
        // ======================================================================= Event handlers

        protected void ListViewAcl_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            var dataItem = e.Item as ListViewDataItem;

            if (dataItem == null)
            {
                return;
            }

            var ace = dataItem.DataItem as SnAccessControlEntry;

            if (ace == null)
            {
                return;
            }

            // Pin the current entry. It is used by the
            // permission list databinding method.
            _currentAce = ace;

            var lblName = GetIdentityControl(dataItem);

            if (lblName != null)
            {
                var identity = Node.Load <GenericContent>(ace.Identity.Path);
                var name     = identity is User ? ((User)identity).Username : identity.Name;
                if (!identity.Path.StartsWith(RepositoryStructure.ImsFolderPath))
                {
                    name = name + " " + HttpContext.GetGlobalResourceObject("Portal", "PermissionLocalGroup");
                }
                else
                {
                    name = identity.Path.Substring(RepositoryStructure.ImsFolderPath.Length + 1);
                }
                lblName.Text = string.Format("{0} ({1})", ContentRepository.Content.Create(identity).DisplayName, name);
            }

            var lblIcon = GetIdentityIconControl(dataItem);

            if (lblIcon != null)
            {
                try
                {
                    lblIcon.CssClass += " snIconBig_" + ContentType.GetByName(Enum.GetName(typeof(SnIdentityKind), ace.Identity.Kind)).Icon;
                }
                catch (Exception ex)
                {
                    SnLog.WriteException(ex);
                }
            }

            var lvAce = GetPermissionListViewControl(dataItem);

            if (lvAce != null)
            {
                lvAce.ItemDataBound += ListViewAce_ItemDataBound;
                lvAce.DataSource     = ace.Permissions.Take(VisiblePermissionCount);
                lvAce.DataBind();
            }

            var lblHidden = GetHiddenAceLabel(dataItem);

            if (lblHidden != null)
            {
                lblHidden.Text = this.EntryIds[ace];
            }

            RefreshAcePanelVisibility(dataItem);
        }