Display different Reporting content depending on the viewer

Display different Reporting content depending on the viewer

Scenario

To create a report that displays different results depending on the user that is viewing the page.

In this example, we are displaying the content only if the user is part of a specific Confluence group, for example, confluence-users.

The content is only viewable by members of that group, which makes it possible to create dynamic content on a page.

Even if the content is hidden from users who are not part of the authorized group, the users can view the content by editing the page.

To hide or securely encrypt your Confluence data, we recommend using Visibility or Security & Encryption apps.

Result

 

Recipe

Apps

Reporting for Confluence Data Center

Level

Easy

Estimated time

15 Minutes

Macros

Report Block, User Group Reporter, Text Filter, Report Body, Report Empty

Suppliers

Global Supplier, User-group Supplier

Storage format

You can copy and paste this code into the Confluence Source Editor:

<ac:structured-macro ac:macro-id="85c01b60-2227-4412-847e-8c6149bedba2" ac:name="report-block" ac:schema-version="1"> <ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter> <ac:rich-text-body> <ac:structured-macro ac:macro-id="72c0d06e-cc6d-451a-a864-4614cbecc11f" ac:name="user-group-reporter" ac:schema-version="1"> <ac:rich-text-body> <p> <ac:structured-macro ac:macro-id="b04e2ab2-9da9-42ea-8073-91cd94bfaea2" ac:name="text-filter" ac:schema-version="1"> <ac:parameter ac:name="contains">%global:current user%</ac:parameter> <ac:parameter ac:name="required">true</ac:parameter> <ac:parameter ac:name="">user-group:members</ac:parameter> </ac:structured-macro> </p> <p> <ac:structured-macro ac:macro-id="db1a30c9-98b4-4e88-bade-4aa09f36f4a9" ac:name="text-filter" ac:schema-version="1"> <ac:parameter ac:name="contains">confluence-users</ac:parameter> <ac:parameter ac:name="required">true</ac:parameter> <ac:parameter ac:name="">user-group:name</ac:parameter> </ac:structured-macro> </p> </ac:rich-text-body> </ac:structured-macro> <ac:structured-macro ac:macro-id="17d5efff-61f7-44cd-a44b-6e5af0cd5efc" ac:name="report-body" ac:schema-version="1"> <ac:rich-text-body> <ac:structured-macro ac:macro-id="9489ef71-25af-4100-ae33-f83e054a1e1a" ac:name="info" ac:schema-version="1"> <ac:rich-text-body> <p>Testing if me, a confluence-users member, can see this</p> </ac:rich-text-body> </ac:structured-macro> </ac:rich-text-body> </ac:structured-macro> <ac:structured-macro ac:macro-id="df1a62db-41a9-4838-a84e-42aedd368014" ac:name="report-empty" ac:schema-version="1"> <ac:rich-text-body> <ac:structured-macro ac:macro-id="a4204713-a921-4cff-a7e8-19bc9f5f7172" ac:name="info" ac:schema-version="1"> <ac:rich-text-body> <p>Nothing to see here, move along</p> </ac:rich-text-body> </ac:structured-macro> </ac:rich-text-body> </ac:structured-macro> </ac:rich-text-body> </ac:structured-macro>

 

Macro structure

You can recreate the example in the editor view:

Steps

  1. Add a Report Block macro to serve as a container for the Reporting macros.

  2. Inside the macro, add the User Group Reporter macro to query the groups.

  3. Within the User Group Reporter macro, add two Text Filter macros with the following parameters:

    1. First Text Filter macro:

      • Key: user-group:members

      • Required: selected

      • Contains Value: %global:current user%
        This parameter takes the user details who accesses the page.

    2. Second Text Filter macro to set contitions:

      • Key: user-group:name

      • Required: Enabled

      • Contains Value: confluence-users
        This is the group(s) that are allowed to view the content in this field.

  4. Add a Report Body macro and enter the content you want to show to the group(s).

  5. (Optional) Add a Report Empty macro and enter the content you want the non-members of the group to view.