Custom Homepage for Groups

Ah! Sorry. I missed that.

Hmm. Yes. I wonder why I removed support for those. I think maybe you can change those in core now?

I’ll see if that’s in core, and if so, remove those settings.

Or maybe something happened in core that broke those changes. I’ll see what I can figure out. . . .

3 Likes

I’m still not sure why I deleted support for the default and anon homepages before. I put those back.

Now if there is a custom_default_homepage it uses that unless there is a matching group match. If there’s an anon_page and the user is anonymous, it uses that.

I couldn’t figure out how or when the mobile page should be set (is it for anon users? all users? does it override the default page? the group map?), so I deleted it. If you’re using that mobile page, tell me what you think it should override (I think maybe set it as the default page if they are on mobile, but if there is a group page, then use that? Still not clear what to do for anon vs logged in–I guess there maybe needs to be mobile versions for all of them?).

Here’s the code:

      let url = null;

      if (settings.custom_default_homepage) {
        url = settings.custom_default_homepage.replace(/^\/+/g, "");
      }

      if (user) {
        if (user.primary_group_name && settings.group_page_map) {
          let groupMap = settings.group_page_map.replace(",", ":").split("|");
          const mapEntry = groupMap.find((value) =>
            RegExp(user.primary_group_name).test(value)
          );
          if (mapEntry) {
            url = mapEntry.split(":")[1].replace(/^\/+/g, "");
          }
        }
      } else if (settings.anon_page) {
        url = settings.anon_page.replace(/^\/+/g, "");
      }

And then it changes the homepage only if url has a value.

8 Likes

Is this theme component intended to redirect anyone in the group to homepage on login or using the links? I have it installed, and the logo will direct to the selected page but on login the user still is directed to the default /latest page. If this handles that login redirect, I must still have something set incorrectly.

My goal is all users be included in a default group and all be redirected to an alternate page on login.

It needs to be their Primary group for this TC to kick in. That is by design, so that there is no conflict when a user is a member of more than one group with a redirect.

Our logic at the start was that it only overrides the default homepage - all others (including anon) take precedence.

The classic use case is using the Categories + Latest view on desktop, as this displays as Categories on mobile (which isn’t very useful).

These days, the sidebar makes this unnecessary for most instances, so I think that removing it makes sense. It might catch out some who have been using the TC for a while though.

2 Likes

Is trust level 0 considered a valid group? Would this be the correct setting for the Group Page Map? trust_level_0:/discourse-ai/ai-bot/conversations. That is the current setting I have set.

No, the trust level groups can not be used as they can not be made Primary.

You could work around that by using the dynamic groups plugin to make a mirror group if that is vital for you.

3 Likes

Have you tried to set the custom default homepage to your AI bot page (so it’s the default for everyone) and then set the homepage for anon users to latest (to overwrite the default for them)?

1 Like

Ah. OK. I think a different version of this got sent in my email notification. I like this answer better. :slight_smile:

2 Likes

Thought you would! Still using email notifications?? That is a bit dinosaurish, Jay!

This is unlikely to work as @everyone isn’t a true group and cannot be made primary

2 Likes

By “everyone”, I meant “global”, not the pseudo group. I will edit my post so that it is not misleading.

2 Likes

I am very old. And besides, I’m logged in to meta for not much more than 10 hours a day, and I don’t want to miss anything!

5 Likes

First, thank you everyone for jumping in and helping with this! It is greatly appreciated!

This is a head scratcher for me.

I have installed this plugin without any issues and set trust_level_0 in the settings with make this primary group. All members in site were added to the group. All users show this as the primary group now.

In the Custom Homepage for Groups component settings this is what I have set.

When accessing the page the users in the Community-Core primary group still land on /latest. If I change the Anon Page to something other than /latest when logging in the users will be shown whatever page is shown in that field so that is the redirect that is occurring.

I am using the Canvas Screen theme and changed to the default to test with the same result.

I also disabled all theme components and plugins to see if this helped without success.

I am thinking that there is either I am missing something that may be apparent to others or there may be an issue with the component.

Did you look in the inspector and see the primary group in the body tag?

Jay, really not sure what inspector for this is?

The users show in the group and have the same indicator on their profiles as mine in this image.

When you right click on your site and select inspect you can see what pfaffman is asking for.
For example I see this on my user admin page (/admin/users/{user_id}/{username})


And since this is my account when I right click and select inspect I see

There you can see “testgroup” in the <body>

That is what I meant, but I now remember/see that the component gets the primary group from the user model, not from the CSS.

So, maybe find a user in the admin user route, and add .json to the URL. Then check what their primary group is and search (in the browser) for primary_group: true and check that the name matches exactly the case you used in the theme config.

2 Likes

Hi everyone,

Thanks for the clarification. I followed these instructions and used the .json URL to confirm the exact group name.

The primary group name is indeed Community-Core, with the capital letters and hyphen, which is exactly what I have entered in the theme component’s settings.

Unfortunately, it’s still not working. The Anon page redirect is still in effect. So, the issue must be something else.

Can others confirm this works for them?

Do you have any other ideas what I could check?

No. If it’s going to the anon page and not the “custom default homepage”, then it’s not finding the user when it does

      const user = api.getCurrentUser();

I don’t know how that could be happening if the user is, in fact, logged in.

Ah, it sets the user in the initializer, so I think if you log in after the site is loaded, this code may not execute again. Have you tried reloading the page?

1 Like

Thanks Jay, I have tried reloading. I tried numerous adjustments to the urls and similar. It definitely loads the Anon page. If I change that it goes to that page and also shows /latest in the browser url.

I have search and assume there is no other way to simply redirect. It was easier with php sites. I still am novice with Discourse.

this is a very odd edge-case scenario and possibly entering the territory of making Discourse do something it’s not designed to do.