コード例 #1
0
    /// <summary>
    /// Page_Load event.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Form == null)
        {
            return;
        }

        // Check if node updated and role permissions should be loaded
        if (!usRoles.HasValue && (Form.Mode != FormModeEnum.Insert))
        {
            // Check if node has own ACL
            if (EditedNode.NodeIsACLOwner)
            {
                DataSet dsRoles = AclItemInfoProvider.GetAllowedRoles(ValidationHelper.GetInteger(EditedNode.GetValue("NodeACLID"), 0), Permission, "RoleID");
                if (!DataHelper.DataSourceIsEmpty(dsRoles))
                {
                    IList <string> roles = DataHelper.GetStringValues(dsRoles.Tables[0], "RoleID");
                    usRoles.Value = TextHelper.Join(";", roles);
                }
            }
        }

        // Set after save operation
        Form.OnAfterSave += AddRoles;

        // Initialize UniSelector
        Reload(false);
    }
    /// <summary>
    /// PreRender action on which security settings are set.
    /// </summary>
    private void Page_PreRender(object sender, EventArgs e)
    {
        if ((Form == null) || !mDocumentSaved)
        {
            return;
        }

        TreeNode editedNode = Form.EditedObject as TreeNode;

        // Create or rebuild department content index
        CreateDepartmentContentSearchIndex(editedNode);

        if ((editedNode == null) || !editedNode.NodeIsACLOwner)
        {
            return;
        }

        ForumInfo        fi = ForumInfoProvider.GetForumInfo("Default_department_" + editedNode.NodeGUID, SiteContext.CurrentSiteID);
        MediaLibraryInfo mi = MediaLibraryInfoProvider.GetMediaLibraryInfo("Department_" + editedNode.NodeGUID, SiteContext.CurrentSiteName);

        // Check if forum of media library exists
        if ((fi == null) && (mi == null))
        {
            return;
        }

        // Get allowed roles ID
        int         aclID     = ValidationHelper.GetInteger(editedNode.GetValue("NodeACLID"), 0);
        DataSet     listRoles = AclItemInfoProvider.GetAllowedRoles(aclID, NodePermissionsEnum.Read, "RoleID");
        IList <int> roleIds   = null;


        if (!DataHelper.DataSourceIsEmpty(listRoles))
        {
            roleIds = DataHelper.GetIntegerValues(listRoles.Tables[0], "RoleID") as List <int>;
        }

        // Set permissions for forum
        if (fi != null)
        {
            // Get resource object
            ResourceInfo resForums = ResourceInfoProvider.GetResourceInfo("CMS.Forums");

            // Get permissions IDs
            var forumPermissions = PermissionNameInfoProvider.GetPermissionNames()
                                   .Column("PermissionID")
                                   .WhereEquals("ResourceID", resForums.ResourceID)
                                   .WhereNotEquals("PermissionName", CMSAdminControl.PERMISSION_READ)
                                   .WhereNotEquals("PermissionName", CMSAdminControl.PERMISSION_MODIFY);

            // Delete old permissions apart attach file permission
            ForumRoleInfoProvider.DeleteAllRoles(new WhereCondition().WhereEquals("ForumID", fi.ForumID).WhereIn("PermissionID", forumPermissions));

            // Set forum permissions
            ForumRoleInfoProvider.SetPermissions(fi.ForumID, roleIds, forumPermissions.Select(p => p.PermissionId).ToArray());

            // Log staging task
            SynchronizationHelper.LogObjectChange(fi, TaskTypeEnum.UpdateObject);
        }

        // Set permissions for media library
        if (mi == null)
        {
            return;
        }

        // Get resource object
        ResourceInfo resMediaLibs = ResourceInfoProvider.GetResourceInfo("CMS.MediaLibrary");

        // Get permissions IDs
        var where = new WhereCondition()
                    .WhereEquals("ResourceID", resMediaLibs.ResourceID)
                    .And()
                    .Where(new WhereCondition()
                           .WhereEquals("PermissionName", "LibraryAccess")
                           .Or()
                           .WhereEquals("PermissionName", "FileCreate"));

        DataSet     dsMediaLibPerm         = PermissionNameInfoProvider.GetPermissionNames().Where(where).Column("PermissionID");
        IList <int> mediaLibPermissionsIds = null;

        if (!DataHelper.DataSourceIsEmpty(dsMediaLibPerm))
        {
            mediaLibPermissionsIds = DataHelper.GetIntegerValues(dsMediaLibPerm.Tables[0], "PermissionID");
        }

        var deleteWhere = new WhereCondition()
                          .WhereEquals("LibraryID", mi.LibraryID)
                          .WhereIn("PermissionID", mediaLibPermissionsIds);

        // Delete old permissions only for Create file and See library content permissions
        MediaLibraryRolePermissionInfoProvider.DeleteAllRoles(deleteWhere.ToString(true));

        MediaLibraryRolePermissionInfoProvider.SetPermissions(mi.LibraryID, roleIds, mediaLibPermissionsIds);

        // Log staging task;
        SynchronizationHelper.LogObjectChange(mi, TaskTypeEnum.UpdateObject);
    }
