Пример #1
0
        public User PostSave(UmbracoUser user)
        {
            user.LoginName = user.Email;

            if (user.Id > 0)
            {
                User umbracoUser = new User(user.LoginName);
                umbracoUser.Name      = user.Name;
                umbracoUser.LoginName = user.LoginName;
                umbracoUser.Password  = HashPassword(user.Password);
                umbracoUser.Email     = user.Email;

                umbracoUser.Save();
                return(umbracoUser);
            }
            else
            {
                UserType userType = UserType.GetUserType(DatabaseContext.Database.Fetch <int>("SELECT id FROM umbracoUserType WHERE userTypeAlias='AccountAdministrator'").FirstOrDefault());
                umbraco.BusinessLogic.User.MakeNew(user.Name, user.LoginName, HashPassword(user.Password), userType);

                User umbracoUser = new User(user.LoginName);
                umbracoUser.Email = user.Email;
                umbracoUser.AddApplication("buildings");

                umbracoUser.Save();

                return(umbracoUser);
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the SaveAndPublish event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// Sets the document's properties and if the page is valid continues to publish it, otherwise just saves a revision.
        /// </remarks>
        protected void Publish(object sender, EventArgs e)
        {
            //update UI and set document properties
            PerformSaveLogic();

            //the business logic here will check to see if the doc can actually be published and will return the
            // appropriate result so we can display the correct error messages (or success).
            var savePublishResult = _document.SaveAndPublishWithResult(UmbracoUser);

            ShowMessageForStatus(savePublishResult.Result);

            if (savePublishResult.Success)
            {
                _littPublishStatus.Text = string.Format("{0}: {1}<br/>", ui.Text("content", "lastPublished", UmbracoUser), _document.VersionDate.ToString());

                if (UmbracoUser.GetPermissions(_document.Path).IndexOf("U") > -1)
                {
                    _unPublish.Visible = true;
                }

                _documentHasPublishedVersion = _document.Content.HasPublishedVersion();
            }

            ClientTools.SyncTree(_document.Path, true);
        }
Пример #3
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var nodeId = GetNodeId();
            var node   = ApplicationContext.Current.Services.ContentService.GetById(nodeId);

            if (node == null)
            {
                feedback.Text         = ui.Text("assignDomain", "invalidNode");
                pane_language.Visible = false;
                pane_domains.Visible  = false;
                phSave.Visible        = false;
                return;
            }

            if (!UmbracoUser.GetPermissions(node.Path).Contains(BusinessLogic.Actions.ActionAssignDomain.Instance.Letter))
            {
                feedback.Text         = ui.Text("assignDomain", "permissionDenied");
                pane_language.Visible = false;
                pane_domains.Visible  = false;
                phSave.Visible        = false;
                return;
            }

            pane_language.Text = ui.Text("assignDomain", "setLanguage");
            pane_domains.Text  = ui.Text("assignDomain", "setDomains");
            prop_language.Text = ui.Text("assignDomain", "language");

            var nodeDomains = DomainHelper.GetNodeDomains(nodeId, true);
            var wildcard    = nodeDomains.FirstOrDefault(d => d.IsWildcard);

            var sb = new StringBuilder();

            sb.Append("languages: [");
            var i = 0;

            foreach (var language in ApplicationContext.Current.Services.LocalizationService.GetAllLanguages())
            {
                sb.AppendFormat("{0}{{ \"Id\": {1}, \"Code\": \"{2}\" }}", (i++ == 0 ? "" : ","), language.Id, language.IsoCode);
            }
            sb.Append("]\r\n");

            sb.AppendFormat(",language: {0}", wildcard == null ? "undefined" : wildcard.Language.id.ToString());

            sb.Append(",domains: [");
            i = 0;
            foreach (var domain in nodeDomains.Where(d => !d.IsWildcard))
            {
                sb.AppendFormat("{0}{{ \"Name\": \"{1}\", \"Lang\": \"{2}\" }}", (i++ == 0 ? "" :","), domain.Name, domain.Language.id);
            }
            sb.Append("]\r\n");

            data.Text = sb.ToString();
        }
        internal IEnumerable <MenuItem> GetAllowedUserMenuItemsForNode(IUmbracoEntity dd)
        {
            var actions = global::umbraco.BusinessLogic.Actions.Action.FromString(UmbracoUser.GetPermissions(dd.Path));

            // A user is allowed to delete their own stuff
            if (dd.CreatorId == UmbracoUser.Id && actions.Contains(ActionDelete.Instance) == false)
            {
                actions.Add(ActionDelete.Instance);
            }

            return(actions.Select(x => new MenuItem(x)));
        }
Пример #5
0
        protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings)
        {
            if (id == Constants.System.Root.ToInvariantString())
            {
                var menu = new MenuItemCollection();

                // if the user's start node is not the root then the only menu item to display is refresh
                if (UserStartNodes.Contains(Constants.System.Root) == false)
                {
                    menu.Items.Add <RefreshNode, ActionRefresh>(
                        Services.TextService.Localize(string.Concat("actions/", ActionRefresh.Instance.Alias)),
                        true);
                    return(menu);
                }

                //set the default to create
                menu.DefaultMenuAlias = ActionNew.Instance.Alias;

                // we need to get the default permissions as you can't set permissions on the very root node
                //TODO: Use the new services to get permissions
                var nodeActions = global::umbraco.BusinessLogic.Actions.Action.FromString(
                    UmbracoUser.GetPermissions(Constants.System.Root.ToInvariantString()))
                                  .Select(x => new MenuItem(x));

                //these two are the standard items
                menu.Items.Add <ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
                menu.Items.Add <ActionSort>(ui.Text("actions", ActionSort.Instance.Alias), true).ConvertLegacyMenuItem(null, "content", "content");

                //filter the standard items
                FilterUserAllowedMenuItems(menu, nodeActions);

                if (menu.Items.Any())
                {
                    menu.Items.Last().SeperatorBefore = true;
                }

                // add default actions for *all* users
                menu.Items.Add <ActionRePublish>(ui.Text("actions", ActionRePublish.Instance.Alias)).ConvertLegacyMenuItem(null, "content", "content");
                menu.Items.Add <RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true);

                return(menu);
            }


            //return a normal node menu:
            int iid;

            if (int.TryParse(id, out iid) == false)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            var item = Services.EntityService.Get(iid, UmbracoObjectTypes.Document);

            if (item == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            //if the user has no path access for this node, all they can do is refresh
            if (Security.CurrentUser.HasPathAccess(item, Services.EntityService, RecycleBinId) == false)
            {
                var menu = new MenuItemCollection();
                menu.Items.Add <RefreshNode, ActionRefresh>(
                    Services.TextService.Localize(string.Concat("actions/", ActionRefresh.Instance.Alias)),
                    true);
                return(menu);
            }

            var nodeMenu = GetAllNodeMenuItems(item);

            //if the content node is in the recycle bin, don't have a default menu, just show the regular menu
            if (item.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Contains(RecycleBinId.ToInvariantString()))
            {
                nodeMenu.DefaultMenuAlias = null;
                nodeMenu = GetNodeMenuItemsForDeletedContent(item);
            }
            else
            {
                //set the default to create
                nodeMenu.DefaultMenuAlias = ActionNew.Instance.Alias;
            }

            var allowedMenuItems = GetAllowedUserMenuItemsForNode(item);

            FilterUserAllowedMenuItems(nodeMenu, allowedMenuItems);

            return(nodeMenu);
        }
        // can't pass multiple complex args in json post request...
        public PostBackModel SaveLanguageAndDomains(PostBackModel model)
        {
            var node = ApplicationContext.Current.Services.ContentService.GetById(model.NodeId);

            if (node == null)
            {
                var response = Request.CreateResponse(HttpStatusCode.BadRequest);
                response.Content      = new StringContent(string.Format("There is no content node with id {0}.", model.NodeId));
                response.ReasonPhrase = "Node Not Found.";
                throw new HttpResponseException(response);
            }

            if (UmbracoUser.GetPermissions(node.Path).Contains(ActionAssignDomain.Instance.Letter) == false)
            {
                var response = Request.CreateResponse(HttpStatusCode.BadRequest);
                response.Content      = new StringContent("You do not have permission to assign domains on that node.");
                response.ReasonPhrase = "Permission Denied.";
                throw new HttpResponseException(response);
            }

            model.Valid = true;
            var domains   = Services.DomainService.GetAssignedDomains(model.NodeId, true).ToArray();
            var languages = Services.LocalizationService.GetAllLanguages().ToArray();
            var language  = model.Language > 0 ? languages.FirstOrDefault(l => l.Id == model.Language) : null;

            // process wildcard

            if (language != null)
            {
                // yet there is a race condition here...
                var wildcard = domains.FirstOrDefault(d => d.IsWildcard);
                if (wildcard != null)
                {
                    wildcard.LanguageId = language.Id;
                }
                else
                {
                    wildcard = new UmbracoDomain("*" + model.NodeId)
                    {
                        LanguageId    = model.Language,
                        RootContentId = model.NodeId
                    };
                }

                var saveAttempt = Services.DomainService.Save(wildcard);
                if (saveAttempt == false)
                {
                    var response = Request.CreateResponse(HttpStatusCode.BadRequest);
                    response.Content      = new StringContent("Saving domain failed");
                    response.ReasonPhrase = saveAttempt.Result.StatusType.ToString();
                    throw new HttpResponseException(response);
                }
            }
            else
            {
                var wildcard = domains.FirstOrDefault(d => d.IsWildcard);
                if (wildcard != null)
                {
                    Services.DomainService.Delete(wildcard);
                }
            }

            // process domains

            // delete every (non-wildcard) domain, that exists in the DB yet is not in the model
            foreach (var domain in domains.Where(d => d.IsWildcard == false && model.Domains.All(m => m.Name.InvariantEquals(d.DomainName) == false)))
            {
                Services.DomainService.Delete(domain);
            }


            var names = new List <string>();

            // create or update domains in the model
            foreach (var domainModel in model.Domains.Where(m => string.IsNullOrWhiteSpace(m.Name) == false))
            {
                language = languages.FirstOrDefault(l => l.Id == domainModel.Lang);
                if (language == null)
                {
                    continue;
                }
                var name = domainModel.Name.ToLowerInvariant();
                if (names.Contains(name))
                {
                    domainModel.Duplicate = true;
                    continue;
                }
                names.Add(name);
                var domain = domains.FirstOrDefault(d => d.DomainName.InvariantEquals(domainModel.Name));
                if (domain != null)
                {
                    domain.LanguageId = language.Id;
                    Services.DomainService.Save(domain);
                }
                else if (Services.DomainService.Exists(domainModel.Name))
                {
                    domainModel.Duplicate = true;
                    var xdomain = Services.DomainService.GetByName(domainModel.Name);
                    var xrcid   = xdomain.RootContentId;
                    if (xrcid.HasValue)
                    {
                        var xcontent = Services.ContentService.GetById(xrcid.Value);
                        var xnames   = new List <string>();
                        while (xcontent != null)
                        {
                            xnames.Add(xcontent.Name);
                            if (xcontent.ParentId < -1)
                            {
                                xnames.Add("Recycle Bin");
                            }
                            xcontent = xcontent.Parent();
                        }
                        xnames.Reverse();
                        domainModel.Other = "/" + string.Join("/", xnames);
                    }
                }
                else
                {
                    // yet there is a race condition here...
                    var newDomain = new UmbracoDomain(name)
                    {
                        LanguageId    = domainModel.Lang,
                        RootContentId = model.NodeId
                    };
                    var saveAttempt = Services.DomainService.Save(newDomain);
                    if (saveAttempt == false)
                    {
                        var response = Request.CreateResponse(HttpStatusCode.BadRequest);
                        response.Content      = new StringContent("Saving new domain failed");
                        response.ReasonPhrase = saveAttempt.Result.StatusType.ToString();
                        throw new HttpResponseException(response);
                    }
                }
            }

            model.Valid = model.Domains.All(m => m.Duplicate == false);

            return(model);
        }
