Page Approval

Last modified by slauriere on 2026/12/01 12:22

cogApplication for approving pages
TypeXAR
CategoryOther
Developed by

slauriere

Rating
1 Votes
LicenseGNU Lesser General Public License 2.1
Compatibility

XWiki 17.10.13 or later

Success

Installable with the Extension Manager

Description

Page Approval adds a version-based approval workflow to wiki pages. Readers see the latest approved version of a page while its authors keep working on the next one. Each version is a draft, awaiting approval or approved, and the approvers of each page decide which versions are approved.

Overview

Key features

  • Three statuses for each version: draft, awaiting approval, approved
  • Readers see the latest approved version by default, and comments, tags and ratings on it need no approval
  • A new page is visible only to its approvers and its creator until its first approval
  • An approvers group for each page, set when the page enters the workflow: the default group, or one computed by a script
  • A status indicator on every page under approval, with a link to the newest version and to the approval history
  • Archiving of pages that are no longer current
  • A dashboard of the pages under approval, also available as a dashboard gadget

How it differs from other extensions

  • Publication Workflow: a page is written as a draft copy and published over a separate page, so it exists twice, and the published page's creator and last contributor are not the users who wrote it. With Page Approval, one page holds every version, and readers see the approved one by default.
  • Change Request: proposed changes live outside the page until an approver merges them, so unapproved content never reaches the page or its history. With Page Approval, every save goes into the page's history.

Terminology

  • Page under approval: a page that has entered the workflow. No action takes it out again.
  • Approvers: the users who approve a page's versions: the members of its approvers group, set when the page enters the workflow, and any users its approval rule names directly. Admins of the page's space or wiki can always approve too.
  • Workflow classes: the classes that put a new page under approval when its first save carries an object of one of them.
  • Whitelisted change: a change, such as a comment, that keeps an approved page approved.

User guide

Typical workflow

  1. A contributor creates a page from a template that carries an object of a workflow class. The page is a draft, visible only to the contributor and the page's approvers.
  2. The contributor edits it as needed, then chooses "Submit for approval".
  3. An approver opens the page, reads the version awaiting approval, and chooses "Approve version", or "Reject version" with a comment saying what to change.
  4. Once approved, the page is visible to every reader. The contributor can keep editing it: their new versions are drafts, and readers keep seeing the approved version until a newer one is approved.

Which pages are under approval

A page is under approval if it was created with an object of one of the workflow classes chosen by the wiki admins, for example every page created from a "Procedure" template. A wiki admin can also put the existing pages of such a class under approval. Other pages behave as usual. A page under approval shows a status indicator below its title.

Version statuses

Every save of a page creates a new version, and every version of a page under approval has one of three statuses:

StatusMeaning
DraftThe status of a new version, unless it only adds whitelisted changes to an approved one.
Awaiting approvalA version submitted to the approvers.
ApprovedA version an approver approved, or one that only adds whitelisted changes to an approved version.

Diagram of the status transitions of the latest version: a new page with an object of a workflow class starts as Draft and an initialized page as Approved; Submit for approval takes Draft to Awaiting approval; Approve takes it to Approved; Reject or a new save takes Awaiting approval back to Draft; a comment, tag or rating keeps Approved; any other save takes Approved back to Draft. Archived is a state of the page that changes no status, and while it lasts no draft can be submitted or approved.
How the status of a page's latest version changes

A status decides which version readers see by default. It does not decide who may read a version.

What readers see

Before the first approval, a new page is visible only to its approvers and its creator. Other users cannot open it, even if they have view right on its space. This lets contributors work on a page and have it reviewed before anyone else sees it.

After the first approval, the page is readable by every user with view right, and it opens on its latest approved version. When the latest version is a draft or awaiting approval, opening the page redirects to the approved version, which XWiki displays as an older revision. Editors find the newer version through the status indicator.

Diagram of what readers see: before the first approval, versions such as Draft v1.1 and Awaiting approval v1.2 can be opened only by the page's approvers and its creator; after it, everyone with view right opens the page on the latest approved version, v1.2, and editors reach the newer draft v2.1 through the status indicator. The default view is not access control: every version stays readable through its URL, the history, diffs, exports and the REST API.
Which version a page opens on, before and after its first approval

