Пример #1
0
        public static bool HasUnlockAccess(SC.Data.Items.Item item, SC.Security.Accounts.User user = null)
        {
            Assert.ArgumentNotNull(item, "item");

            if (user == null)
            {
                user = SC.Context.User;
                Assert.IsNotNull(user, "context user");
            }

            if (user.IsAdministrator)
            {
                return(true);
            }

            SC.Security.AccessControl.AccessRight checkIn = SC.Security.AccessControl.AccessRight.FromName("item:checkin");

            if (checkIn != null)
            {
                return(SC.Security.AccessControl.AuthorizationManager.IsAllowed(item, checkIn, user));
            }

            SC.Security.Accounts.Role control = SC.Security.Accounts.Role.FromName("sitecore\\Sitecore Client Maintaining");

            return(SC.Security.Accounts.Role.Exists(control.Name) && SC.Security.Accounts.RolesInRolesManager.IsUserInRole(SC.Context.User, control, true /*includeIndirectMembership*/));
        }
Пример #2
0
        /// <summary>
        /// Apply the rule.
        /// </summary>
        /// <param name="ruleContext">Rule processing context.</param>
        public override void Apply(T ruleContext)
        {
            Assert.ArgumentNotNull(ruleContext, "ruleContext");
            Assert.ArgumentNotNull(ruleContext.Item, "ruleContext.Item");

            // for each language available in the item
            foreach (SC.Globalization.Language lang in ruleContext.Item.Languages)
            {
                SC.Data.Items.Item item = ruleContext.Item.Database.GetItem(
                    ruleContext.Item.ID,
                    lang);

                if (item == null)
                {
                    continue;
                }

                // to prevent the while loop from reaching MinVersions,
                // only process this number of items
                int limit = item.Versions.Count - this.MinVersions;
                int i     = 0;

                while (item.Versions.Count > this.MinVersions && i < limit)
                {
                    SC.Data.Items.Item version = item.Versions.GetVersions()[i++];
                    Assert.IsNotNull(version, "version");

                    if (this.MinUpdatedDays < 1 ||
                        version.Statistics.Updated.AddDays(this.MinUpdatedDays) < DateTime.Now)
                    {
                        this.HandleVersion(version);
                    }
                }
            }
        }
Пример #3
0
        public void Process(SC.Pipelines.GetContentEditorWarnings.GetContentEditorWarningsArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            SC.Data.Items.Item item = args.Item;

            if (item == null)
            {
                return;
            }

            if (SC.Context.IsAdministrator || CheckIn.CanCheckIn(item))
            {
                if (item.Locking.IsLocked() && (string.Compare(item.Locking.GetOwner(), SC.Context.User.Name, StringComparison.InvariantCultureIgnoreCase) != 0))
                {
                    SC.Pipelines.GetContentEditorWarnings.GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add();
                    warning.Title = SC.Globalization.Translate.Text("'{0}' has locked this item.", new object[] { item.Locking.GetOwnerWithoutDomain() });
                    warning.AddOption(SC.Globalization.Translate.Text("Check In"), string.Format("item:checkin(id={0},language={1},version={2})", item.ID, item.Language, item.Version.Number));
                }
            }
            else if (item.Locking.IsLocked())
            {
                if (!item.Locking.HasLock())
                {
                    args.Add(SC.Globalization.Translate.Text("You cannot edit this item because '{0}' has locked it.", new object[] { item.Locking.GetOwnerWithoutDomain() }), string.Empty);
                }
            }
            else if (SC.Configuration.Settings.RequireLockBeforeEditing && SC.Data.Managers.TemplateManager.IsFieldPartOfTemplate(SC.FieldIDs.Lock, item))
            {
                SC.Pipelines.GetContentEditorWarnings.GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add();
                warning.Title = SC.Globalization.Translate.Text("You must lock this item before you can edit it.");
                warning.Text  = SC.Globalization.Translate.Text("To lock this item, click Edit on the Home tab.");
                warning.AddOption(SC.Globalization.Translate.Text("Lock and Edit"), "item:checkout");
            }
        }
