Small Fix Planned for 28-March-2023

Hello! :wave:

We plan to push out a bug fix regarding rules and page detail views. This will change behavior for some pages, and Support has emailed the account owners with details about it. If you didn’t receive an email, it shouldn’t affect any of your views, if you were one of a small number of our users who did, please reach out to Support with any questions.

Since there are a few days between when the email communications went out, and when the fix will happen, here are the details:

Details about an upcoming bug fix that will be released on Tuesday, 3/28/23.
This fix may require you to make specific changes in Page Rules.

Summary

In Page Detail views, rules are currently not being followed correctly for User Roles.

Current Behavior

The screenshots below depict a details page, showing the details of a connected account, with a rule set up indicating that specific action should be taken in that view, based on the user role.

Currently, the Staff User is not redirected to the parent page, and instead, is allowed to click on the item details.

The Admin User, when clicking on “View”, is redirected to the parent page.

In other words, a Staff User who clicks on “View” on this details page, should be redirected to the parent page.

The Upcoming Bug Fix

Next week’s release will correct this, so the result will be that the Staff User will be redirected to the parent page, while the Admin User will be able to view the details.

The rule on the details page will follow the signed-in user, as expected.

Action Required: If you would prefer to keep the current behavior after the release, the rule will need to be changed to point to specifically target the record on the page (not the signed-in user), as shown in the Post Release screenshot.

Post Release

Change the rule to target the Record detail (not the user role).

The Support Team has a list of all affected views in each app (at the time of email) and can provide a list to those who reach out.

We apologize for any inconvenience this may cause and thank you for your patience if this affected you.

Cheers,
Kara

2 Likes

cc: @EricAlderman

1 Like

@DavidRoize61529 :sunglasses: David very kindly wrote up an explanation in what may be a more clear way (I thought it was!) so I’ve asked him to also post that as well. Thank you David! :dizzy:

Current Behavior/Bug

Currently, page rules that target the logged-in user are either ignored or otherwise broken when the page contains a view listing user account records.

The Fix

Page rules targeting the logged-in user on affected pages will start working correctly.

Example

To see this bug in action, login to this Knack app with the following login details:
Username: authorized@example.com
Password: test123

We have a grid listing Companies, with links to 3 different pages.

Each of the linked pages has two identical Page Rules set up:

  1. If the logged-in user has Authorized=Yes, show a Confirmation (green) message.

  2. If the Manager Account connected to the page’s company has Authorized=Yes, show a Warning (amber) message.

We would expect these rules to behave the same on all three pages.

But if you try going to each of them for each Company, you’ll find that the first Page Rule only works for the Company Details page. This is because both the Account Details and Connected Accounts pages contain at least one view listing user account records.

Do I need to take action?

If you were intending to target the logged-in user with your rule, you should be fine and the rule will now work as originally intended.

If you intended to target the user record connected to the page but mistakenly selected the field on the logged-in user (the one without a field name in parentheses), then you’ll have to change the rule to target the appropriate field.

Am I affected?

If you are affected by this change, you should have received an email from Knack Support about this bug fix.

You may reply to that email or email support@knack.com to request a list of affected pages, so you can check if you need to take action.

You can also use the below code snippet to get a nicely formatted list, with links to affected pages in the builder.

  1. Open your Live App.
  2. Right-click anywhere on the page
  3. Click Inspect Element
  4. Click the Console tab in the panel that appears
  5. Paste the following and press enter:
{
  const userObjects = Knack.objects.where({ user: true }).map((obj) => obj.get('key'));
  // Check if view has user object source, excluding logged-in user record
  const checkView = ({ source }) =>
    source && !source.authenticated_user && source.type !== 'database' && userObjects.includes(source.object);
  // Check if rule has criteria involving provided object
  const checkRule = (rule, objectKey) =>
    rule.criteria?.some((criteria) =>
      criteria.field.startsWith(Knack.objects.findWhere({ key: objectKey }).get('profile_key'))
    );
  const affectedScenes = Knack.scenes.filter(({ attributes: { views, rules } }) =>
    views.some((view) => checkView(view) && rules?.some((rule) => checkRule(rule, view.source.object)))
  );
  const formattedScenes = affectedScenes.map(({ attributes: { name, slug, key, rules, views } }) => ({
    name,
    slug,
    key,
    builderURL: `https://builder.${Knack.domain}/${Knack.account.slug}/${Knack.app.get('slug')}/pages/${key}/rules`,
    views: views.filter((view) => checkView(view) && rules?.some((rule) => checkRule(rule, view.source.object))),
    rules: views.reduce((acc, view) => {
      if (checkView(view)) {
        const foundRules = rules
          ?.map((rule, idx) => [rule, idx])
          .filter(([rule]) => !acc.some(([{ key }]) => key === rule.key) && checkRule(rule, view.source.object));
        return [...acc, ...foundRules];
      }
      return acc;
    }, []),
  }));

  console.debug(formattedScenes);
  if (formattedScenes.length) {
    formattedScenes.forEach((scene) => {
      console.group(scene.name);

      console.log(scene.builderURL);

      console.group('Affected rules');
      scene.rules.forEach(([, idx]) => console.log(`Page Rule ${idx + 1}`));
      console.groupEnd();

      console.groupEnd();
    });
  } else {
    console.log('No affected pages detected 👍');
  }
}
8 Likes

Hi @hmnd - This is an AWESOME solution for being able to quickly check whether there are any rules that may be affected by this upcoming change. I highly recommend that all builders run this. :+1:
I really appreciate your generosity and time taken to provide this to the community :pray:

4 Likes

@hmnd :rocket:
Echoing @CarlHolmes sentiment, thank you so much for the time you spent to make this more clear, and building the console checker. I know that @Kat and the Support team will be so appreciative when they see this as well! :trophy:
Fantastic example of collaboration and working #bettertogether :100:

5 Likes

Hey @hmnd - absolutely love this! Huge thank you from us at Support!

2 Likes

Thanks David to share this with us.

1 Like

Very helpful @hmnd. Thanks a lot.

@hmnd Thank you very much David!!