Warning

The default view is not access control. Once a page has an approved version, all its versions, drafts included, stay readable by every user with view right: through their URL, the page history, diffs, exports and the REST API. Search results and inclusions of the page in other pages also show its current version, which may be a draft. Content that must stay confidential until it is approved should not rely on Page Approval after the page's first approval.

The status indicator

Every page under approval shows a status indicator between its header and its content. It starts with a badge giving the displayed version's status and number, for example "Approved · v2.1" or "Archived · v2.1". Its colour follows what it shows:

  • "Approved", "Draft" or "Awaiting approval", from the displayed version's status
  • "Archived", when the page is archived, whatever the version's status

The badge's tooltip says who gave the status and when. Clicking the badge opens the page's approval history.

Next to the badge, the indicator shows, when they apply:

  • the "Submit for approval", "Approve version" and "Reject version" buttons you may use on the displayed version
  • the archiving date, when the page is archived
  • "Readers see: v1.2 (approved)", when you are looking at a version other than the one readers see
  • "Newer: v2.1 (draft)", when a newer version exists. This is how you find the draft you just saved, since saving takes you back to the approved version.

Status indicator of approved version 1.2, with a link to the newer draft 2.1
The approved version, opened by default, with XWiki's restricted mode notice and a link to the newer draft

Status indicator of draft version 2.1, with the Submit for approval button and a link to the approved version 1.2
The draft as its author sees it, with the version readers are shown

Status indicator of version 1.1 awaiting approval, with the Approve version and Reject version buttons
A version awaiting approval, as an approver sees it

Status indicator of an archived page, with its archiving date
An archived page

Approval actions

The More actions menu, with its Approval group: Approve version, Reject version, Archive and Edit the approval rule
The Approval group of the More actions menu, as an approver sees it

The approval actions are in the page's "More actions" menu, in a group titled "Approval", and the version actions are repeated in the status indicator. Each action is shown only to the users who may use it, and only when it applies. Submitting, approving, rejecting, archiving and restoring each ask for confirmation, with an optional comment that is kept in the approval history.

ActionWhoWhen
"Submit for approval"Users with edit right on the pageOn the latest version, when it is a draft and the page is not archived
"Approve version"ApproversOn the version awaiting approval, when the page is not archived
"Reject version"ApproversOn the version awaiting approval
"Archive" / "Restore"ApproversAny time
"View approved version"Everyone who can view the pageWhen another version is displayed
"Edit the approval rule"Approvers, and admins of the page's space or wikiAny time
  • Submitting a newer version withdraws the older one awaiting approval, which becomes a draft again.
  • Saving the page while a version awaits approval creates a draft, which has to be submitted too. The version already awaiting approval keeps that status until an approver approves or rejects it, or a newer version is submitted.
  • Approvers may approve a version they wrote or submitted themselves, since an approvers group may have a single member. The approval history records who approved it.
  • To go back to the approved content, roll back to it as usual: the rollback creates a new version, which is a draft and has to be approved again.

Comments, tags and ratings

Commenting on a page, tagging it or rating it saves the page as a new version. As long as the latest version is approved, these changes keep it approved, so they reach readers without waiting for an approver. Wiki admins choose which kinds of changes behave this way.

When the latest version is a draft or awaiting approval, later comments, tags and ratings go into drafts, and readers see them only when a version that includes them is approved.

Archiving

Approvers archive a page that is no longer current, with "Archive" in the "Approval" group of the "More actions" menu. Archiving has these effects:

  • The page becomes hidden, so it drops out of search results, the navigation tree and the page index for users who do not display hidden pages.
  • It stays readable by direct link, with an "Archived" badge and the archiving date in its status indicator.
  • No version status changes: an archived approved page stays approved.
  • It stays editable, but a new draft cannot be submitted or approved until the page is restored.

"Restore" undoes the archiving. To ask for a page to be archived, leave a comment on it.

Approval history