Пример #4
0
        public override SC.Shell.Framework.Commands.CommandState QueryState(SC.Shell.Framework.Commands.CommandContext context)
        {
            Assert.ArgumentNotNull(context, "context");

            if (context.Items.Length != 1)
            {
                return(base.QueryState(context));
            }

            SC.Data.Items.Item item = context.Items[0];
            Assert.ArgumentNotNull(item, "context.Items[0]");

            if (SC.Context.IsAdministrator || !CheckIn.CanCheckIn(item))
            {
                return(base.QueryState(context));
            }

            if (!item.Locking.IsLocked())
            {
                return(SC.Shell.Framework.Commands.CommandState.Hidden);
            }

            if (CanCheckIn(item))
            {
                return(SC.Shell.Framework.Commands.CommandState.Enabled);
            }

            return(base.QueryState(context));
        }
Пример #5
0
        /// <summary>
        /// Triggered by Sitecore to initialize the index rebuilding strategy.
        /// </summary>
        /// <param name="index">Index associated with the index rebuilding strategy.</param>
        public void Initialize(SC.ContentSearch.ISearchIndex index)
        {
            Assert.ArgumentNotNull(index, "index");

            if (this._ruleDatabase == null && !string.IsNullOrEmpty(index.Name))
            {
                string[] parts = index.Name.Split('_');

                if (parts.Length > 1)
                {
                    this._ruleDatabase = SC.Configuration.Factory.GetDatabase(parts[1]);
                }
            }

            SC.Diagnostics.Assert.IsNotNull(this._ruleDatabase, "_ruleDatabase");

            if (string.IsNullOrEmpty(this._indexedDatabaseName))
            {
                this._indexedDatabaseName = this._ruleDatabase.Name;
            }

            SC.ContentSearch.Diagnostics.CrawlingLog.Log.Info(string.Format(
                                                                  "[Index={0}] Initializing {1} with interval '{2}'.",
                                                                  index.Name,
                                                                  this.GetType().Name,
                                                                  this._alarmClock.Interval));
            this._index            = index;
            this._alarmClock.Ring += (sender, args) => this.Handle(args);
        }
Пример #6
0
        public ManagerResponse <CreateUserResult, CommerceUser> RegisterUserCustomer(IStorefrontContext storefrontContext, string userName, string password,
                                                                                     string email, string secondaryEmail)
        {
            Assert.ArgumentNotNull(storefrontContext, nameof(storefrontContext));
            Assert.ArgumentNotNullOrEmpty(userName, nameof(userName));
            Assert.ArgumentNotNullOrEmpty(password, nameof(password));
            CreateUserResult createUserResult1;

            try
            {
                var createUserRequest = new CreateUserRequest(userName, password, email, storefrontContext.CurrentStorefront.ShopName);
                createUserRequest.Properties.Add("SecondEmail", secondaryEmail);
                createUserResult1 = CustomerServiceProvider.CreateUser(createUserRequest);
                //createUserResult1 = CustomerServiceProvider.CreateUser(new CreateUserRequest(userName, password, email, storefrontContext.CurrentStorefront.ShopName));
                if (!createUserResult1.Success)
                {
                    Helpers.LogSystemMessages(createUserResult1.SystemMessages, createUserResult1);
                }
                else if (createUserResult1.Success)
                {
                    if (createUserResult1.CommerceUser == null)
                    {
                        if (createUserResult1.SystemMessages.Count == 0)
                        {
                            createUserResult1.Success = false;
                            createUserResult1.SystemMessages.Add(new SystemMessage()
                            {
                                Message = storefrontContext.GetSystemMessage("User Already Exists")
                            });
                        }
                    }
                }
            }
            catch (MembershipCreateUserException ex)
            {
                CreateUserResult createUserResult2 = new CreateUserResult {
                    Success = false
                };
                createUserResult1 = createUserResult2;
                createUserResult1.SystemMessages.Add(new SystemMessage()
                {
                    Message = ErrorCodeToString(storefrontContext, ex.StatusCode)
                });
            }
            catch (Exception ex)
            {
                CreateUserResult createUserResult2 = new CreateUserResult {
                    Success = false
                };
                createUserResult1 = createUserResult2;
                createUserResult1.SystemMessages.Add(new SystemMessage()
                {
                    Message = storefrontContext.GetSystemMessage("Unknown Membership Provider Error")
                });
            }
            CreateUserResult serviceProviderResult = createUserResult1;

            return(new ManagerResponse <CreateUserResult, CommerceUser>(serviceProviderResult, serviceProviderResult.CommerceUser));
        }
 /// <summary>
 /// Rules engine condition implementation to determine if the name of an index
 /// contains a specific value.
 /// </summary>
 /// <param name="ruleContext">Rules processing context.</param>
 /// <returns>Returns true if the name of the index contains the specified value.</returns>
 protected override bool Execute(T ruleContext)
 {
     Assert.ArgumentNotNull(ruleContext, "ruleContext");
     Assert.ArgumentNotNull(ruleContext.IndexName, "ruleContext.IndexName)");
     Assert.ArgumentNotNullOrEmpty(this.MatchIndexNameAgainst, "MatchIndexNameAgainst");
     return(ruleContext.IndexName.ToLower().Contains(
                this.MatchIndexNameAgainst.ToLower()));
 }