コード例 #3
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        // Set general properties
        repUsers.DataBindByDefault = false;
        pagerElem.PageControl      = repUsers.ID;

        if (StopProcessing)
        {
            // Do nothing
            filterUsers.StopProcessing = true;
            srcUsers.StopProcessing    = true;
        }
        else
        {
            filterUsers.Visible          = ShowFilterControl;
            filterUsers.OnFilterChanged += filterUsers_OnFilterChanged;
            srcUsers.OnFilterChanged    += filterUsers_OnFilterChanged;

            // Basic control properties
            repUsers.HideControlForZeroRows = HideControlForZeroRows;
            repUsers.ZeroRowsText           = ZeroRowsText;


            TreeNode     node = null;
            TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

            // Check if path is set
            if (String.IsNullOrEmpty(Path))
            {
                TreeNode curDoc = DocumentContext.CurrentDocument;
                // Check if current document is department
                if ((curDoc != null) && (curDoc.NodeClassName.ToLowerCSafe() == DEPARTMENT_CLASS_NAME))
                {
                    node = DocumentContext.CurrentDocument;
                }
            }
            else
            {
                // Obtain document from specified path
                node = tree.SelectSingleNode(SiteName, Path, LocalizationContext.PreferredCultureCode, true, DEPARTMENT_CLASS_NAME, false, false, false);
            }

            // If department document exists and has own ACL continue with initializing controls
            if ((node != null) && node.NodeIsACLOwner)
            {
                // Get users and roles with read permission for department document
                int     aclId   = ValidationHelper.GetInteger(node.GetValue("NodeACLID"), 0);
                DataSet dsRoles = AclItemInfoProvider.GetAllowedRoles(aclId, NodePermissionsEnum.Read, "RoleID");
                DataSet dsUsers = AclItemInfoProvider.GetAllowedUsers(aclId, NodePermissionsEnum.Read, "UserID");

                string where = null;

                // Process users dataset to where condition
                if (!DataHelper.DataSourceIsEmpty(dsUsers))
                {
                    // Get allowed users ids
                    IList <string> users   = DataHelper.GetStringValues(dsUsers.Tables[0], "UserID");
                    string         userIds = TextHelper.Join(", ", users);

                    // Populate where condition with user condition
                    where = SqlHelper.AddWhereCondition("UserID IN (" + userIds + ")", where);
                }

                // Process roles dataset to where condition
                if (!DataHelper.DataSourceIsEmpty(dsRoles))
                {
                    // Get allowed roles ids
                    IList <string> roles   = DataHelper.GetStringValues(dsRoles.Tables[0], "RoleID");
                    string         roleIds = TextHelper.Join(", ", roles);

                    // Populate where condition with role condition
                    where = SqlHelper.AddWhereCondition("UserID IN (SELECT UserID FROM View_CMS_UserRole_MembershipRole_ValidOnly_Joined WHERE RoleID IN (" + roleIds + "))", where, "OR");
                }


                if (!String.IsNullOrEmpty(where))
                {
                    // Check if exist where condition and add it to current where condition
                    where = SqlHelper.AddWhereCondition(WhereCondition, where);

                    // Data source properties
                    srcUsers.WhereCondition     = where;
                    srcUsers.OrderBy            = OrderBy;
                    srcUsers.TopN               = SelectTopN;
                    srcUsers.SelectedColumns    = Columns;
                    srcUsers.SiteName           = SiteName;
                    srcUsers.FilterName         = filterUsers.ID;
                    srcUsers.SourceFilterName   = FilterName;
                    srcUsers.CacheItemName      = CacheItemName;
                    srcUsers.CacheDependencies  = CacheDependencies;
                    srcUsers.CacheMinutes       = CacheMinutes;
                    srcUsers.SelectOnlyApproved = SelectOnlyApproved;
                    srcUsers.SelectHidden       = SelectHidden;

                    // Init data properties
                    filterUsers.InitDataProperties(srcUsers);


                    #region "Repeater template properties"

                    // Apply transformations if they exist
                    if (!String.IsNullOrEmpty(TransformationName))
                    {
                        repUsers.ItemTemplate = CMSDataProperties.LoadTransformation(this, TransformationName);
                    }
                    if (!String.IsNullOrEmpty(AlternatingItemTransformationName))
                    {
                        repUsers.AlternatingItemTemplate = CMSDataProperties.LoadTransformation(this, AlternatingItemTransformationName);
                    }
                    if (!String.IsNullOrEmpty(FooterTransformationName))
                    {
                        repUsers.FooterTemplate = CMSDataProperties.LoadTransformation(this, FooterTransformationName);
                    }
                    if (!String.IsNullOrEmpty(HeaderTransformationName))
                    {
                        repUsers.HeaderTemplate = CMSDataProperties.LoadTransformation(this, HeaderTransformationName);
                    }
                    if (!String.IsNullOrEmpty(SeparatorTransformationName))
                    {
                        repUsers.SeparatorTemplate = CMSDataProperties.LoadTransformation(this, SeparatorTransformationName);
                    }

                    #endregion


                    // UniPager properties
                    pagerElem.PageSize       = PageSize;
                    pagerElem.GroupSize      = GroupSize;
                    pagerElem.QueryStringKey = QueryStringKey;
                    pagerElem.DisplayFirstLastAutomatically    = DisplayFirstLastAutomatically;
                    pagerElem.DisplayPreviousNextAutomatically = DisplayPreviousNextAutomatically;
                    pagerElem.HidePagerForSinglePage           = HidePagerForSinglePage;
                    pagerElem.Enabled = EnablePaging;

                    switch (PagingMode.ToLowerCSafe())
                    {
                    case "querystring":
                        pagerElem.PagerMode = UniPagerMode.Querystring;
                        break;

                    default:
                        pagerElem.PagerMode = UniPagerMode.PostBack;
                        break;
                    }


                    #region "UniPager template properties"

                    // UniPager template properties
                    if (!String.IsNullOrEmpty(PagesTemplate))
                    {
                        pagerElem.PageNumbersTemplate = CMSDataProperties.LoadTransformation(pagerElem, PagesTemplate);
                    }

                    if (!String.IsNullOrEmpty(CurrentPageTemplate))
                    {
                        pagerElem.CurrentPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, CurrentPageTemplate);
                    }

                    if (!String.IsNullOrEmpty(SeparatorTemplate))
                    {
                        pagerElem.PageNumbersSeparatorTemplate = CMSDataProperties.LoadTransformation(pagerElem, SeparatorTemplate);
                    }

                    if (!String.IsNullOrEmpty(FirstPageTemplate))
                    {
                        pagerElem.FirstPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, FirstPageTemplate);
                    }

                    if (!String.IsNullOrEmpty(LastPageTemplate))
                    {
                        pagerElem.LastPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, LastPageTemplate);
                    }

                    if (!String.IsNullOrEmpty(PreviousPageTemplate))
                    {
                        pagerElem.PreviousPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, PreviousPageTemplate);
                    }

                    if (!String.IsNullOrEmpty(NextPageTemplate))
                    {
                        pagerElem.NextPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, NextPageTemplate);
                    }

                    if (!String.IsNullOrEmpty(PreviousGroupTemplate))
                    {
                        pagerElem.PreviousGroupTemplate = CMSDataProperties.LoadTransformation(pagerElem, PreviousGroupTemplate);
                    }

                    if (!String.IsNullOrEmpty(NextGroupTemplate))
                    {
                        pagerElem.NextGroupTemplate = CMSDataProperties.LoadTransformation(pagerElem, NextGroupTemplate);
                    }

                    if (!String.IsNullOrEmpty(DirectPageTemplate))
                    {
                        pagerElem.DirectPageTemplate = CMSDataProperties.LoadTransformation(pagerElem, DirectPageTemplate);
                    }

                    if (!String.IsNullOrEmpty(LayoutTemplate))
                    {
                        pagerElem.LayoutTemplate = CMSDataProperties.LoadTransformation(pagerElem, LayoutTemplate);
                    }

                    #endregion


                    // Connects repeater with data source
                    repUsers.DataSource = srcUsers.DataSource;
                }
                else
                {
                    // Disable datasource
                    srcUsers.StopProcessing = true;
                }
            }
            else
            {
                // Disable datasource
                srcUsers.StopProcessing = true;
            }

            pagerElem.RebindPager();
            repUsers.DataBind();
        }
    }