The "Approval" entry of a page's "Information" tab names the page's approvers group, with a link to the group's page. It also links to the page's approval history, as the status indicator's badge does.

Approval history of a page: its approvers, its versions with their statuses, and its events
The approval history of a page

The approval history lists the page's versions with their statuses, newest first, each with who gave the status and when. It then lists the approval actions taken on the page (entering the workflow, submissions, approvals, rejections, archiving and restoring) with their users, dates and comments.

Approval dashboard

The approval dashboard, listing pages with their status, approvers, creator and last author
The approval dashboard

The approval dashboard lists the pages under approval that you can view, with their status, whether a version is awaiting approval, whether they are archived, their approvers, their creator and their last author. You can filter and sort it. Archived pages are left out unless you filter on them.

The full dashboard is reachable from the "Page approval" entry of the "Applications" panel. It is also available as the {{approvalDashboard/}} macro, which you can add to any page or, as a gadget, to a dashboard. Its parameters preset its filters, which readers can still change:

ParameterTypeDefaultDescription
createdByMebooleanfalseOnly the pages the current user created
awaitingApprovalbooleanfalseOnly the pages with a version awaiting approval
archivedbooleanfalseOnly archived pages, which are otherwise left out

For example, to list the pages you created that are waiting for an approver, on your profile's dashboard:

{{approvalDashboard createdByMe="true" awaitingApproval="true"/}}

And for approvers, the pages with a version awaiting approval:

{{approvalDashboard awaitingApproval="true"/}}

The dashboard's column chooser also offers the date of the page's last change and the fields of the first listed workflow class, as columns hidden until a reader picks them.

Administration

This section is for wiki admins.

Installation

Installing "Page Approval" puts no page under approval: until you choose workflow classes, the wiki behaves as before. Page Approval reads no xwiki.properties setting. Its configuration is stored in the XWiki.PageApproval.ApprovalConfiguration page.

Demo

To try Page Approval first, install the "Page Approval Demo" extension on a test wiki, never on a production one: it creates users, an admin among them, and changes the approval configuration. It brings "Page Approval" with it.

The demo is a small company knowledge base under the "Page Approval Demo" page (APV-Demo):

  • How-tos for three applications, CRM, Payroll and Intranet, each approved by the owner group of its application. A Velocity resolver reads that group from the application's page, and Intranet has none, to show a page without approvers.
  • Procedures, approved by the admin group of the nearest space above them. A Groovy resolver walks the spaces up from the procedure.
  • Policies, which are not under approval at installation, to show the initialization of existing pages.

Install it as a wiki admin with programming right, then use the three sections of the demo's home page:

  1. Setup. Type a password and run it. It creates the demo users with that password, adds the how-to and procedure classes and their two resolvers to the configuration, sets a default approvers group if the wiki has none, and creates a few pages in each state: a draft, a page awaiting approval, an approved page with a newer draft, a rejected one, an archived one, and pages with no approvers group. Its report gives each page with the state it reached. Setup can be run again: it only adds what is missing.
  2. Walkthrough. Eighteen steps, each naming the user to log in as and what that user should see: what readers are refused, how an approval lifts the read restriction, why a comment keeps a page approved, how an approvers group is computed once at entry, and what happens when the configuration is saved by an admin without programming right.
  3. Remove. Deletes the pages the demo and the walkthrough created, takes the demo's classes and resolvers out of the configuration, and deletes the demo users. Run it before uninstalling the demo, since an uninstall alone leaves the users behind, the admin among them. When uninstalling, tick every page in Extension Manager's question about the pages to delete.
UserRole in the demo
PageApprovalDemoContributorWrites how-tos, procedures and policies
PageApprovalDemoApproverAApproves Payroll how-tos, Infrastructure procedures and policies
PageApprovalDemoApproverBApproves CRM how-tos and the other procedures
PageApprovalDemoReaderReads and comments
PageApprovalDemoWikiAdminA wiki admin without programming right

Configuration

The configuration is in Administer Wiki > Content > Page approval.

The Page approval section of the wiki administration
The Page approval section of the wiki administration

It holds, in this order:

