# link\_policy

Source: https://zotonic.com/docs/3204/link_policy

URI: https://zotonic.com/id/3204

Language: en



Link policy for editors and site configuration.

`m.link_policy.editor[id]` returns policy for a visible resource; approval controls also require resource edit and property update permission. `editor` without an id returns policy for a new resource (normal insert ACLs still apply on save). `nofollow` and `noreferrer` expose the public site defaults, both true when unset.

For example, retrieve approval controls for the resource being edited:

```django
{% with m.link_policy.editor[id] as policy %}
    {% if policy.can_approve %}
        <p>{_ You can approve external URLs for this page. _}</p>
    {% endif %}
{% endwith %}
```

The editor policy is a map with these fields:

| Field         | Value                                                                            |
| ------------- | -------------------------------------------------------------------------------- |
| `id`          | Resource id, or `undefined` for a new resource.                                  |
| `can_approve` | Whether the current user may change URL approvals. New resources still require insert permission when saved. |
| `urls`        | List of approved, unescaped URL binaries; empty for a new resource.              |
| `hosts`       | Site hostname and host aliases for editor URL classification.                    |
| `nofollow`    | Boolean default for new external links inserted by eligible editors.             |
| `noreferrer`  | Boolean indicating whether external links suppress referrer information.         |

The model returns `enoent` for an unknown resource, `eacces` for an invisible resource, and `unknown_path` for an unsupported model path. The default-setting paths `m.link_policy.nofollow` and `m.link_policy.noreferrer` are public.

`site.link_nofollow` is a new-link default only for users with approval rights (normally `use.mod_admin`, plus permission to edit the resource). For these editors, true means the follow checkbox is unchecked after entering a new external URL; false means checked. They can override this choice per URL. An empty-URL dialog initially shows the checkbox checked; entering a URL recalculates it. Existing external links reflect their stored URL approval.

Users without approval rights see status but no checkbox. Their unapproved external URLs always receive nofollow, regardless of the configured default; existing resource approvals remain effective. `site.link_noreferrer` applies to all users independently of approval and defaults to true.

There are no model write routes: approvals are saved with normal resource updates.

`resanitize/2` re-applies current settings to an editable resource's stored HTML. Configuration changes do not rewrite historical content automatically. To migrate existing resources, call this function for the desired ids with an authorized context. It preserves the resource allow-list and checks ordinary update ACLs. This is a direct Erlang API, not a model write path:

```erlang
m_link_policy:resanitize(Id, Context).
```

It returns `{ok, Id}` or an error from the resource update, such as `{error, eacces}` when the context lacks the required permissions.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/3204?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/3204?language=en>)