Пример #7
0
 private bool CurrentUserHasPermissions(IContent contentNode)
 {
     return(Action.FromString(UmbracoUser.GetPermissions(contentNode.Path)).OfType <ActionBrowse>().Any());
 }
Пример #8
0
        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);

            //validate!
            int id;

            if (int.TryParse(Request.QueryString["id"], out id) == false)
            {
                //if this is invalid show an error
                this.DisplayFatalError("Invalid query string");
                return;
            }
            _contentId = id;


            _unPublish.Click += UnPublishDo;

            //Loading Content via new public service to ensure that the Properties are loaded correct
            var content = ApplicationContext.Current.Services.ContentService.GetById(id);

            _document = new Document(content);

            //check if the doc exists
            if (string.IsNullOrEmpty(_document.Path))
            {
                //if this is invalid show an error
                this.DisplayFatalError("No document found with id " + _contentId);
                //reset the content id to null so processing doesn't continue on OnLoad
                _contentId = null;
                return;
            }

            // we need to check if there's a published version of this document
            _documentHasPublishedVersion = _document.Content.HasPublishedVersion();

            // Check publishing permissions
            if (!UmbracoUser.GetPermissions(_document.Path).Contains(ActionPublish.Instance.Letter.ToString()))
            {
                // Check to see if the user has send to publish permissions
                if (!UmbracoUser.GetPermissions(_document.Path).Contains(ActionToPublish.Instance.Letter.ToString()))
                {
                    //If no send to publish permission then revert to NoPublish mode
                    _canPublish = controls.ContentControl.publishModes.NoPublish;
                }
                else
                {
                    _canPublish = controls.ContentControl.publishModes.SendToPublish;
                }
            }

            _cControl = new controls.ContentControl(_document, _canPublish, "TabView1");

            _cControl.ID = "TabView1";

            _cControl.Width  = Unit.Pixel(666);
            _cControl.Height = Unit.Pixel(666);

            // Add preview button

            foreach (uicontrols.TabPage tp in _cControl.GetPanels())
            {
                AddPreviewButton(tp.Menu, _document.Id);
            }

            plc.Controls.Add(_cControl);


            var publishStatus = new PlaceHolder();

            if (_documentHasPublishedVersion)
            {
                _littPublishStatus.Text = ui.Text("content", "lastPublished", UmbracoUser) + ": " + _document.VersionDate.ToShortDateString() + " &nbsp; ";

                publishStatus.Controls.Add(_littPublishStatus);
                if (UmbracoUser.GetPermissions(_document.Path).IndexOf("U") > -1)
                {
                    _unPublish.Visible = true;
                }
                else
                {
                    _unPublish.Visible = false;
                }
            }
            else
            {
                _littPublishStatus.Text = ui.Text("content", "itemNotPublished", UmbracoUser);
                publishStatus.Controls.Add(_littPublishStatus);
                _unPublish.Visible = false;
            }

            _unPublish.Text = ui.Text("content", "unPublish", UmbracoUser);
            _unPublish.ID   = "UnPublishButton";
            _unPublish.Attributes.Add("onClick", "if (!confirm('" + ui.Text("defaultdialogs", "confirmSure", UmbracoUser) + "')) return false; ");
            publishStatus.Controls.Add(_unPublish);

            _publishProps.addProperty(ui.Text("content", "publishStatus", UmbracoUser), publishStatus);

            // Template
            var template     = new PlaceHolder();
            var documentType = new DocumentType(_document.ContentType.Id);

            _cControl.PropertiesPane.addProperty(ui.Text("documentType"), new LiteralControl(documentType.Text));


            //template picker
            _cControl.PropertiesPane.addProperty(ui.Text("template"), template);
            int defaultTemplate;

            if (_document.Template != 0)
            {
                defaultTemplate = _document.Template;
            }
            else
            {
                defaultTemplate = documentType.DefaultTemplate;
            }

            if (UmbracoUser.UserType.Name == "writer")
            {
                if (defaultTemplate != 0)
                {
                    template.Controls.Add(new LiteralControl(businesslogic.template.Template.GetTemplate(defaultTemplate).Text));
                }
                else
                {
                    template.Controls.Add(new LiteralControl(ui.Text("content", "noDefaultTemplate")));
                }
            }
            else
            {
                _ddlDefaultTemplate.Items.Add(new ListItem(ui.Text("choose") + "...", ""));
                foreach (var t in documentType.allowedTemplates)
                {
                    var tTemp = new ListItem(t.Text, t.Id.ToString());
                    if (t.Id == defaultTemplate)
                    {
                        tTemp.Selected = true;
                    }
                    _ddlDefaultTemplate.Items.Add(tTemp);
                }
                template.Controls.Add(_ddlDefaultTemplate);
            }


            // Editable update date, release date and expire date added by NH 13.12.04
            _dp.ID   = "updateDate";
            _dp.Text = _document.UpdateDate.ToShortDateString() + " " + _document.UpdateDate.ToShortTimeString();
            _publishProps.addProperty(ui.Text("content", "updateDate", UmbracoUser), _dp);

            _dpRelease.ID       = "releaseDate";
            _dpRelease.DateTime = _document.ReleaseDate;
            _dpRelease.ShowTime = true;
            _publishProps.addProperty(ui.Text("content", "releaseDate", UmbracoUser), _dpRelease);

            _dpExpire.ID       = "expireDate";
            _dpExpire.DateTime = _document.ExpireDate;
            _dpExpire.ShowTime = true;
            _publishProps.addProperty(ui.Text("content", "expireDate", UmbracoUser), _dpExpire);

            _cControl.Save           += Save;
            _cControl.SaveAndPublish += Publish;
            _cControl.SaveToPublish  += SendToPublish;

            // Add panes to property page...
            _cControl.tpProp.Controls.AddAt(1, _publishProps);
            _cControl.tpProp.Controls.AddAt(2, _linkProps);

            // add preview to properties pane too
            AddPreviewButton(_cControl.tpProp.Menu, _document.Id);
        }