Пример #8
0
        /// <summary>
        /// Rules engine condition to determine whether the number of items updated
        /// since the last commit of changes to the search index to disk exceeds
        /// a given threshold.
        /// </summary>
        /// <param name="ruleContext">Rule processing context.</param>
        /// <returns>True if the number of indexed items updated since the last commit
        /// exceeds the given threshold.</returns>
        protected override bool Execute(T ruleContext)
        {
            Assert.IsTrue(this.Threshold > 0, "Threshold: " + this.Threshold);
            Assert.ArgumentNotNull(ruleContext, "ruleContext");
            bool result = ruleContext.UpdatesSinceLastCommit > this.Threshold;

            return(result);
        }
 /// <summary>
 /// Rules engine condition implementation to determine whether a search index
 /// has been updated within the specified number of minutes.
 /// </summary>
 /// <param name="ruleContext">Rules processing context.</param>
 /// <returns>True if the index has not been updated
 /// within the specified number of minutes.</returns>
 protected override bool Execute(T ruleContext)
 {
     Assert.ArgumentNotNull(ruleContext, "ruleContext");
     Assert.ArgumentNotNull(this.CompareLastUpdatedAgainstMinutes, "CompareLastUpdatedAgainstMinutes");
     return(DateTime.Compare(
                ruleContext.LastUpdated.AddMinutes(this.CompareLastUpdatedAgainstMinutes.Value),
                DateTime.Now) < 0);
 }
        /// <summary>
        /// Rules engine condition to determine whether a given number
        /// of milliseconds has elapsed since the last commit of changes
        /// to a search engine to disk.
        /// </summary>
        /// <param name="ruleContext">Rule context type.</param>
        /// <returns>True if the number of milliseconds has updates </returns>
        protected override bool Execute(T ruleContext)
        {
            Assert.IsTrue(this.Threshold > 0, "Threshold: " + this.Threshold);
            Assert.ArgumentNotNull(ruleContext, "ruleContext");
            bool result = DateTime.Now.CompareTo(ruleContext.LastCommitted.AddMilliseconds(this.Threshold)) > 0;

            return(result);
        }
Пример #11
0
 /// <summary>
 /// Deletes the old version.
 /// </summary>
 /// <param name="version">The old version to delete.</param>
 public override void HandleVersion(SC.Data.Items.Item version)
 {
     Assert.ArgumentNotNull(version, "version");
     SC.Diagnostics.Log.Audit(
         this,
         "Delete version : {0}",
         new string[] { SC.Diagnostics.AuditFormatter.FormatItem(version) });
     version.Versions.RemoveVersion();
 }