SettingDescriptionDefault
Workflow classesA page created with an object of one of these classes enters the approval workflowNone
Whitelisted classesChanges to objects of these classes keep a page approvedComments, tags and average ratings
Default approvers groupThe approvers group given to a page entering the workflow when no custom resolver appliesNone
Approvers resolversScripts computing the approvers group of the pages carrying an object of a given classNone
Approvers resolver timeoutHow long a resolver may run, in seconds5
Initialization of existing pagesPuts the existing pages of the workflow classes under approval

There is no on/off switch: emptying the list of workflow classes only stops new pages from entering the workflow.

Getting started

  1. Create the group whose members will approve pages, and set it as the "Default approvers group".
  2. If some pages need other approvers, define approvers resolvers.
  3. Add the class of the pages to approve, for example the class of your procedures' template, to the "Workflow classes". From then on, every new page created with an object of that class enters the workflow.
  4. Check that users create those pages as non-terminal pages, from a template that carries an object of the class. An App Within Minutes application does this for its entries once its template provider's "Terminal" setting is "No". Check that setting: App Within Minutes sets it to "Yes" for some applications, and shows it to advanced users only.
  5. Run the "Initialization of existing pages" to put the existing pages of that class under approval.

Set the approvers before adding the class, since each page's approvers group is computed only once, when it enters the workflow.

Workflow classes

A page enters the workflow when its first save carries an object of one of the workflow classes. A page that gets such an object on a later save does not enter it, and neither does a page that is moved or restored from the recycle bin. A page copied with its children is under approval, with the original's approval records. One copied without them enters the workflow as a new page. Entering the workflow writes only outside the page, so it adds no version to it.

Removing a class from the list, or removing a page's object of that class, does not take any page out of the workflow. There is no per-space switch and no action that puts a single existing page under approval.

Pages under approval must be non-terminal pages, since each one keeps its approval records in a child page. A terminal page created with a workflow class object does not enter the workflow, and an error is logged.

Initialization of existing pages

Pages that existed before their class was added to the workflow classes enter the workflow only through the initialization job. Run it with "Run the initialization" in the administration section, each time you add a workflow class.

The job puts under approval the existing pages carrying an object of a workflow class added since its previous run, and approves their current version as is, without review and with no read restriction, so their readers keep seeing them. Each page gets its approvers group as a new page would.

Its report lists the pages it put under approval, the pages already under approval that it skipped, and the pages it left out, with the reason: terminal pages, failed entries, or classes already initialized. Pages left out after a failure are retried by the next run.

Information

Leaving existing pages out of the workflow would keep them out for good, and every later change to them would go unreviewed. The cost of initializing them is that an approved version does not always mean an approver read it: the approval history of an initialized page shows that it entered the workflow approved.

Whitelisted classes

A save keeps an approved page approved when it changes neither the content, nor the attachments, nor the page's fields (the author fields and the hidden flag aside), and every object it adds, changes or removes belongs to a whitelisted class. The list starts with XWiki.XWikiComments, XWiki.TagClass and XWiki.AverageRatingsClass. Remove a class to make its changes create a draft, or add one, for example the class of a field that editors update without review.

A change to the page's rights is never whitelisted. A save that Page Approval could not check creates a draft.

Approvers

When a page enters the workflow, Page Approval computes its approvers group and grants that group edit right on the page's hidden Approvals child page. The page's approvers are the users with that right, so the approver check is XWiki's own edit right check. Admins of the page's space or wiki can always approve.

The group is computed once. When the data it was computed from changes later, or the default approvers group changes, the approvers of pages already under approval stay as they were.

Default approvers group

The group set as "Default approvers group" approves every page that no custom resolver applies to.

Custom approvers resolvers

A resolver computes the approvers group of the pages carrying an object of a given class, from data on the page or elsewhere in the wiki. For example, a procedure page's approvers can be the managers of the department it belongs to.

Resolvers are objects of the XWiki.PageApproval.ApproversResolverClass class on the XWiki.PageApproval.ApprovalConfiguration page. The administration section lists them, and "Edit the approvers resolvers" opens that page's object editor. Each resolver has:

