Files
b9eed09fde Docs: Update ABAC and property system docs for v12.0 (#39297)
* Docs: Add an access policy expression reference

Access rule syntax was spread across several pages and the v12
changelog, and the multiselect, hierarchical, IP range, version and
account-age operators and the native user fields weren't documented
anywhere. Add one reference page that covers the values a rule can
use, every Simple Mode operator and the expression it produces, the
full set of operators Advanced Mode accepts, ranked, hierarchical,
channel and session attributes, how rules combine, and what happens
when a rule can't be evaluated. List it in the attribute-based access
control section of the sidebar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Document channel attributes in access rules

Channel attributes can be compared with user attributes in membership
and permission policy rules, but the docs still described them, and
Classification Markings, as informational only. Replace those claims
with a section on using channel attributes in access rules: linking
the attributes, adding one in the editor, the supported comparisons,
and the warning that a channel missing a value denies everyone.

Also document the Classification Markings clearance attribute, drop the
feature flag instructions for channel attributes, and correct the
license badge to Entry or Enterprise Advanced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Update ABAC overview and system-wide policies for v12

Point navigation at the Membership Policies and Permission Policies
pages, describe per-channel auto-add and the "Enforce policy
immediately" option, and add steps for creating a permission policy.
Explain that simulation is available in permission policy editors via
Simulate rules, including session attribute overrides.

Replace the Simple Mode operator lists with a link to the expression
reference, fix the Advanced Mode syntax to user.attributes.<name>, drop
instructions for feature flags that are now on by default, align
versions (permission policies in v11.7, burn-on-read in v12.1), update
the license tier to Entry or Enterprise Advanced, and shorten the team
assignment section in favour of the team membership page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Update channel and team-scoped channel policy pages for v12

Team Admins can assign team-level channel membership policies to public
as well as private channels, so the team channel policies page now
describes both and explains that public channels are advisory. The
self-inclusion filter and self-exclusion check only apply when a policy
covers a private channel.

Auto-add is described as a per-channel setting that isn't inherited
from system policies, replacing the old active-state wording. On public
channels with auto-add on, a matching user who leaves is added again at
the next sync, and both pages now say so. Policy inheritance now says
plainly that every applicable policy must allow access. The duplicated
Team Settings section on the channel access rules page is replaced with
a link, operator lists link to the expression reference, and
instructions for feature flags that are on by default are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Fix team membership policy labels and licensing

Quote the System Console setting as it appears in the UI ("Allow
attribute based access controls on this server") and describe the
license as Entry or Enterprise Advanced throughout. Drop the feature
flag instructions and the flag on/off table, since team membership
policies are on by default.

Call the editor Simple Mode, as the UI does, and point the operator
lists at the expression reference rather than repeating an incomplete
list. Link the sync interval settings and the ABAC setting to the
System Attributes settings reference, and align the team settings
entry in the user management configuration page with these pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Document hierarchical attributes and attribute sync in Attribute Management

Add a Hierarchical attributes section covering how to build the value
tree (top-level and child values, multiple parents, moving and deleting
values), the create-only type, the parent and depth limits, where values
are set, and how the attribute is used in access rules.

Correct the licensing badges to Entry, Enterprise, or Enterprise Advanced
for the page and Entry or Enterprise Advanced for the Channels resource,
drop the feature-flag conditions, and fix the Channels display location
choices. Note that AD/LDAP takes precedence when both sources are linked,
that hierarchical attributes can't be linked, and point the user-managed
attributes link at the System Attributes settings reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Document mmctl user attributes commands

The mmctl reference described a top-level `mmctl cpa` command with flags
and field types that don't exist. Replace it with the real
`mmctl user attributes` command (aliases `attrs` and `cpa`), covering the
field list/create/edit/delete and value list/set subcommands with their
actual arguments and flags.

Explain that from v12.0, field edit and delete fail for attributes linked
to Attribute Management, that the underlying User Attributes API is
deprecated, and correct the license badge to Entry, Enterprise, or
Enterprise Advanced. Point existing links at the new section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Point user attribute links at Attribute Management

The User attributes page describes the System Console page from before
v12.0, which now redirects to Attribute Management. Retitle it and state
plainly that it covers earlier releases only, fix its malformed
EnableUserManagedAttributes config example, and use the UI's own
"Editable by users" label throughout.

Links elsewhere that mean the current feature (zero trust, plans, profile,
calls, session attributes, user management, mission partner and Slack
migration pages) now go to Attribute Management, and the calls page uses
the current "Profile display: Hidden" label. Also fixes a typo on the
editions page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Add System Attributes settings reference and ABAC audit events

The System attributes page listed features but documented none of the
AccessControlSettings. It is now a settings reference: an index of the
System Attributes console pages, then one entry per setting with its
console label, default, config.json key and environment variable,
including the four settings that have no console option.

The audit log schema now lists the per-user membership records written
by sync jobs when ABAC audit logging is enabled, with their parameters
and reason values. The access control events table now describes what
each event records today and adds the plugin policy, team policy cleanup
and batch auto-add events. User attributes events gain cpaValueChange.

Links that pointed at the legacy user attributes page for the
user-managed attributes setting now point at the new reference entry,
and the team membership page no longer says that an attribute refresh
interval of 0 disables refreshing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Document user attribute sync in AD/LDAP and SAML settings

The AD/LDAP and SAML settings pages covered only the built-in profile
fields, so admins setting up an identity provider couldn't find the
User attributes sync section. Add a settings entry for it in both
sections, describing how mappings are saved, which attribute types can
be synced, how values and options are managed, AD/LDAP precedence, and
when each source syncs. Point to it from the AD/LDAP and SAML setup
pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Document bot attributes and user attribute values

Bot accounts can carry user attribute values from v12.1, so access
policies check them like any user. The integrations settings page now
explains where to set them, who can, and how they interact with access
rules and the user-managed attributes setting.

The profile page now covers user attributes from the user's side: where
they appear, which values users can change and why some are read-only,
how each kind of value is chosen (including the hierarchical picker),
and how the profile popover shows them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Correct v12 ABAC and attribute notes in changelog and upgrade guides

The v12 release notes pointed integrations at an undefined "Global
Attributes API" and never said the User Attributes (Custom Profile
Attributes) API is deprecated. Name the Properties API endpoints for user
attributes and templates instead, and add a deprecation entry that covers
the HTTP 400 on linked fields, the effect on mmctl user attributes field
edit and delete, and the planned removal.

Also correct the session attributes note (they're available by default but
each one starts disabled), drop feature flag conditions for channel
attributes that were already on by default, and link the hierarchical
functions and channel attributes notes to their reference pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Remove the bot attributes section from integrations settings

Setting user attribute values on bot accounts isn't in a released
version yet, so the Bot attributes subsection described a feature
readers can't use. Remove it until the feature ships.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Limit AD/LDAP and SAML attribute sync notes to current behavior

The AD/LDAP, SAML and Attribute Management pages described attribute
sync behavior that hasn't shipped in a release: Select and Multiselect
attributes keeping their type, sync-managed options and the option
limit, clearing values the identity provider stops sending, and AD/LDAP
taking precedence over SAML. Remove those notes. Linking an attribute to
AD/LDAP or SAML changes it to Text, and an external source can be added
only before the attribute applies to a resource, as the Attribute
Management page said before.

The User attributes sync settings entries, when each source syncs, and
the links from Attribute Management are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Remove the burn-on-read permission from permission policy pages

Restricting who can send burn-on-read messages with a permission policy
isn't in a released version yet; released permission policies cover
file upload and file download only. Remove the burn-on-read permission
from the system-wide and channel permission policy pages, the ABAC
overview, the System Attributes settings and audit log pages, and the
end-user burn-on-read section. Burn-on-read messages themselves are
still documented, along with the setting that turns them off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Remove hierarchical "has any of" against channel attributes

In v12.0, hasAnyOf and hasAllOf need a multiselect user attribute, and
Simple Mode doesn't offer a channel attribute for "has any of" or "has
all of" on a hierarchical attribute. Hierarchical attributes compare
with a channel attribute only through the covers and within operators,
so the expression reference and the channel attributes page no longer
say otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Limit the permission policy warning to file actions

In v12.0, permission policies cover only file upload and file download,
so posting a message is never evaluated against them. The warning no
longer describes incoming webhooks and custom slash commands, which
can't attach files, or plugins posting messages.

It also said scheduled messages are evaluated when they're scheduled.
In v12.0 nothing is checked at scheduling or at send time: the upload
restriction is checked when each file is uploaded, so the warning now
says that instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Drop required channel attribute claims from the v12.0 changelog

In v12.0, required channel attributes are enforced only when the
off-by-default ChannelAttributesRequired feature flag is on. By default
the create-channel dialog doesn't ask for channel attributes and the
channels API doesn't refuse a channel without a required value, so the
channel attributes entry no longer says either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Remove the Managed by indicator from Attribute Management

The Users resource settings in v12.0 don't show which external source
an attribute is synced from; the Managed by indicator isn't in a
released version yet. Linked sources are still listed under Synced with.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Restore existing burn-on-read and permission policy text

Recent edits removed text about restricting burn-on-read messages with a
permission policy, and rewrote the permission policy warning about
plugins, webhooks, slash commands and scheduled messages. That text was
already in the docs before these edits, so put it back as it was: the
burn-on-read permission and the setting it works with on the system-wide
policies page, the warning, the burn-on-read mentions on the ABAC
overview and channel access rules pages, and the end-user burn-on-read
section.

Label, version and typo fixes made to those pages since are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Restore existing attribute sync notes in Attribute Management

Recent edits removed or reworded notes in the Link an attribute to
AD/LDAP or SAML section that were already in the docs: Select and
Multiselect attributes keeping their type, sync-managed options, which
types keep their type when linked, the Managed by indicator, and values
cleared when the identity provider stops sending them. The note that an
attribute linked to an external source doesn't need options was removed
too. Put that text back as it was.

The correction that Ranked attributes change to Text and Hierarchical
attributes can't be linked is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Restore required channel attribute notes in the v12 changelog

The channel attributes entry in the v12.0 release notes said that users
are asked for required channel attributes when creating a channel, and
that the channels API refuses a channel missing a required value. Those
sentences were in the release notes before recent edits removed them, so
put them back. The entry's licensing wording is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* API docs: Correct access control policy schemas

The access control policy schema described fields the server never
had (display_name, description, a policy-level expression, is_active,
update_at, delete_at). It now matches the policy model: type, version,
roles, imports, scope and a rules array, with each rule's role,
actions, expression and auto_add metadata. The deprecated active
field is marked as such.

Also fix the related schemas: list and test responses return total,
the policy search accepts auto_add, actions, team_id and scope, the
expression error has no field property, the expression test and
visual AST requests take teamId, and the visual AST condition's
value_type is an integer with an attribute_type. Simulation results
gain the missing blame sources, merged_rules, the evaluation tree
node and the session id; use_active_session is marked as ignored.
The Action Search schemas list the supported resource type, actions
and denial reason. The fields autocomplete endpoint returns an array
of property fields, so its unused response schema is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* API docs: Document delegated access control permissions and parameters

The access control routes said "requires manage_system" almost
everywhere, but team admins and channel admins can call most of them
through team_id, teamId and channelId, which weren't documented either.
Each route now lists the permissions its handler checks and the
parameters it reads, with the minimum server version.

Also corrects several responses and conditions: the batch activate
endpoint returns an array and sets auto-add, the deprecated single
activate endpoint rejects cookie sessions, the channel attributes
response is a map of value arrays and is empty when channel access
indicators are off, the team policy response includes parent_policies,
policy search and simulation describe when they return 501, and Action
Search describes its real permission check and supported actions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* API docs: Document property field option routes and v12 property types

Add the property field options endpoints (list, create, update, delete)
with their option and page schemas, so large and hierarchical option
sets can be read and edited one option at a time.

Add the rank and graph field types, the session and system object
types, how fields with more than 1000 options are returned, and the
value shape for each field type. Note per-route minimum server
versions, license requirements, permissions, the value patch limits and
the access control group field limits, and correct the delta sync
boundary on the value routes, which is inclusive.

Document property_values on channel creation, which sets channel
attribute values when the channel is created.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* API docs: Deprecate custom profile attribute endpoints and fix their schemas

Mark every custom profile attributes endpoint as deprecated since v12.0,
pointing each one at its Properties API replacement. Document the 400
that field patch and delete return for fields linked to a global
attribute template, and how to create a linked attribute instead.

Fix the value shapes: the values endpoints take and return a map from
field ID to value (at most 50 entries), and listing a user's values
returns a map too; its response schema was also detached by its
indentation. Add the rank and graph field types, option rank and
parents, the managed attribute, the omitted-options markers, the
license requirement and the permission for setting another user's
values.

Declare the access control, properties, custom profile attributes and
permissions tags, so each gets a description and its own page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Plugin API docs: Correct minimum versions and document access control methods

The plugin access control methods first shipped in 11.11, the property
field option methods in 12.0, and HasPermissionToFileAction in 12.0
(with backports to 11.7.12, 11.10.3 and 11.11.1), so their minimum
server version tags now say so.

The godoc also now describes what plugin authors need to call these
methods correctly: the access_control group and the refused
custom_profile_attributes name, required field properties and field
types, value shapes per type, the no-policy decision and fail-closed
errors, plugin policy validation rules, what actingUserID is used for,
and a link to the access policy expression reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Add developer guides for the property system and plugin access control

Plugin authors had only the generated SDK reference for the property
system and attribute-based access control. Add two server plugin guides:
one on groups, fields, values, templates, options and the property
websocket events, with plugin API examples; and one on protecting
plugin-owned resources with access policies, checking decisions safely,
reusing the System Console rule editors in a web app plugin, and
respecting file upload and download policies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Reorganize attribute-based access control navigation

List the attribute-based access control pages in task order: define
user, channel and session attributes first, then system-wide, team and
channel policies, then the expression reference, with the page for the
User Attributes screen of releases before v12.0 last. The sidebar
comment now explains that order.

Also tidy a few pages found while checking the section:
- The ABAC overview links to the System Attributes settings reference.
- The session attributes operator table links to the expression
  reference.
- The legacy User attributes page shows the Entry, Enterprise and
  Enterprise Advanced badge, matching its license gate.
- The channel and team channel policy pages describe the attribute
  refresh interval as the delay before searches and rule tests see an
  attribute change, rather than a fixed refresh schedule.
- The server plugins overview links to the property system and plugin
  access control guides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Leave the v12 changelog and plugin API comments unchanged

Keep this change to the documentation pages and the REST API reference.
The v12 changelog and the plugin API comments go back to their current
text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Leave the important upgrade notes unchanged

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Leave the deprecated features page unchanged

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Mark custom property groups as deprecated

Tell plugin developers to put new attributes in a built-in group, and
that fields used in access control decisions must be in the
access_control group. Plugin-registered groups belong to version 1 of
the property system and are now described as deprecated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Address CodeRabbit review on ABAC and property docs

Align OpenAPI responses and tag text with existing endpoint docs, fix a
repeated word, list the missing permission in the policy steps, and nest
mmctl user attributes under mmctl user.

Co-authored-by: mattermost-code <matty-code@mattermost.com>

* Docs: Name the action decisions endpoint in the access control tag

Co-authored-by: mattermost-code <matty-code@mattermost.com>

* Docs: Address remaining CodeRabbit notes on ABAC and CPA docs

Document inherited auto-add, async policy sync, JSON null value
clearing, the 401 on PatchCPAValuesForUser, and which pre-v12
attributes are not linked.

Co-authored-by: mattermost-code <matty-code@mattermost.com>

* Docs: Address review feedback and trim API descriptions

Shorten the API descriptions this branch added. License requirements
are stated once in the properties and custom profile attributes tag
descriptions instead of on every endpoint, error conditions move into
the description of the response they produce, and operation
descriptions keep what a caller needs to make the request.

Document attrs.display_name and the access_control naming rules on
PropertyField, with the matching 422 on field create and patch. Clarify
which fields channel creation accepts in property_values. On the
end-user banners page, say that markings don't control access on their
own and that from v12.0 an access rule can restrict a channel by
classification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Fix CPA list replacement route and discovery-mode wording

The Properties API returns 400 for a user field list without a scope,
so the replacement for listing custom profile attribute fields now
includes target_type=system. The action decisions request schema now
says that an empty or omitted actions list both select discovery mode,
matching the endpoint description.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Generalize permission policies and drop window editor guidance

Describe file upload and download as one example of permission
policies, clarify that the policy editor methods run in the plugin's
server, and remove the section on the rule editors exported on
window.Components, which the web app marks as internal plugin use only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Docs: Address review feedback on ABAC docs

- Remove EnableUserManagedAttributes documentation
- Drop mid-page license notes covered by the plan label
- Describe channel permission rules generically instead of listing actions
- Clarify that OR-combined rules apply to channel permission rules

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: mattermost-code <matty-code@mattermost.com>
2026-11-06 12:23:34 -05:00

15 KiB

title, sidebar_position
title sidebar_position
Store custom data with the property system 20

The property system lets a plugin attach typed data to Mattermost objects without managing its own database tables. A plugin can define a "status" for posts, a "region" for channels, or any other attribute, and store a value for each object. Mattermost uses the same system for user attributes, channel attributes and the other attributes that attribute-based access control policies read.

This page explains the concepts and walks through the server plugin API. For the method reference, see the server plugin SDK reference.

Concepts

Groups

A group is a namespace for fields. Every field and value belongs to exactly one group, and most plugin API methods take the group's ID.

New attributes should use one of Mattermost's built-in groups, such as access_control. Get a built-in group with GetPropertyGroup.

The built-in access_control group (model.AccessControlPropertyGroupName) holds user attributes, Global Attribute templates and channel attributes, and it's the only group that access control policies read. A field that access control decisions depend on, such as an attribute used in an attribute-based access control policy, must be in the access_control group. Working with it needs a Mattermost Entry, Enterprise or Enterprise Advanced license. The old name custom_profile_attributes is refused by both RegisterPropertyGroup and GetPropertyGroup.

Custom groups (deprecated)

Custom groups are deprecated. They're part of version 1 of the property system, so don't create one for new fields. Existing custom groups keep working.

A plugin creates a custom group with RegisterPropertyGroup. Calling it again with the same name returns the existing group. Group names may contain only lowercase letters, digits and underscores, and must start with a letter or digit.

Custom groups are version 1 groups, which limits what they can do:

  • No REST access. The REST API's /api/v4/properties/groups/... routes serve only version 2 groups. A plugin's web app reads and writes its data through the plugin's own HTTP endpoints (ServeHTTP), not through the core REST API.
  • No object type. Fields in a version 1 group must leave ObjectType empty. A field with an ObjectType is refused.
  • Options live on the field. A field's options are read and written as part of the field, in Attrs["options"]. The option methods, such as GetPropertyFieldOptions, refuse fields in a version 1 group.
  • No field events. Changes to fields in a version 1 group don't send the property field websocket events. See React to changes.
  • Values aren't checked against the field. Mattermost stores any JSON value. The plugin decides what a valid value is.
  • No access control. Policies can't use fields in a custom group.

Fields

A field defines an attribute: its name, its type, and for some types the options a value can choose from. Name and Type are required. The types are:

Type Constant Holds
text model.PropertyFieldTypeText Free text
select model.PropertyFieldTypeSelect One option
multiselect model.PropertyFieldTypeMultiselect Several options
date model.PropertyFieldTypeDate A date
user model.PropertyFieldTypeUser One user
multiuser model.PropertyFieldTypeMultiuser Several users
rank model.PropertyFieldTypeRank One option, where the options have an order
graph model.PropertyFieldTypeGraph Several options, where the options form a hierarchy

Field names in a version 1 group are unique within the group and target ID, so GetPropertyFieldByName finds a field your plugin created earlier. Deleting a field is a soft delete.

Values

A value is one object's data for one field. A model.PropertyValue names the field (FieldID), the group (GroupID), and the object the value belongs to (TargetType and TargetID). An object holds at most one value per field, which is why UpsertPropertyValue can create or replace it.

Value is raw JSON. Mattermost's own convention, which it enforces in the access_control group, is:

Field type Value
text A string
select, rank An option ID
multiselect, graph An array of option IDs
user A user ID
multiuser An array of user IDs

Following the same convention in your own group keeps your data easy to read for anyone who knows the property system.

Object type and target type

In a version 2 group such as access_control, a field has two separate settings:

  • ObjectType says what kind of object the field's values belong to, such as user or channel. The special object type template marks a template (see the next section).
  • TargetType and TargetID say where the field is defined: system (with an empty TargetID), or a specific team or channel (with its ID as TargetID).

So a system-wide user attribute has ObjectType: "user" and TargetType: "system", and each user's value has TargetType: "user" and the user's ID as TargetID.

In your own version 1 group there's no object type. A field's TargetType and TargetID are free for your plugin to use; leave them empty for a field that applies everywhere. A value's TargetType is required, and its TargetID must be a Mattermost ID.

Templates and linked fields

In the access_control group, a template is a field with object type template that owns a type and a list of options. A user attribute or channel attribute links to a template through LinkedFieldID and inherits its type and options. The attributes an admin creates on the Attribute Management page are templates with linked user and channel attributes. See Attribute Management for how admins use them.

The rules for linked fields:

  • A linked field's type and options can't be changed. Change the template instead.
  • Set LinkedFieldID to an empty string to unlink a field.
  • A template can't be deleted while fields still link to it.

Options and hierarchies

select, multiselect, rank and graph fields have options. Each option has an id, a name and an optional color. When you create a field, list its options in Attrs["options"]; Mattermost assigns an ID to every option that doesn't have one.

In a graph field, each option can name the options directly above it in parents, by name. A hierarchical attribute such as an organization chart is a graph field. An option can have up to 100 parents, a hierarchy can be up to 100 levels deep, and a graph field can hold up to 100,000 options. A field can't be converted to or from graph. To learn how access rules use hierarchies, see Hierarchical attributes.

A field read lists at most 1,000 options in Attrs["options"]. A field with more has Attrs["options_omitted"] set to true and the number of options in Attrs["options_count"]. From Mattermost v12.0, read the options of such a field one page at a time with GetPropertyFieldOptions, and change them with CreatePropertyFieldOptions, UpdatePropertyFieldOptions and DeletePropertyFieldOptions. These methods work only on fields in version 2 groups such as access_control.

Use the plugin API

The examples call p.API directly. If your plugin uses the pluginapi client, client.Property has the same methods with the same signatures.

The basic property methods need Mattermost v10.10 or later; the search and count methods need v11.0, and the option methods need v12.0. Set min_server_version in your plugin manifest to match what you use.

Register a group and create a field

Register the group and make sure your fields exist when the plugin activates. This example creates a select field for a status that the plugin stores on posts:

package main

import (
	"encoding/json"
	"fmt"

	"github.com/mattermost/mattermost/server/public/model"
	"github.com/mattermost/mattermost/server/public/plugin"
)

type Plugin struct {
	plugin.MattermostPlugin

	groupID     string
	statusField *model.PropertyField
}

func (p *Plugin) OnActivate() error {
	group, err := p.API.RegisterPropertyGroup("tasks_plugin")
	if err != nil {
		return fmt.Errorf("failed to register property group: %w", err)
	}
	p.groupID = group.ID

	// Reuse the field if an earlier activation created it.
	field, err := p.API.GetPropertyFieldByName(group.ID, "", "status")
	if err != nil {
		field, err = p.API.CreatePropertyField(&model.PropertyField{
			GroupID: group.ID,
			Name:    "status",
			Type:    model.PropertyFieldTypeSelect,
			Attrs: model.StringInterface{
				model.PropertyFieldAttributeOptions: []any{
					map[string]any{"name": "Open"},
					map[string]any{"name": "Done"},
				},
			},
		})
		if err != nil {
			return fmt.Errorf("failed to create status field: %w", err)
		}
	}
	p.statusField = field

	return nil
}

Leave ID empty when you create a field; Mattermost assigns it.

Set and read values

To store a value, find the option ID and upsert the value for the post:

// optionID returns the ID of the field's option with the given name.
func optionID(field *model.PropertyField, name string) (string, error) {
	raw, err := json.Marshal(field.Attrs[model.PropertyFieldAttributeOptions])
	if err != nil {
		return "", err
	}
	var options []model.PropertyFieldOption
	if err := json.Unmarshal(raw, &options); err != nil {
		return "", err
	}
	for _, option := range options {
		if option.Name == name {
			return option.ID, nil
		}
	}
	return "", fmt.Errorf("field %s has no option %q", field.Name, name)
}

func (p *Plugin) setStatus(postID, status string) error {
	id, err := optionID(p.statusField, status)
	if err != nil {
		return err
	}
	value, err := json.Marshal(id)
	if err != nil {
		return err
	}

	_, err = p.API.UpsertPropertyValue(&model.PropertyValue{
		GroupID:    p.groupID,
		FieldID:    p.statusField.ID,
		TargetType: "post",
		TargetID:   postID,
		Value:      value,
	})
	return err
}

To read values, search by target. PerPage is required:

func (p *Plugin) getStatusOptionID(postID string) (string, error) {
	values, err := p.API.SearchPropertyValues(p.groupID, model.PropertyValueSearchOpts{
		TargetIDs: []string{postID},
		FieldID:   p.statusField.ID,
		PerPage:   1,
	})
	if err != nil {
		return "", err
	}
	if len(values) == 0 {
		return "", nil // no status set
	}

	var id string
	if err := json.Unmarshal(values[0].Value, &id); err != nil {
		return "", err
	}
	return id, nil
}

To write several values in one call, use UpsertPropertyValues. All the values in a call must belong to the same group, and each field can appear only once. To remove data when an object goes away, use DeletePropertyValuesForTarget.

Page through options

GetPropertyFieldOptions reads a field's options one page at a time, ordered by creation time. It's the way to read a large option list, such as a big hierarchy in the access_control group. Each page can hold up to 200 options. For the first page, pass a zero cursor; then pass the cursor from the page you just read, and keep going while HasMore is true. Don't stop on a short page: a page can hold fewer options than you asked for even when more follow.

func (p *Plugin) listOptions(groupID, fieldID string) ([]*model.PropertyFieldOption, error) {
	var all []*model.PropertyFieldOption
	var cursorCreateAt int64
	var cursorID string

	for {
		page, err := p.API.GetPropertyFieldOptions(groupID, fieldID, cursorCreateAt, cursorID, 200)
		if err != nil {
			return nil, err
		}
		all = append(all, page.Options...)
		if !page.HasMore {
			return all, nil
		}
		cursorCreateAt, cursorID = page.NextCursorCreateAt, page.NextCursorID
	}
}

Each option on a page has its ID, Name and Color. In a graph field, Parents lists the names of the options directly above it. Options that a linked field inherits from its template are marked ReadOnly.

The write methods take up to 200 options per call, and each call succeeds or fails as a whole:

  • CreatePropertyFieldOptions adds options. Don't set ID; Mattermost assigns it. Parents can name options already in the field or options in the same call, so you can build a hierarchy in one call.
  • UpdatePropertyFieldOptions changes options, each identified by ID. Anything you leave out stays as it was; Parents, when given, replaces the option's parents.
  • DeletePropertyFieldOptions removes options by ID. You can't remove an option that still has options below it unless you remove those too. Values that name a removed option are left as they are; the removed option is ignored wherever it's read.

React to changes

There are no server plugin hooks for property changes.

A web app plugin can listen to the websocket events that Mattermost sends when fields and values in version 2 groups change, with registerWebSocketEventHandler:

Event Data
property_field_created property_field: the field, as a JSON string. object_type: the field's object type.
property_field_updated Same as property_field_created.
property_field_deleted field_id, object_type
property_values_updated object_type, target_id, and values: the changed values, as a JSON string. When all of a field's values are deleted at once, the event has field_id and an empty values list instead.

Field events are sent whenever a field in a version 2 group changes, to the team or channel the field is defined for, or to everyone for a system field. They aren't sent for fields in version 1 groups. property_values_updated is sent for value changes made through the REST API and by Mattermost itself, and when values are deleted; creating or updating values through the plugin API doesn't send it. If your web app needs to know about changes your server plugin makes, send your own event with PublishWebSocketEvent.

Treat an event as a signal to refresh: read the field or values again to get what the current user is allowed to see.

Use the REST API

The REST API works with version 2 groups such as access_control. See the properties endpoints in the API reference. The custom profile attributes endpoints are deprecated; use the properties endpoints in the access_control group instead.