예제 #1
0
    private void ReloadData()
    {
        if (StopProcessing)
        {
            // Do nothing
            editDoc.StopProcessing = true;
        }
        else
        {
            SetContext();
            bool isAuthorizedToCreateDoc = false;
            if (ParentNode != null)
            {
                // Check if single class name is set
                string className = (!string.IsNullOrEmpty(AllowedChildClasses) && !AllowedChildClasses.Contains(";")) ? AllowedChildClasses : null;

                // Check user's permission to create new document if allowed
                isAuthorizedToCreateDoc = !CheckPermissions || MembershipContext.AuthenticatedUser.IsAuthorizedToCreateNewDocument(ParentNodeID, className);
                // Check group's permission to create new document if allowed
                isAuthorizedToCreateDoc &= CheckGroupPermission("createpages");

                if (!CheckDocPermissionsForInsert && CheckPermissions)
                {
                    // If document permissions are not required check create permission on parent document
                    isAuthorizedToCreateDoc = MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(ParentNode, NodePermissionsEnum.Create) == AuthorizationResultEnum.Allowed;
                }

                if (AllowUsers == UserContributionAllowUserEnum.DocumentOwner)
                {
                    // Do not allow documents creation under virtual user
                    if (MembershipContext.AuthenticatedUser.IsVirtual)
                    {
                        isAuthorizedToCreateDoc = false;
                    }
                    else
                    {
                        // Check if user is document owner (or global admin)
                        isAuthorizedToCreateDoc = isAuthorizedToCreateDoc && ((ParentNode.NodeOwner == MembershipContext.AuthenticatedUser.UserID) || MembershipContext.AuthenticatedUser.IsGlobalAdministrator);
                    }
                }
            }

            // Enable/disable inserting new document
            if (pnlList.Visible)
            {
                // Not authenticated to create new docs and grid is hidden
                StopProcessing = true;
            }

            ReleaseContext();
        }
    }
