Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rune Kildahl Bentsen 8 posts 98 karma points
    Nov 01, 2017 @ 15:52
    Rune Kildahl Bentsen
    0

    Exporting a Module with a backoffice page

    Ok, so for the last couple of months, I've been working hard on creating a nice backoffice page to take advantage of our software and form a platform for integration into umbraco.

    I succeeded in creating a neat backoffice page using a VS project with umbraco installed with NuGet along with our other software - for all purposes this project is supposed to be a demo, but the backoffice pages can only be added this way AFAIK.

    So I want to share all that good stuff, and thus I'm trying to export the demo site including backoffice pages and everything as an umbraco package.

    I then created a new fresh blank umbraco installation to test my umbraco package for installation.

    For the most part, the umbraco package works with pages, dictionary items, views, templates, partials, shared, etc. all looks good...

    But the backoffice page I've been working on is not showing after install :(

    So does anyone know what is needed to install a backoffice page with an umbraco package? Any kind of documentation about this very specific area would be really nice, since all I can find on tutorials are about how Umbraco "magically" finds your override classes and extends the backoffice when it implements IApplication and has a Tree. (nice tutorials exists on this).

    I've even run into a similar problem in the beginning, as I wanted to seperate all the logic into a seperate project to conform with Umbraco Cloud standards of a .Core project and a .Web project. Even here, Umbraco simply doesn't add the backoffice pages if the code is defined in the .Core project. I'm not sure if I'm fighting some general thing here, but I really hope there's a solution or a workaround for this particular issue.

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Nov 01, 2017 @ 16:59
    Kevin Jump
    0

    Hi

    it depends a bit by what you mean by back office page.

    If it's a dashboard. the you can add them in the actions section of the package - here is an example of what you might put in the box.:

    <Action runat="install" alias="addDashboardSection" dashboardAlias="usyncBackOffice">
          <section>
            <areas>
              <area>developer</area>
            </areas>
            <tab caption="uSync BackOffice">
              <control>/App_Plugins/usync/uSyncDashboard.html</control>
            </tab>
          </section>
        </Action>
    

    (see example package file here https://github.com/KevinJump/uSync/blob/Dev-v7_7/BuildPackage/Jumoo.uSync.BackOffice/Package.xml)

    if you mean custom sections / trees then they as you say they are discovered by umbraco so you shouldn't need to add anything to the application or tree section, because umbraco should do that when it discovers them.

  • Rune Kildahl Bentsen 8 posts 98 karma points
    Nov 02, 2017 @ 09:48
    Rune Kildahl Bentsen
    0

    Hi Kevin and thanks for the reply

    I didn't consider using the actions section to do this kinda stuff - so i'll check that out! :) However I am talking about an entire section with trees and backoffice pages.

    I think I was just a bit tired yesterday, since I forgot an important part. The new section is actually there, but I forgot that it's not visible since I haven't yet added permissions for anyone to see the stuff. It sure fooled me enough to make a cry for help here, but I think I'm getting close to a full package :)

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Nov 02, 2017 @ 11:00
    Kevin Jump
    100

    Ahh yeah.

    That's a bit different - for a user to see a section it needs to be in the list of sections that they can see from there account .

    Pre Umbraco 7.6 this was done against each user account - from Umbraco 7.7 this is done against the user group.

    so for example to add a section to the default user in Umbraco 7.6:

        private void AddSectionSevenSix(string alias)
        {
            var user = _userService.GetUserById(0);
            if (user != null)
            {
                if (!user.AllowedSections.Contains(alias))
                {
                    user.AddAllowedSection(alias);
                    _userService.Save(user);
                }
            }
        }
    

    and to add a section to the Admin group in Umbraco 7.7

        private void AddSectionSevenSeven(string alias)
        {
            var adminGroup = _userService.GetUserGroupByAlias("admin");
            if (adminGroup != null)
            {
                if (!adminGroup.AllowedSections.Contains(alias))
                {
                    adminGroup.AddAllowedSection(alias);
                    _userService.Save(adminGroup);
                }
            }
        }
    

    so at startup you will need to detect which version of Umbraco you are running before calling these... e.g

      public void AddSectionsToDefaultUser(string alias)
            {
                var currentVersion = Umbraco.Core.Configuration.UmbracoVersion.Current;
    
                if (currentVersion < new Version(7,7,0))
                {
                    // do the v7.6 version of adding sections 
                    AddSectionSevenSix(alias);
                }
    
                if (currentVersion > new Version(7,7,0))
                {
                    // do the new user group version of adding groups
                    AddSectionSevenSeven(alias);
                }
            }
    
  • Rune Kildahl Bentsen 8 posts 98 karma points
    Nov 02, 2017 @ 14:14
    Rune Kildahl Bentsen
    0

    Thanks a bunch Kevin!

    I do have one question to those examples though..

    You're not describing how to create the _userService, so I was thinking it's simply a direct reference to Umbraco.Core.Services.UserService. Problem is, even if it is compiling, it seems to not be working on install..

    Also Umbraco.Core.Services.UserService doesn't have a "Contains" method but a "InvariantContains", so I'll hope that one works the same. Still I'm beginning to wonder if I'm doing something wrong here. As far as documentation on the userservice, it has been changed with Umb version 7.7, so I'm a little on deep water with documentation on that.

    Could you specify how you're initializing the userservice?

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Nov 02, 2017 @ 14:56
    Kevin Jump
    0

    hi yes sorry that was taken from a class i have in some code doing this.

    ideally you will be calling this from the ApplicationStarted function of an application event handler (https://our.umbraco.org/Documentation/Getting-Started/Code/Umbraco-Services/#access-via-applicationeventhandler)

    from this function you have the applicationContext parameter and that let you get to the services for the current request. in our case you will be able to put:

    var _userService = applicationContext.Services.UserService; 
    
Please Sign in or register to post replies

Write your reply to:

Draft