PropertyDescription
Applies to classThe full reference of the class whose objects select the pages it applies to, for example Procedures.Code.ProcedureClass
Languagevelocity or groovy
ScriptThe script computing the group
DescriptionWhat the resolver computes, for wiki admins

The script gets docRef, the reference of the page entering the workflow, as a variable. A Velocity script gives the group by setting $approversGroup, a Groovy script by returning it. The group is a document reference, or a string resolved in the page's wiki, where a bare page name, such as MarketingApprovers, is looked up in the XWiki space. The script runs in the page's wiki, with no current document: only docRef identifies the page.

A Velocity resolver taking the group from the page's department, assuming the procedure class has a department field naming a department page, and the department class a managers field naming a group:

#set ($procedure = $xwiki.getDocument($docRef))
#set ($department = $procedure.getValue('department'))
#if ("$!department" != '')
  #set ($approversGroup = $xwiki.getDocument($department).getValue('managers'))
#end

A Groovy resolver choosing the group from the page's space:

docRef.lastSpaceReference.name == 'Marketing' ? 'MarketingApprovers' : 'ProcedureApprovers'

Rights. Only wiki admins can edit the configuration page. A resolver runs with the rights of the configuration page's last author, never those of the user creating the page, and only while that author is a wiki admin, with programming right for a Groovy resolver. The administration section names that author.

Failing closed. A resolver fails when it throws an error, gives nothing, gives something other than an existing group, or runs longer than the timeout. A page matched by two resolvers counts as a failure too. A failure is logged and leaves the page with no approvers group, so only admins of the page's space or wiki can approve it until one is set. The page's "Information" tab then says that the page has no approvers group.

Warning

Whoever can edit the data a resolver reads decides the approvers of every page that resolver handles, and whoever can edit a group's page decides its members, at any time. Restrict edit right on that data, and on the approvers groups, to their owners and to wiki admins.

Changing the approvers of a page

A page's approvers are changed with "Edit the approval rule", in the "Approval" group of the page's "More actions" menu:

  • Admins of the page's space or wiki get the rights editor of the page's Approvals child, where they change which group or users have edit right.
  • Approvers get the object editor of that child, on its rights objects.

The page under approval gets no new version, so its status and its last author do not change. The history of the Approvals child records each change, with who made it and when.

Warning

When a group or user that alone holds the edit right on an Approvals child is deleted, XWiki removes that rule, and every user who may edit the page can then approve it. If the page has not been approved yet, XWiki also removes that group or user from the page's read restriction, and deletes the restriction if it named no one else, which leaves the page readable by every user with view right. Before deleting an approvers group, give its pages another one.

Approval records

Each page under approval keeps its approval records in a hidden child page, <page>.Approvals: one object per approval action, with the version it applies to, the user, the date and the comment, and a summary that the dashboard filters on. The records are kept outside the page so that approving a version does not save the page, and the page's creator and last contributor remain the users who wrote it.

  • Rights. The edit right on the child names the page's approvers. Only admins of the page's space or wiki may delete the child: Page Approval makes XWiki.superadmin its creator, since XWiki lets a page's creator delete the page whatever its rights.
  • Hand edits. Approvers may correct the records by hand in the object editor. Page Approval refuses a hand edit that would take the page out of the workflow or leave it with no approvers, and brings the summary and the read restriction back in line after any other.
  • Copy and export. The records travel with the page when it is copied or exported with its children.
  • Move. Page Approval moves the records with the page, along with an unapproved page's read restriction, even when the user moving the page may not delete them. A move that would make a page under approval terminal is refused.
  • Delete. The records go to the recycle bin with the page, so a page created later at the same place does not inherit them. Restoring the page alone leaves it out of the workflow. Restore its Approvals child as well to put it back under approval.

Read restriction of unapproved pages

Until its first approval, a page is readable only by its approvers and its creator. Page Approval writes this as a "page and children" view rule in the page's own WebPreferences, so writing and lifting it add no version to the page. The first approval removes it. Page Approval only touches that rule, never the page's other rules.