コード例 #4
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do nothing
            srcUsers.StopProcessing = true;
        }
        else
        {
            TreeNode     node = null;
            TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

            // Check if path is set
            if (String.IsNullOrEmpty(Path))
            {
                TreeNode curDoc = DocumentContext.CurrentDocument;
                // Check if current document is department
                if ((curDoc != null) && (curDoc.NodeClassName.ToLowerCSafe() == DEPARTMENT_CLASS_NAME))
                {
                    node = DocumentContext.CurrentDocument;
                }
            }
            else
            {
                // Obtain document from specified path
                node = tree.SelectSingleNode(SiteName, Path, LocalizationContext.PreferredCultureCode, true, DEPARTMENT_CLASS_NAME, false, false, false);
            }

            // If department document exists and has own ACL continue with initializing controls
            if ((node != null) && AclInfoProvider.HasOwnAcl(node))
            {
                // Get users and roles with read permission for department document
                int     aclId   = ValidationHelper.GetInteger(node.GetValue("NodeACLID"), 0);
                DataSet dsRoles = AclItemInfoProvider.GetAllowedRoles(aclId, NodePermissionsEnum.Read, "RoleID");
                DataSet dsUsers = AclItemInfoProvider.GetAllowedUsers(aclId, NodePermissionsEnum.Read, "UserID");

                string where = null;

                // Process users dataset to where condition
                if (!DataHelper.DataSourceIsEmpty(dsUsers))
                {
                    // Get allowed users ids
                    IList <string> users   = DataHelper.GetStringValues(dsUsers.Tables[0], "UserID");
                    string         userIds = TextHelper.Join(", ", users);

                    // Populate where condition with user condition
                    where = SqlHelper.AddWhereCondition("UserID IN (" + userIds + ")", where);
                }

                // Process roles dataset to where condition
                if (!DataHelper.DataSourceIsEmpty(dsRoles))
                {
                    // Get allowed roles ids
                    IList <string> roles   = DataHelper.GetStringValues(dsRoles.Tables[0], "RoleID");
                    string         roleIds = TextHelper.Join(", ", roles);

                    // Populate where condition with role condition
                    where = SqlHelper.AddWhereCondition("UserID IN (SELECT UserID FROM View_CMS_UserRole_MembershipRole_ValidOnly_Joined WHERE RoleID IN (" + roleIds + "))", where, "OR");
                }


                if (!String.IsNullOrEmpty(where))
                {
                    // Check if exist where condition and add it to current where condition
                    where = SqlHelper.AddWhereCondition(WhereCondition, where);

                    // Set datasource properties
                    srcUsers.WhereCondition     = where;
                    srcUsers.OrderBy            = OrderBy;
                    srcUsers.TopN               = SelectTopN;
                    srcUsers.FilterName         = ValidationHelper.GetString(GetValue("WebPartControlID"), ID);
                    srcUsers.SourceFilterName   = FilterName;
                    srcUsers.SiteName           = SiteName;
                    srcUsers.CacheItemName      = CacheItemName;
                    srcUsers.CacheDependencies  = CacheDependencies;
                    srcUsers.CacheMinutes       = CacheMinutes;
                    srcUsers.SelectOnlyApproved = SelectOnlyApproved;
                    srcUsers.SelectHidden       = SelectHidden;
                    srcUsers.SelectedColumns    = Columns;
                }
                else
                {
                    srcUsers.StopProcessing = true;
                }
            }
            else
            {
                srcUsers.StopProcessing = true;
            }
        }
    }
