Example #1
0
        /// <summary>
        /// Gets the status friendly name.
        /// </summary>
        /// <returns></returns>
        public static string GetStatusName(int statusId)
        {
            string cacheKey = CmsCache.CreateCacheKey(String.Format("workflow-statusname{0}", statusId));

            // check cache first
            object cachedObject = CmsCache.Get(cacheKey);

            if (cachedObject != null)
            {
                return((string)cachedObject);
            }

            string statusName = String.Empty;

            using (IDataReader reader = WorkflowStatus.LoadById(statusId))
            {
                if (reader.Read())
                {
                    statusName = reader["FriendlyName"].ToString();
                }

                reader.Close();
            }

            // Insert to the cache collection
            CmsCache.Insert(cacheKey, statusName, CmsConfiguration.Instance.Cache.WorkflowTimeout);

            return(statusName);
        }
Example #2
0
        /// <summary>
        /// Determines whether there is a language version exists for a specified page.
        /// It will return true, if user specified has a draft version already created.
        /// It will return false if version does not exist or if currently logged in user does not
        /// have access to the status'es page versions are in.
        ///
        /// Specify version id to check if current user has access to that specific version.
        /// </summary>
        /// <param name="pageId">The page id.</param>
        /// <param name="langId">The lang id.</param>
        /// <param name="versionId">The version id.</param>
        /// <returns>
        ///     <c>true</c> if [has language version] [the specified page id]; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasLanguageVersion(int pageId, int langId, int versionId)
        {
            // Load current user
            Guid userId = (Guid)ProfileContext.Current.User.ProviderUserKey;

            // Load user roles and populate status ids allowed for user roles
            string[] roles = Roles.GetRolesForUser();

            ArrayList allowedStatusId = new ArrayList();

            if (roles != null && roles.Length > 0)
            {
                foreach (string role in roles)
                {
                    ArrayList statusList = WorkflowAccess.LoadListByRoleId(role);

                    foreach (object status in statusList)
                    {
                        if (!allowedStatusId.Contains(status))
                        {
                            allowedStatusId.Add(status);
                        }
                    }
                }
            }

            //get archive status id
            int archiveStatusId = WorkflowStatus.GetArcStatus(0);

            using (IDataReader reader = PageVersion.GetVersionByLangId(pageId, langId))
            {
                while (reader.Read())
                {
                    // Check the access to the specific version
                    if (versionId > 0 && versionId != (int)reader["VersionId"])
                    {
                        continue;
                    }

                    int statusId = (int)reader["StatusId"];
                    using (IDataReader status = WorkflowStatus.LoadById(statusId))
                    {
                        if (status.Read())
                        {
                            if (statusId == archiveStatusId || allowedStatusId.Contains(statusId))
                            {
                                versionId = (int)reader["VersionId"];
                                status.Close();
                                return(true);
                            }
                        }

                        status.Close();
                    }

                    //add user draft
                    Guid ownerKey = new Guid(reader["EditorUID"].ToString());
                    if (statusId == WorkflowStatus.DraftId && userId == ownerKey)
                    {
                        versionId = (int)reader["VersionId"];
                        reader.Close();
                        return(true);
                    }
                }

                reader.Close();
            }
            return(false);
        }