protected void CreateGroup()
 {
     if (Page.IsValid)
     {
         Group group = new Group();
         group.Name = Name.Text;
         foreach (ListItem roleListItem in RoleList.Items)
         {
             if (roleListItem.Selected)
             {
                 Role role = RoleDataSource.Load(AlwaysConvert.ToInt(roleListItem.Value));
                 group.Roles.Add(role);
                 roleListItem.Selected = false;
             }
         }
         Store store = AbleContext.Current.Store;
         store.Groups.Add(group);
         store.Save();
         AddedMessage.Text    = string.Format(AddedMessage.Text, group.Name);
         AddedMessage.Visible = true;
         Name.Text            = String.Empty;
         Name.Focus();
         if (ItemAdded != null)
         {
             ItemAdded(this, new PersistentItemEventArgs(group.Id, group.Name));
         }
     }
 }
Beispiel #2
0
        public virtual ActionResult List(RoleDataSource datasource = null)
        {
            datasource.Data = Mapper.Map <List <RoleViewModel> >(_roleManager.Roles);
            datasource.Initialize();

            return(View(datasource));
        }
 protected void UpdateGroup()
 {
     if (Page.IsValid)
     {
         CommerceBuilder.Users.Group group = GroupDataSource.Load(this.GroupId);
         group.Name = Name.Text;
         group.Roles.Clear();
         group.Save();
         foreach (ListItem roleListItem in RoleList.Items)
         {
             if (roleListItem.Selected)
             {
                 Role role = RoleDataSource.Load(AlwaysConvert.ToInt(roleListItem.Value));
                 group.Roles.Add(role);
             }
         }
         group.Save();
         SavedMessage.Text    = string.Format(SavedMessage.Text, group.Name);
         SavedMessage.Visible = true;
         if (ItemUpdated != null)
         {
             ItemUpdated(this, new PersistentItemEventArgs(this.GroupId, group.Name));
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Creates a new store object
        /// </summary>
        /// <param name="storeName">Name of the new store</param>
        /// <param name="adminEmail">Email address of initial super user account</param>
        /// <param name="adminPassword">Password for initial super user account</param>
        /// <param name="switchContext">If true, the token context is switched to the new store.  If false, the token
        /// context remains the same as it was before the method is called.</param>
        /// <returns>The created store object</returns>
        public static Store CreateStore(string storeName, string adminEmail, string adminPassword, bool switchContext)
        {
            //NEED TO SAVE THE CURRENT STORE CONTEXT
            Store masterStore = Token.Instance.Store;
            //CREATE THE STORE
            Store newStore = new Store();

            newStore.Name             = storeName;
            newStore.NextOrderId      = 1;
            newStore.OrderIdIncrement = 1;
            newStore.WeightUnit       = CommerceBuilder.Shipping.WeightUnit.Pounds;
            newStore.MeasurementUnit  = CommerceBuilder.Shipping.MeasurementUnit.Inches;
            newStore.Save();
            //NEED TO SWITCH OUR TOKEN CONTEXT TO THE NEW STORE
            Token.Instance.InitStoreContext(newStore);
            //INITIALIZE THE AUDIT LOGS
            Logger.Audit(AuditEventType.ApplicationStarted, true, string.Empty);
            //INITIALIZE ROLES AND GROUPS
            RoleDataSource.EnsureDefaultRoles();
            GroupDataSource.EnsureDefaultGroups();
            //CREATE THE SUPER USER
            User user = UserDataSource.CreateUser(adminEmail, adminPassword);

            //ASSIGN USER TO APPROPRIATE GROUP
            CommerceBuilder.Users.Group suGroup = GroupDataSource.LoadForName("Super Users");
            user.UserGroups.Add(new UserGroup(user.UserId, suGroup.GroupId));
            user.Save();
            //RESET THE ORIGINAL STORE CONTEXT
            if (!switchContext)
            {
                Token.Instance.InitStoreContext(masterStore);
            }
            //RETURN THE NEW STORE
            return(newStore);
        }
Beispiel #5
0
        public virtual ActionResult List()
        {
            var roles = _roleManager.Roles;
            var model = new RoleDataSource();

            model.Roles = Mapper.Map <List <RoleViewModel> >(roles);
            model.SetActions();

            return(View(MVC.Shared.Views._Grid, model.GetGridModel()));
        }
        /// <summary>
        /// Gets the collection of roles accessible to the current user for assignment.
        /// </summary>
        /// <returns>The collection of roles accessible to the current user for assignment.</returns>
        public static IList <Role> GetManagableRoles()
        {
            User        user           = AbleContext.Current.User;
            List <Role> managableRoles = new List <Role>();

            // GET LIST OF ROLSE
            IList <Role> roles = RoleDataSource.LoadAll("Name");

            // IF USER IS IN JR ADMIN ROLES
            if (user != null && user.IsInRole(Role.JrAdminRoles))
            {
                foreach (Role role in roles)
                {
                    // IF ROLE IS AN ADMIN ROLE
                    if (Role.AllAdminRoles.Any(r => r == role.Name))
                    {
                        // ONLY SECURITY ADMIN CAN MANAGE ADMIN ROLES
                        if (user.IsSecurityAdmin)
                        {
                            if (Role.SystemAdminRoles.Any(r => r == role.Name))
                            {
                                // ONLY SYSTEM ADMIN CAN MANAGE SYSTEM ROLE
                                if (user.IsSystemAdmin)
                                {
                                    managableRoles.Add(role);
                                }
                            }
                            else
                            {
                                managableRoles.Add(role);
                            }
                        }
                    }
                    else
                    {
                        managableRoles.Add(role);
                    }
                }
            }

            return(managableRoles);
        }
Beispiel #7
0
 public virtual ActionResult DataSource(RoleDataSource datasource)
 {
     return(List(datasource));
 }
Beispiel #8
0
        private void SaveSettings()
        {
            Store store = AbleContext.Current.Store;
            StoreSettingsManager settings = store.Settings;

            store.Name = StoreName.Text;
            store.VolumeDiscountMode       = (VolumeDiscountMode)DiscountMode.SelectedIndex;
            store.WeightUnit               = (WeightUnit)AlwaysConvert.ToInt(WeightUnit.SelectedValue);
            store.MeasurementUnit          = (MeasurementUnit)AlwaysConvert.ToInt(MeasurementUnit.SelectedValue);
            settings.TimeZoneCode          = TimeZoneOffset.SelectedValue;
            settings.TimeZoneOffset        = GetTimeZoneOffset(TimeZoneOffset.SelectedValue);
            settings.PostalCodeCountries   = PostalCodeCountries.Text.Replace(" ", string.Empty);
            settings.SiteDisclaimerMessage = SiteDisclaimerMessage.Text.Trim();

            // INVENTORY
            store.Settings.EnableInventory                       = EnableInventory.Checked;
            settings.InventoryDisplayDetails                     = CurrentInventoryDisplayMode.SelectedIndex == 1;
            settings.InventoryInStockMessage                     = InStockMessage.Text;
            settings.InventoryOutOfStockMessage                  = OutOfStockMessage.Text;
            settings.InventoryAvailabilityMessage                = InventoryAvailabilityMessage.Text;
            settings.InventoryRestockNotificationLink            = RestockNotificationLink.Text;
            settings.InventoryRestockNotificationEmailTemplateId = AlwaysConvert.ToInt(RestockNotificationEmail.SelectedValue);

            // ORDERS
            short increment = AlwaysConvert.ToInt16(OrderIdIncrement.Text);

            if (increment >= 1)
            {
                store.OrderIdIncrement = increment;
            }
            settings.CheckoutTermsAndConditions     = CheckoutTerms.Text.Trim();
            settings.OrderMinimumAmount             = AlwaysConvert.ToDecimal(OrderMinAmount.Text);
            settings.OrderMaximumAmount             = AlwaysConvert.ToDecimal(OrderMaxAmount.Text);
            settings.AcceptOrdersWithInvalidPayment = IgnoreFailedPayments.Checked;
            settings.EnablePartialPaymentCheckouts  = AllowPartialPaymnets.Checked;

            settings.EnableOnePageCheckout  = EnableOnePageCheckout.Checked;
            settings.AllowAnonymousCheckout = AllowGuestCheckout.Checked || LimitedGuestCheckout.Checked;
            settings.AllowAnonymousCheckoutForDigitalGoods = !LimitedGuestCheckout.Checked;
            settings.EnableCustomerOrderNotes      = EnableOrderNotes.Checked;
            settings.EnableShipMessage             = EnableShipMessage.Checked;
            settings.EnableShipToMultipleAddresses = EnableShipToMultipleAddresses.Checked;

            // PRODUCTS PURCHASING
            settings.ProductPurchasingDisabled = ProductPurchasingDisabled.Checked;

            // WISHLISTS ENABLED
            settings.WishlistsEnabled = WishlistsEnabled.Checked;

            // RESTRICT STORE ACCESS
            settings.RestrictStoreAccess = (AccessRestrictionType)Enum.Parse(typeof(AccessRestrictionType), RestrictStoreAccessOptions.SelectedValue);
            if (settings.RestrictStoreAccess == AccessRestrictionType.AuthorizedGroupsOnly)
            {
                IList <Group> allGroups      = GroupDataSource.LoadForStore(AbleContext.Current.StoreId, "Name ASC");
                IList <Group> nonAdminGroups = allGroups.FindAll(grp => !grp.IsInRole(Role.AllAdminRoles)) as IList <Group>;

                // remove permissions for all non-admin groups
                Role authorizedUserRole = RoleDataSource.LoadForRolename(Role.CustomerRoles[0]);
                foreach (Group group in nonAdminGroups)
                {
                    group.Roles.Remove(authorizedUserRole);
                }
                foreach (ListItem item in AuthorizedGroups.Items)
                {
                    if (item.Selected)
                    {
                        int groupId = AlwaysConvert.ToInt(item.Value);
                        foreach (Group group in nonAdminGroups)
                        {
                            // add permissions for selected groups
                            if (groupId == group.Id)
                            {
                                group.Roles.Add(authorizedUserRole);
                            }
                        }
                    }
                }
                nonAdminGroups.Save();
            }

            // SEARCH SETTINGS
            settings.WishlistSearchEnabled        = EnableWishlistSearch.Checked;
            settings.MinimumSearchLength          = AlwaysConvert.ToInt(MinimumSearchLength.Text);
            settings.PopularSearchThreshold       = AlwaysConvert.ToInt(PopularSearchThreshold.Text);
            settings.CategorySearchDisplayLimit   = AlwaysConvert.ToInt(CategorySearchDisplayLimit.Text);
            settings.EnablePaymentProfilesStorage = PaymentStorage.Checked;

            // HTML EDITOR SETTING
            settings.EnableWysiwygEditor = EnableHtmlEditor.Checked;

            store.Save();

            // CHECK NEXT ORDER NUMBER
            if (OrigNextOrderNumber.Value != NextOrderId.Text)
            {
                // NEXT ORDER NUMBER WAS UPDATED
                store.NextOrderId         = StoreDataSource.SetNextOrderNumber(AlwaysConvert.ToInt(NextOrderId.Text));
                OrigNextOrderNumber.Value = store.NextOrderId.ToString();
            }
            else
            {
                // DETERMINE CORRECT VALUE FOR NEXT ORDER NUMBER
                OrigNextOrderNumber.Value = StoreDataSource.GetNextOrderNumber(false).ToString();
            }
            OrderIdIncrement.Text = store.OrderIdIncrement.ToString();
            UpdateNextOrderNumber(store);
            store.Save();

            if (SearchProvider.SelectedValue != ApplicationSettings.Instance.SearchProvider)
            {
                ApplicationSettings.Instance.SearchProvider = SearchProvider.SelectedValue;
                ApplicationSettings.Instance.Save();

                if (SearchProvider.SelectedValue == "SqlFtsSearchProvider")
                {
                    bool fullTextSearch = false;
                    // FTS IS TURNED ON, MAKE SURE THE CATALOG IS AVAILABLE
                    if (KeywordSearchHelper.EnsureCatalog())
                    {
                        // CATALOG IS FOUND, MAKE SURE INDEXES ARE AVAILABLE
                        if (KeywordSearchHelper.EnsureIndexes())
                        {
                            // FTS CAN BE SAFELY ENABLED
                            fullTextSearch = true;
                        }
                    }

                    if (!fullTextSearch)
                    {
                        KeywordSearchHelper.RemoveCatalog();
                    }
                }

                if (SearchProvider.SelectedValue == "LuceneSearchProvider")
                {
                    AbleContext.Resolve <IFullTextSearchService>().AsyncReindex();
                }
            }
        }