コード例 #5
0
    /// <summary>
    /// PreRender action on which security settings are set.
    /// </summary>
    private void Page_PreRender(object sender, EventArgs e)
    {
        if ((Form == null) || !mDocumentSaved)
        {
            return;
        }

        TreeNode editedNode = Form.EditedObject as TreeNode;

        // Create or rebuild department content index
        CreateDepartmentContentSearchIndex(editedNode);

        if ((editedNode == null) || !editedNode.NodeIsACLOwner)
        {
            return;
        }

        ForumInfo        fi = ForumInfoProvider.GetForumInfo("Default_department_" + editedNode.NodeGUID, SiteContext.CurrentSiteID);
        MediaLibraryInfo mi = MediaLibraryInfoProvider.GetMediaLibraryInfo("Department_" + editedNode.NodeGUID, SiteContext.CurrentSiteName);

        // Check if forum of media library exists
        if ((fi == null) && (mi == null))
        {
            return;
        }

        // Get allowed roles ID
        int     aclID     = ValidationHelper.GetInteger(editedNode.GetValue("NodeACLID"), 0);
        DataSet listRoles = AclItemInfoProvider.GetAllowedRoles(aclID, NodePermissionsEnum.Read, "RoleID");
        string  roleIDs   = null;

        if (!DataHelper.DataSourceIsEmpty(listRoles))
        {
            IList <string> roles = DataHelper.GetStringValues(listRoles.Tables[0], "RoleID");
            roleIDs = TextHelper.Join(";", roles);
        }

        // Set permissions for forum
        if (fi != null)
        {
            // Get resource object
            ResourceInfo resForums = ResourceInfoProvider.GetResourceInfo("CMS.Forums");

            // Get permissions IDs
            DataSet dsForumPerm      = PermissionNameInfoProvider.GetPermissionNames("ResourceID = " + resForums.ResourceID + " AND (PermissionName != '" + CMSAdminControl.PERMISSION_READ + "' AND PermissionName != '" + CMSAdminControl.PERMISSION_MODIFY + "')", null, 0, "PermissionID");
            string  forumPermissions = null;
            if (!DataHelper.DataSourceIsEmpty(dsForumPerm))
            {
                foreach (DataRow drForumPerm in dsForumPerm.Tables[0].Rows)
                {
                    forumPermissions += drForumPerm["PermissionID"] + ";";
                }
                forumPermissions = forumPermissions.TrimEnd(';');
            }

            // Delete old permissions apart attach file permission
            ForumRoleInfoProvider.DeleteAllRoles("ForumID = " + fi.ForumID + " AND PermissionID IN (" + forumPermissions.Replace(";", ", ") + ")");

            // Set forum permissions
            ForumRoleInfoProvider.SetPermissions(fi.ForumID, roleIDs, forumPermissions);

            // Log staging task
            SynchronizationHelper.LogObjectChange(fi, TaskTypeEnum.UpdateObject);
        }

        // Set permissions for media library
        if (mi == null)
        {
            return;
        }

        // Get resource object
        ResourceInfo resMediaLibs = ResourceInfoProvider.GetResourceInfo("CMS.MediaLibrary");

        // Get permissions IDs
        DataSet dsMediaLibPerm      = PermissionNameInfoProvider.GetPermissionNames("ResourceID = " + resMediaLibs.ResourceID + " AND (PermissionName = 'LibraryAccess' OR PermissionName = 'FileCreate')", null, 0, "PermissionID");
        string  mediaLibPermissions = null;

        if (!DataHelper.DataSourceIsEmpty(dsMediaLibPerm))
        {
            foreach (DataRow drMediaLibPerm in dsMediaLibPerm.Tables[0].Rows)
            {
                mediaLibPermissions += drMediaLibPerm["PermissionID"] + ";";
            }
            mediaLibPermissions = mediaLibPermissions.TrimEnd(';');
        }

        // Delete old permissions only for Create file and See library content permissions
        MediaLibraryRolePermissionInfoProvider.DeleteAllRoles("LibraryID = " + mi.LibraryID + " AND PermissionID IN (" + mediaLibPermissions.Replace(";", ", ") + ")");

        // Set media library permissions
        MediaLibraryRolePermissionInfoProvider.SetPermissions(mi.LibraryID, roleIDs, mediaLibPermissions);

        // Log staging task
        SynchronizationHelper.LogObjectChange(mi, TaskTypeEnum.UpdateObject);
    }