The restriction holds against readers, not against the page's editors, who can open the page to others by adding page rights. The page's history shows who did so.

Security considerations

  • Versions stay readable. After a page's first approval, every version is readable by every user with view right.
  • Scripts in pages under approval. The approved version is often an older revision, which XWiki renders in restricted mode, so the script macros in it do not run. Keep scripts out of the content of pages under approval, and put them in sheets or wiki macros instead.
  • Resolvers. Resolvers are scripts run with a wiki admin's rights. Review them as you would any wiki admin's script, and protect the data they read.

Development

Scripting

The $services.pageApproval script service gives scripts the approval state of a page and performs the approval actions as the current user. Every method that takes a page takes its document reference, docRef.

MethodReturns
isUnderApproval(docRef)Whether the page is under approval
getVersionStatus(docRef, version)The version's status: DRAFT, CANDIDATE (awaiting approval) or APPROVED
getVersionStatuses(docRef)Every version, oldest first, with its status, the user who gave it and when
getApproval(docRef, version)The approval that covers the version: the approved version, the last version it covers (whitelisted changes saved on top of it), the approver, the date and the comment
getLatestApprovedVersion(docRef)The latest approved version, or nothing when the page has none
getDefaultVersion(docRef)The version shown when none is requested: the latest approved one, or the current version when the page has none
isApprover(docRef)Whether the current user is an approver of the page
getApproversGroups(docRef)The groups and users that the page's approval rule names
getArchive(docRef)The page's archiving, with its date, user and comment, or nothing when the page is not archived
submitForApproval(docRef, version, comment)Submits the current version, a draft; true on success
approveVersion(docRef, version, comment)Approves the version awaiting approval; true on success
rejectVersion(docRef, version, comment)Rejects the version awaiting approval; true on success
archive(docRef, comment), restore(docRef, comment)Archives or restores the page; true on success
startInitialization()Starts the initialization of existing pages; true when it started or is already running
getInitializationStatus()The report of the running or last initialization: its state, and the pages it put under approval, skipped as already under approval, and left out
getLastError()Why the last action that returned false in this request failed: its reason, such as NOT_ALLOWED or NOT_A_DRAFT, and its message

Rights. The read methods return nothing for a page the current user cannot view. An action runs only when both the current user and the script's author hold the right it needs: edit right on the page to submit, and edit right on its Approvals child for the other actions. A script a contributor wrote therefore cannot act as the user viewing it. The two initialization methods need both to be wiki admins.

Form token. The script service does not check a form token. A page that performs actions should do so only on a POST request carrying a valid one, as Page Approval's own forms do.

#set ($docRef = $doc.documentReference)
#if ($services.pageApproval.isUnderApproval($docRef))
  Readers see version $services.pageApproval.getDefaultVersion($docRef).
#end
#if ($request.method == 'POST' && $services.csrf.isTokenValid($request.form_token))
  #if (!$services.pageApproval.approveVersion($docRef, $request.version, $request.comment))
    #set ($error = $services.pageApproval.lastError)
    $services.rendering.escape("$error.reason: $error.message", 'xwiki/2.1')
  #end
#end

Java API

Java code depends on org.xwiki.contrib:page-approval-api and injects the org.xwiki.contrib.pageapproval.ApprovalService component, which the script service wraps. It has the same read methods, with the same rule for pages the current user cannot view, and the same actions, which throw an ApprovalException carrying a Reason instead of returning false. It checks the current user's rights only: checking the script's author is the script service's addition. The types it returns, ApprovalStatus, VersionStatus, VersionApproval and PageArchive, are in the same package. The initialization of existing pages has no Java API.

Limitations

  • One level of approval: no multi-step workflows, such as reviewer, then manager, then director, and no delegation.
  • No notifications yet: approvers find the versions awaiting approval in the dashboard.
  • Translations: only a page's default-locale document is considered.
  • No action takes a page out of the workflow.
  • The dashboard does not filter on the date of the page's last change.

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Versions

Dependencies

Dependencies for this extension (org.xwiki.contrib:page-approval-ui 1.0):

  • org.xwiki.contrib:page-approval-api 1.0

Get Connected