Пример #9
0
        // can't pass multiple complex args in json post request...
        public PostBackModel SaveLanguageAndDomains(PostBackModel model)
        {
            var node = ApplicationContext.Current.Services.ContentService.GetById(model.NodeId);

            if (node == null)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content      = new StringContent(string.Format("There is no content node with id {0}.", model.NodeId)),
                    ReasonPhrase = "Node Not Found."
                });
            }

            if (!UmbracoUser.GetPermissions(node.Path).Contains(global::umbraco.BusinessLogic.Actions.ActionAssignDomain.Instance.Letter))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content      = new StringContent("You do not have permission to assign domains on that node."),
                    ReasonPhrase = "Permission Denied."
                });
            }

            model.Valid = true;
            var domains   = Routing.DomainHelper.GetNodeDomains(model.NodeId, true);
            var languages = global::umbraco.cms.businesslogic.language.Language.GetAllAsList().ToArray();
            var language  = model.Language > 0 ? languages.FirstOrDefault(l => l.id == model.Language) : null;

            // process wildcard

            if (language != null)
            {
                var wildcard = domains.FirstOrDefault(d => d.IsWildcard);
                if (wildcard != null)
                {
                    wildcard.Language = language;
                }
                else // yet there is a race condition here...
                {
                    Domain.MakeNew("*" + model.NodeId, model.NodeId, model.Language);
                }
            }
            else
            {
                var wildcard = domains.FirstOrDefault(d => d.IsWildcard);
                if (wildcard != null)
                {
                    wildcard.Delete();
                }
            }

            // process domains

            foreach (var domain in domains.Where(d => model.Domains.All(m => !m.Name.Equals(d.Name, StringComparison.OrdinalIgnoreCase))))
            {
                domain.Delete();
            }

            var names = new List <string>();

            foreach (var domainModel in model.Domains.Where(m => !string.IsNullOrWhiteSpace(m.Name)))
            {
                language = languages.FirstOrDefault(l => l.id == domainModel.Lang);
                if (language == null)
                {
                    continue;
                }
                var name = domainModel.Name.ToLowerInvariant();
                if (names.Contains(name))
                {
                    domainModel.Duplicate = true;
                    continue;
                }
                names.Add(name);
                var domain = domains.FirstOrDefault(d => d.Name.Equals(domainModel.Name, StringComparison.OrdinalIgnoreCase));
                if (domain != null)
                {
                    domain.Language = language;
                }
                else if (Domain.Exists(domainModel.Name))
                {
                    domainModel.Duplicate = true;
                }
                else // yet there is a race condition here...
                {
                    Domain.MakeNew(name, model.NodeId, domainModel.Lang);
                }
            }

            model.Valid = model.Domains.All(m => !m.Duplicate);

            return(model);
        }