예제 #2
0
    /// <summary>
    /// Reloads control.
    /// </summary>
    /// <param name="forceReload">Forces nested CMSForm to reload if true</param>
    public void ReloadData(bool forceReload)
    {
        if (!mFormLoaded || forceReload)
        {
            // Check License
            LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.UserContributions);

            if (!StopProcessing)
            {
                // Set document manager mode
                if (NewDocument)
                {
                    DocumentManager.Mode           = FormModeEnum.Insert;
                    DocumentManager.ParentNodeID   = NodeID;
                    DocumentManager.NewNodeClassID = ClassID;
                    DocumentManager.CultureCode    = CultureCode;
                    DocumentManager.SiteName       = SiteName;
                }
                else if (NewCulture)
                {
                    DocumentManager.Mode             = FormModeEnum.InsertNewCultureVersion;
                    DocumentManager.NodeID           = NodeID;
                    DocumentManager.CultureCode      = CultureCode;
                    DocumentManager.SiteName         = SiteName;
                    DocumentManager.SourceDocumentID = CopyDefaultDataFromDocumentID;
                }
                else
                {
                    DocumentManager.Mode        = FormModeEnum.Update;
                    DocumentManager.NodeID      = NodeID;
                    DocumentManager.SiteName    = SiteName;
                    DocumentManager.CultureCode = CultureCode;
                }

                ScriptHelper.RegisterDialogScript(Page);

                titleElem.TitleText = String.Empty;

                pnlSelectClass.Visible = false;
                pnlEdit.Visible        = false;
                pnlInfo.Visible        = false;
                pnlNewCulture.Visible  = false;
                pnlDelete.Visible      = false;

                // If node found, init the form

                if (NewDocument || (Node != null))
                {
                    // Delete action
                    if (Delete)
                    {
                        // Delete document
                        pnlDelete.Visible = true;

                        titleElem.TitleText = GetString("Content.DeleteTitle");
                        chkAllCultures.Text = GetString("ContentDelete.AllCultures");
                        chkDestroy.Text     = GetString("ContentDelete.Destroy");

                        lblQuestion.Text = GetString("ContentDelete.Question");
                        btnYes.Text      = GetString("general.yes");
                        // Prevent button double-click
                        btnYes.Attributes.Add("onclick", string.Format("document.getElementById('{0}').disabled=true;this.disabled=true;{1};", btnNo.ClientID, ControlsHelper.GetPostBackEventReference(btnYes, string.Empty, true, false)));
                        btnNo.Text = GetString("general.no");

                        DataSet culturesDS = CultureSiteInfoProvider.GetSiteCultures(SiteName);
                        if ((DataHelper.DataSourceIsEmpty(culturesDS)) || (culturesDS.Tables[0].Rows.Count <= 1))
                        {
                            chkAllCultures.Visible = false;
                            chkAllCultures.Checked = true;
                        }

                        if (Node.IsLink)
                        {
                            titleElem.TitleText    = GetString("Content.DeleteTitleLink") + " \"" + HTMLHelper.HTMLEncode(Node.NodeName) + "\"";
                            lblQuestion.Text       = GetString("ContentDelete.QuestionLink");
                            chkAllCultures.Checked = true;
                            plcCheck.Visible       = false;
                        }
                        else
                        {
                            titleElem.TitleText = GetString("Content.DeleteTitle") + " \"" + HTMLHelper.HTMLEncode(Node.NodeName) + "\"";
                        }
                    }
                    // New document or edit action
                    else
                    {
                        if (NewDocument)
                        {
                            titleElem.TitleText = GetString("Content.NewTitle");
                        }

                        // Document type selection
                        if (NewDocument && (ClassID <= 0))
                        {
                            // Use parent node
                            TreeNode parentNode = DocumentManager.ParentNode;
                            if (parentNode != null)
                            {
                                // Select document type
                                pnlSelectClass.Visible = true;

                                // Apply document type scope
                                string whereCondition = DocumentTypeScopeInfoProvider.GetScopeClassWhereCondition(parentNode);

                                var parentClassId = ValidationHelper.GetInteger(parentNode.GetValue("NodeClassID"), 0);
                                var siteId        = SiteInfoProvider.GetSiteID(SiteName);

                                // Get the allowed child classes
                                DataSet ds = AllowedChildClassInfoProvider.GetAllowedChildClasses(parentClassId, siteId)
                                             .Where(whereCondition)
                                             .OrderBy("ClassID")
                                             .Columns("ClassName", "ClassDisplayName", "ClassID");

                                ArrayList deleteRows = new ArrayList();

                                if (!DataHelper.DataSourceIsEmpty(ds))
                                {
                                    // Get the unwanted classes
                                    string allowed = AllowedChildClasses.Trim().ToLowerCSafe();
                                    if (!string.IsNullOrEmpty(allowed))
                                    {
                                        allowed = String.Format(";{0};", allowed);
                                    }

                                    var    userInfo  = MembershipContext.AuthenticatedUser;
                                    string className = null;
                                    // Check if the user has 'Create' permission per Content
                                    bool isAuthorizedToCreateInContent = userInfo.IsAuthorizedPerResource("CMS.Content", "Create");
                                    bool hasNodeAllowCreate            = (userInfo.IsAuthorizedPerTreeNode(parentNode, NodePermissionsEnum.Create) != AuthorizationResultEnum.Allowed);
                                    foreach (DataRow dr in ds.Tables[0].Rows)
                                    {
                                        className = ValidationHelper.GetString(DataHelper.GetDataRowValue(dr, "ClassName"), String.Empty).ToLowerCSafe();
                                        // Document type is not allowed or user hasn't got permission, remove it from the data set
                                        if ((!string.IsNullOrEmpty(allowed) && (!allowed.Contains(";" + className + ";"))) ||
                                            (CheckPermissions && CheckDocPermissionsForInsert && !isAuthorizedToCreateInContent && !userInfo.IsAuthorizedPerClassName(className, "Create") && (!userInfo.IsAuthorizedPerClassName(className, "CreateSpecific") || !hasNodeAllowCreate)))
                                        {
                                            deleteRows.Add(dr);
                                        }
                                    }

                                    // Remove the rows
                                    foreach (DataRow dr in deleteRows)
                                    {
                                        ds.Tables[0].Rows.Remove(dr);
                                    }
                                }

                                // Check if some classes are available
                                if (!DataHelper.DataSourceIsEmpty(ds))
                                {
                                    // If number of classes is more than 1 display them in grid
                                    if (ds.Tables[0].Rows.Count > 1)
                                    {
                                        ds.Tables[0].DefaultView.Sort = "ClassDisplayName";
                                        lblError.Visible = false;
                                        lblInfo.Visible  = true;
                                        lblInfo.Text     = GetString("Content.NewInfo");

                                        DataSet sortedResult = new DataSet();
                                        sortedResult.Tables.Add(ds.Tables[0].DefaultView.ToTable());
                                        gridClass.DataSource = sortedResult;
                                        gridClass.ReloadData();
                                    }
                                    // else show form of the only class
                                    else
                                    {
                                        ClassID = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(ds.Tables[0].Rows[0], "ClassID"), 0);
                                        ReloadData(true);
                                        return;
                                    }
                                }
                                else
                                {
                                    // Display error message
                                    lblError.Visible  = true;
                                    lblError.Text     = GetString("Content.NoAllowedChildDocuments");
                                    lblInfo.Visible   = false;
                                    gridClass.Visible = false;
                                }
                            }
                            else
                            {
                                pnlInfo.Visible  = true;
                                lblFormInfo.Text = GetString("EditForm.DocumentNotFound");
                            }
                        }
                        // Insert or update of a document
                        else
                        {
                            // Display the form
                            pnlEdit.Visible = true;

                            // Try to get GroupID if group context exists
                            int currentGroupId = ModuleCommands.CommunityGetCurrentGroupID();

                            btnDelete.Attributes.Add("style", "display: none;");
                            btnRefresh.Attributes.Add("style", "display: none;");

                            // CMSForm initialization
                            formElem.NodeID                 = Node.NodeID;
                            formElem.SiteName               = SiteName;
                            formElem.CultureCode            = CultureCode;
                            formElem.ValidationErrorMessage = ValidationErrorMessage;
                            formElem.IsLiveSite             = IsLiveSite;

                            // Set group ID if group context exists
                            formElem.GroupID = currentGroupId;

                            // External editing is allowed for live site only if the permissions are checked or user is global administrator or for group context - user is group administrator
                            formElem.AllowExternalEditing = !IsLiveSite || CheckPermissions || MembershipContext.AuthenticatedUser.IsGlobalAdministrator || MembershipContext.AuthenticatedUser.IsGroupAdministrator(currentGroupId);

                            // Set the form mode
                            if (NewDocument)
                            {
                                ci = DataClassInfoProvider.GetDataClassInfo(ClassID);
                                if (ci == null)
                                {
                                    throw new Exception(String.Format("[CMSAdminControls/EditForm.aspx]: Class ID '{0}' not found.", ClassID));
                                }

                                string classDisplayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ci.ClassDisplayName));
                                titleElem.TitleText = GetString("Content.NewTitle") + ": " + classDisplayName;

                                // Set default template ID
                                formElem.DefaultPageTemplateID = TemplateID > 0 ? TemplateID : ci.ClassDefaultPageTemplateID;

                                // Set document owner
                                formElem.OwnerID  = OwnerID;
                                formElem.FormMode = FormModeEnum.Insert;
                                string newClassName = ci.ClassName;
                                string newFormName  = newClassName + ".default";
                                if (!String.IsNullOrEmpty(AlternativeFormName))
                                {
                                    // Set the alternative form full name
                                    formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName);
                                }
                                if (newFormName.ToLowerCSafe() != formElem.FormName.ToLowerCSafe())
                                {
                                    formElem.FormName = newFormName;
                                }
                            }
                            else if (NewCulture)
                            {
                                formElem.FormMode = FormModeEnum.InsertNewCultureVersion;
                                // Default data document ID
                                formElem.CopyDefaultDataFromDocumentId = CopyDefaultDataFromDocumentID;

                                ci = DataClassInfoProvider.GetDataClassInfo(Node.NodeClassName);
                                formElem.FormName = Node.NodeClassName + ".default";
                                if (!String.IsNullOrEmpty(AlternativeFormName))
                                {
                                    // Set the alternative form full name
                                    formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName);
                                }
                            }
                            else
                            {
                                formElem.FormMode = FormModeEnum.Update;
                                ci = DataClassInfoProvider.GetDataClassInfo(Node.NodeClassName);
                                formElem.FormName = String.Empty;
                                if (!String.IsNullOrEmpty(AlternativeFormName))
                                {
                                    // Set the alternative form full name
                                    formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName);
                                }
                            }

                            // Allow the CMSForm
                            formElem.StopProcessing = false;

                            ReloadForm();
                            formElem.LoadForm(true);
                        }
                    }
                }
                // New culture version
                else
                {
                    // Switch to new culture version mode
                    DocumentManager.Mode        = FormModeEnum.InsertNewCultureVersion;
                    DocumentManager.NodeID      = NodeID;
                    DocumentManager.CultureCode = CultureCode;
                    DocumentManager.SiteName    = SiteName;

                    if (Node != null)
                    {
                        // Offer a new culture creation
                        pnlNewCulture.Visible = true;

                        titleElem.TitleText    = GetString("Content.NewCultureVersionTitle") + " (" + HTMLHelper.HTMLEncode(MembershipContext.AuthenticatedUser.PreferredCultureCode) + ")";
                        lblNewCultureInfo.Text = GetString("ContentNewCultureVersion.Info");
                        radCopy.Text           = GetString("ContentNewCultureVersion.Copy");
                        radEmpty.Text          = GetString("ContentNewCultureVersion.Empty");

                        radCopy.Attributes.Add("onclick", "ShowSelection();");
                        radEmpty.Attributes.Add("onclick", "ShowSelection()");

                        AddScript(
                            "function ShowSelection() { \n" +
                            "   if (document.getElementById('" + radCopy.ClientID + "').checked) { document.getElementById('divCultures').style.display = 'block'; } \n" +
                            "   else { document.getElementById('divCultures').style.display = 'none'; } \n" +
                            "} \n"
                            );

                        btnOk.Text = GetString("ContentNewCultureVersion.Create");

                        // Load culture versions
                        SiteInfo si = SiteInfoProvider.GetSiteInfo(Node.NodeSiteID);
                        if (si != null)
                        {
                            lstCultures.Items.Clear();

                            DataSet nodes = TreeProvider.SelectNodes(si.SiteName, Node.NodeAliasPath, TreeProvider.ALL_CULTURES, false, null, null, null, 1, false);
                            foreach (DataRow nodeCulture in nodes.Tables[0].Rows)
                            {
                                ListItem li = new ListItem();
                                li.Text  = CultureInfoProvider.GetCultureInfo(nodeCulture["DocumentCulture"].ToString()).CultureName;
                                li.Value = nodeCulture["DocumentID"].ToString();
                                lstCultures.Items.Add(li);
                            }
                            if (lstCultures.Items.Count > 0)
                            {
                                lstCultures.SelectedIndex = 0;
                            }
                        }
                    }
                    else
                    {
                        pnlInfo.Visible  = true;
                        lblFormInfo.Text = GetString("EditForm.DocumentNotFound");
                    }
                }
            }
            // Set flag that the form is loaded
            mFormLoaded = true;
        }
    }
    private void ReloadData()
    {
        if (StopProcessing)
        {
            // Do nothing
            gridDocs.StopProcessing = true;
            editDoc.StopProcessing  = true;
        }
        else
        {
            if (((AllowUsers == UserContributionAllowUserEnum.Authenticated) || (AllowUsers == UserContributionAllowUserEnum.DocumentOwner)) &&
                !AuthenticationHelper.IsAuthenticated())
            {
                // Not authenticated, do not display anything
                pnlList.Visible = false;
                pnlEdit.Visible = false;

                StopProcessing = true;
            }
            else
            {
                SetContext();

                // Hide document list
                gridDocs.Visible = false;

                // If the list of documents should be displayed ...
                if (DisplayList)
                {
                    // Get all documents of the current user
                    TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

                    // Generate additional where condition
                    WhereCondition condition = new WhereCondition(WhereCondition);

                    if (!String.IsNullOrEmpty(ClassNames))
                    {
                        condition.WhereIn("ClassName", ClassNames.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries));
                    }

                    // Add user condition
                    if (AllowUsers == UserContributionAllowUserEnum.DocumentOwner)
                    {
                        condition.WhereEquals("NodeOwner", MembershipContext.AuthenticatedUser.UserID);
                    }

                    // Get the documents
                    var query =
                        DocumentHelper.GetDocuments()
                        .OnSite(SiteName)
                        .Path(MacroResolver.ResolveCurrentPath(Path))
                        .Where(condition)
                        .OrderBy(OrderBy)
                        .Published(SelectOnlyPublished)
                        .NestingLevel(MaxRelativeLevel)
                        .CheckPermissions(CheckPermissions);

                    TreeProvider.SetQueryCultures(query, CultureCode, CombineWithDefaultCulture);

                    // Do not apply published from / to columns to make sure the published information is correctly evaluated
                    query.Properties.ExcludedVersionedColumns = new[] { "DocumentPublishFrom", "DocumentPublishTo" };

                    var ds = query.Result;

                    if (!DataHelper.DataSourceIsEmpty(ds))
                    {
                        // Display and initialize grid if datasource is not empty
                        gridDocs.Visible            = true;
                        gridDocs.DataSource         = ds;
                        gridDocs.OrderBy            = OrderBy;
                        editDoc.AlternativeFormName = AlternativeFormName;
                    }
                }

                bool isAuthorizedToCreateDoc = false;
                if (ParentNode != null)
                {
                    // Check if single class name is set
                    string className = (!string.IsNullOrEmpty(AllowedChildClasses) && !AllowedChildClasses.Contains(";")) ? AllowedChildClasses : null;

                    // Check user's permission to create new document if allowed
                    isAuthorizedToCreateDoc = !CheckPermissions || MembershipContext.AuthenticatedUser.IsAuthorizedToCreateNewDocument(ParentNodeID, className);
                    // Check group's permission to create new document if allowed
                    isAuthorizedToCreateDoc &= CheckGroupPermission("createpages");

                    if (!CheckDocPermissionsForInsert && CheckPermissions)
                    {
                        // If document permissions are not required check create permission on parent document
                        isAuthorizedToCreateDoc = MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(ParentNode, NodePermissionsEnum.Create) == AuthorizationResultEnum.Allowed;
                    }

                    if (AllowUsers == UserContributionAllowUserEnum.DocumentOwner)
                    {
                        if (VirtualContext.ReadonlyMode)
                        {
                            isAuthorizedToCreateDoc = false;
                        }
                        else
                        {
                            // Check if user is document owner (or global admin)
                            isAuthorizedToCreateDoc = isAuthorizedToCreateDoc &&
                                                      ((ParentNode.NodeOwner == MembershipContext.AuthenticatedUser.UserID) ||
                                                       MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin));
                        }
                    }
                }

                // Enable/disable inserting new document
                pnlNewDoc.Visible = (isAuthorizedToCreateDoc && AllowInsert);

                if (!gridDocs.Visible && !pnlNewDoc.Visible && pnlList.Visible)
                {
                    // Not authenticated to create new docs and grid is hidden
                    StopProcessing = true;
                }

                ReleaseContext();
            }
        }
    }
    private void ReloadData()
    {
        if (StopProcessing)
        {
            // Do nothing
            gridDocs.StopProcessing = true;
            editDoc.StopProcessing  = true;
        }
        else
        {
            if (((AllowUsers == UserContributionAllowUserEnum.Authenticated) || (AllowUsers == UserContributionAllowUserEnum.DocumentOwner)) &&
                !AuthenticationHelper.IsAuthenticated())
            {
                // Not authenticated, do not display anything
                pnlList.Visible = false;
                pnlEdit.Visible = false;

                StopProcessing = true;
            }
            else
            {
                SetContext();

                // Hide document list
                gridDocs.Visible = false;

                // If the list of documents should be displayed ...
                if (DisplayList)
                {
                    // Get all documents of the current user
                    TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

                    // Generate additional where condition
                    string classWhere = null;
                    if (!String.IsNullOrEmpty(ClassNames))
                    {
                        // Remove ending semicolon
                        classWhere = ClassNames.TrimEnd(';');
                        // Replace single apostrophs
                        classWhere = SqlHelper.GetSafeQueryString(classWhere, false);
                        // Replace ; with ','
                        classWhere = classWhere.Replace(";", "','");
                        if (!String.IsNullOrEmpty(classWhere))
                        {
                            classWhere = String.Format("ClassName IN ('{0}')", classWhere);
                        }
                    }

                    string where = SqlHelper.AddWhereCondition(WhereCondition, classWhere);

                    // Add user condition
                    if (AllowUsers == UserContributionAllowUserEnum.DocumentOwner)
                    {
                        where = SqlHelper.AddWhereCondition(where, "NodeOwner = " + MembershipContext.AuthenticatedUser.UserID);
                    }

                    // Ensure that required columns are included in "Columns" list
                    string columns = EnsureColumns();

                    // Get the documents
                    DataSet ds = DocumentHelper.GetDocuments(SiteName, MacroResolver.ResolveCurrentPath(Path), CultureCode, CombineWithDefaultCulture, null, where, OrderBy, MaxRelativeLevel, SelectOnlyPublished, 0, columns, tree);
                    if (CheckPermissions)
                    {
                        ds = TreeSecurityProvider.FilterDataSetByPermissions(ds, NodePermissionsEnum.Read, MembershipContext.AuthenticatedUser);
                    }

                    if (!DataHelper.DataSourceIsEmpty(ds))
                    {
                        // Display and initialize grid if datasource is not empty
                        gridDocs.Visible            = true;
                        gridDocs.DataSource         = ds;
                        gridDocs.OrderBy            = OrderBy;
                        editDoc.AlternativeFormName = AlternativeFormName;
                    }
                }

                bool isAuthorizedToCreateDoc = false;
                if (ParentNode != null)
                {
                    // Check if single class name is set
                    string className = (!string.IsNullOrEmpty(AllowedChildClasses) && !AllowedChildClasses.Contains(";")) ? AllowedChildClasses : null;

                    // Check user's permission to create new document if allowed
                    isAuthorizedToCreateDoc = !CheckPermissions || MembershipContext.AuthenticatedUser.IsAuthorizedToCreateNewDocument(ParentNodeID, className);
                    // Check group's permission to create new document if allowed
                    isAuthorizedToCreateDoc &= CheckGroupPermission("createpages");

                    if (!CheckDocPermissionsForInsert && CheckPermissions)
                    {
                        // If document permissions are not required check create permission on parent document
                        isAuthorizedToCreateDoc = MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(ParentNode, NodePermissionsEnum.Create) == AuthorizationResultEnum.Allowed;
                    }

                    if (AllowUsers == UserContributionAllowUserEnum.DocumentOwner)
                    {
                        // Do not allow documents creation under virtual user
                        if (MembershipContext.AuthenticatedUser.IsVirtual)
                        {
                            isAuthorizedToCreateDoc = false;
                        }
                        else
                        {
                            // Check if user is document owner (or global admin)
                            isAuthorizedToCreateDoc = isAuthorizedToCreateDoc && ((ParentNode.NodeOwner == MembershipContext.AuthenticatedUser.UserID) || MembershipContext.AuthenticatedUser.IsGlobalAdministrator);
                        }
                    }
                }

                // Enable/disable inserting new document
                pnlNewDoc.Visible = (isAuthorizedToCreateDoc && AllowInsert);

                if (!gridDocs.Visible && !pnlNewDoc.Visible && pnlList.Visible)
                {
                    // Not authenticated to create new docs and grid is hidden
                    StopProcessing = true;
                }

                ReleaseContext();
            }
        }
    }