Пример #12
0
 /// <summary>
 /// Rules engine condition implementation to determine
 /// if the name of the database associated with an index
 /// matches a specific value.
 /// </summary>
 /// <param name="ruleContext">Rules processing context.</param>
 /// <returns>Returns true if the name of the database associated with the index
 /// matches the specified value.</returns>
 protected override bool Execute(T ruleContext)
 {
     Assert.ArgumentNotNull(ruleContext, "ruleContext");
     Assert.ArgumentNotNull(ruleContext.IndexedDatabaseName, "ruleContext.IndexedDatabaseName)");
     Assert.ArgumentNotNullOrEmpty(this.MatchIndexedDatabaseNameAgainst, "MatchIndexedDatabaseNameAgainst");
     return(string.Equals(
                ruleContext.IndexedDatabaseName,
                this.MatchIndexedDatabaseNameAgainst,
                StringComparison.InvariantCultureIgnoreCase));
 }
        /// <summary>
        /// Implementation allows index rebuilding if the system minute
        /// is between StartMinute and EndMinute minutes since midnight, inclusive.
        /// </summary>
        /// <param name="ruleContext">Rule processing context.</param>
        /// <returns>True if this condition allows index rebuilding.</returns>
        protected override bool Execute(T ruleContext)
        {
            Assert.ArgumentNotNull(ruleContext, "ruleContext");
            Assert.ArgumentNotNull(this.StartMinute, "StartMinute");
            Assert.ArgumentNotNull(this.EndMinute, "EndMinute");
            DateTime now     = DateTime.Now;
            int      minutes = (now.Hour * 60) + now.Minute;

            return(minutes >= this.StartMinute.Value && minutes <= this.EndMinute.Value);
        }
Пример #14
0
        public override void DoProcess(
            SC.Sharedsource.Pipelines.GetPresentationDataSources.GetPresentationDataSourcesArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            if (!string.IsNullOrEmpty(args.RawDataSource))
            {
                return;
            }

            args.DataSourceItems.Add(SC.Context.Item);
        }
Пример #15
0
        public override SC.Shell.Framework.Commands.CommandState QueryState(SC.Shell.Framework.Commands.CommandContext context)
        {
            Assert.ArgumentNotNull(context, "context");
            SC.Shell.Framework.Commands.CommandState state = base.QueryState(context);

            if (context.Items.Length == 1 && context.Items[0] != null && state == SC.Shell.Framework.Commands.CommandState.Disabled && CheckIn.CanCheckIn(context.Items[0]))
            {
                return(SC.Shell.Framework.Commands.CommandState.Enabled);
            }

            return(state);
        }
Пример #16
0
 public GetPresentationDataSourcesArgs(
     string dataSource,
     SC.Data.Items.Item contextItem,
     bool storeUISearchResults,
     bool storeSearchResultIDs,
     CS.IProviderSearchContext searchContext)
 {
     Assert.ArgumentNotNull(contextItem, "contextItem");
     this.RawDataSource        = dataSource;
     this.ContextItem          = contextItem;
     this.StoreUISearchResults = storeUISearchResults;
     this.StoreSearchResultIDs = storeSearchResultIDs;
     this.SearchContext        = searchContext;
 }
Пример #17
0
 internal static void ValidateArguments <TRequest, TResult>(ServicePipelineArgs args, out TRequest request,
                                                            out TResult result) where TRequest : ServiceProviderRequest where TResult : ServiceProviderResult
 {
     Assert.ArgumentNotNull(args, nameof(args));
     Assert.ArgumentNotNull(args.Request, "args.Request");
     Assert.ArgumentNotNull(args.Request.RequestContext, "args.Request.RequestContext");
     Assert.ArgumentNotNull(args.Result, "args.Result");
     request = args.Request as TRequest;
     result  = args.Result as TResult;
     Assert.IsNotNull(request,
                      "The parameter args.Request was not of the expected type.  Expected {0}.  Actual {1}.",
                      typeof(TRequest).Name, args.Request.GetType().Name);
     Assert.IsNotNull(result,
                      "The parameter args.Result was not of the expected type.  Expected {0}.  Actual {1}.",
                      typeof(TResult).Name, args.Result.GetType().Name);
 }
Пример #18
0
        public static bool CanCheckIn(SC.Data.Items.Item item, SC.Security.Accounts.User user = null)
        {
            Assert.ArgumentNotNull(item, "item");

            if (user == null)
            {
                user = SC.Context.User;
                Assert.IsNotNull(user, "context user");
            }

            if (item.Appearance.ReadOnly || !item.Locking.IsLocked() || !item.Access.CanWrite() || !item.Access.CanWriteLanguage())
            {
                return(false);
            }

            return(user.IsAdministrator ||
                   string.Compare(item.Locking.GetOwner(), user.Name, System.StringComparison.OrdinalIgnoreCase) == 0 ||
                   CheckIn.HasUnlockAccess(item));
        }
Пример #19
0
        /// <summary>
        /// Archives the old version.
        /// </summary>
        /// <param name="version">The old version to archive.</param>
        public override void HandleVersion(SC.Data.Items.Item version)
        {
            Assert.ArgumentNotNull(version, "version");
            SC.Data.Archiving.Archive archive = version.Database.Archives["archive"];

            if (archive != null)
            {
                SC.Diagnostics.Log.Audit(
                    new object(),
                    "Archive version: {0}",
                    new string[] { SC.Diagnostics.AuditFormatter.FormatItem(version) });
                archive.ArchiveVersion(version);
            }
            else
            {
                SC.Diagnostics.Log.Audit(
                    this,
                    "Recycle version : {0}",
                    new string[] { SC.Diagnostics.AuditFormatter.FormatItem(version) });
                version.RecycleVersion();
            }
        }
Пример #20
0
        protected new void Run(SC.Web.UI.Sheer.ClientPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            if (!SC.Web.UI.Sheer.SheerResponse.CheckModified())
            {
                return;
            }

            SC.Data.Items.Item item = SC.Client.GetItemNotNull(args.Parameters["id"], SC.Globalization.Language.Parse(args.Parameters["language"]), SC.Data.Version.Parse(args.Parameters["version"]));

            if (!(item.Locking.HasLock() || SC.Context.IsAdministrator || CheckIn.HasUnlockAccess(item)))
            {
                return;
            }

            SC.Diagnostics.Log.Audit(this, "Check in: {0}", new string[] { SC.Diagnostics.AuditFormatter.FormatItem(item) });

            using (new SC.Data.Items.EditContext(item, SC.SecurityModel.SecurityCheck.Disable))
                item.Locking.Unlock();

            SC.Context.ClientPage.SendMessage(this, "item:checkedin");
        }
        /// <summary>
        /// Empty implementation.
        /// </summary>
        /// <param name="searchIndex">Search index.</param>
        public void Initialize(CS.ISearchIndex searchIndex)
        {
            Assert.ArgumentNotNull(searchIndex, "searchIndex");
            Assert.ArgumentNotNullOrEmpty(searchIndex.Name, "searchIndex.Name");

            if (!string.IsNullOrEmpty(this.RuleDatabaseName))
            {
                return;
            }

            string[] parts = searchIndex.Name.Split('_');

            if (parts.Length < 2)
            {
                return;
            }

            if (SC.StringUtil.Contains(
                    parts[1],
                    SC.Configuration.Factory.GetDatabaseNames()))
            {
                this.RuleDatabaseName = parts[1];
            }
        }
 public CommitPolicyWrapper(SC.ContentSearch.ICommitPolicy policyToWrap)
 {
     Assert.ArgumentNotNull(policyToWrap, "policyToWrap");
     this._wrappedPolicy = policyToWrap;
 }
Пример #23
0
 protected static new bool CanCheckIn(SC.Data.Items.Item item)
 {
     Assert.ArgumentNotNull(item, "item");
     return(CheckIn.CanCheckIn(item));
 }