Edgewall Software

Changes between Initial Version and Version 1 of TracDev/PluginDevelopment/ExtensionPoints/trac.attachment.ILegacyAttachmentPolicyDelegate


Ignore:
Timestamp:
Jul 15, 2012, 1:23:02 PM (12 years ago)
Author:
Peter Suter
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/PluginDevelopment/ExtensionPoints/trac.attachment.ILegacyAttachmentPolicyDelegate

    v1 v1  
     1== Extension Point : ''ILegacyAttachmentPolicyDelegate'' ==
     2
     3||'''Interface'''||''ILegacyAttachmentPolicyDelegate''||'''Since'''||[wiki:TracDev/ApiChanges/0.11#ILegacyAttachmentDelegate 0.11]||
     4||'''Module'''||''trac.attachment''||'''Source'''||[source:trunk/trac/attachment.py#/ILegacyAttachmentPolicyDelegate attachment.py]||
     5
     6The ''ILegacyAttachmentPolicyDelegate'' implementations define how to check for `ATTACHMENT_*` permissions for different realms.
     7
     8== Purpose ==
     9
     10The TracPermissions system defines coarse permissions to control which users have access to which modules. TracFineGrainedPermissions introduced more fine grained control over permissions for individual resources. The [wiki:trac.perm.IPermissionPolicy IPermissionPolicy] interface is used to implement this new system, re-implement the legacy behavior and allow plugins to extend the permission policies.
     11
     12Attachment permissions are not really separate permissions and can not e.g. be specified in the Admin interface. `LegacyAttachmentPolicy` (a `IPermissionPolicy` implementation) handles the legacy attachment permissions `ATTACHMENT_CREATE`, `ATTACHMENT_VIEW` and `ATTACHMENT_DELETE`. For the ''ticket'', ''wiki'' and ''milestone'' realms, it maps them directly to `TICKET_*`, `WIKI_*` and `MILESTONE_*` permissions on the parent resource. Attachments are child resources, and this delegates attachment permissions to their parent resources'. (E.g., if a user has the permission to modify a page, that user can also attach a file; permission to delete a page also gives permission to delete an attachment, etc.)
     13
     14Plugins that implement other resource realms and also support attachments can implement the `ILegacyAttachmentPolicyDelegate` interface. This allows extending `LegacyAttachmentPolicy` with similar mappings.
     15
     16== Usage ==
     17
     18Implementing the interface follows the standard guidelines found in [wiki:TracDev/ComponentArchitecture] and of course [wiki:TracDev/PluginDevelopment].
     19
     20`ILegacyAttachmentPolicyDelegate` implementations are only used if the `LegacyAttachmentPolicy` is listed in the ''permission_policies'' configured in [wiki:TracIni#trac-section trac.ini].
     21
     22These policies are called for user actions on a attachments. They can explicitly allow or deny these action, or abstain to defer the check to the next policy in the chain. For attachments to realms other than ''ticket'', ''wiki'' or ''milestone'', the `LegacyAttachmentPolicy` will defer to `ILegacyAttachmentPolicyDelegate` implementations.
     23
     24== Examples ==
     25
     26A minimal ILegacyAttachmentPolicyDelegate in isolation is not very useful (but possible) and usually accompanied by implementations of other interfaces that request and require these permissions. Hence the following example is best understood in context of the ComponentModuleExamples.
     27
     28In Trac components have no attachments. One could extend the ComponentModuleExamples to implement support for such attachments. The following example maps attachment permissions to component and ticket admin permissions:
     29
     30{{{#!python
     31from trac.core import Component, implements
     32from trac.perm import ILegacyAttachmentPolicyDelegate
     33
     34class ComponentModule(Component):
     35    implements(ILegacyAttachmentPolicyDelegate)
     36
     37    def check_attachment_permission(self, action, username, resource, perm):
     38        if resource.parent.realm == 'component':
     39            if action == 'ATTACHMENT_VIEW':
     40                return 'COMPONENT_VIEW' in perm(resource.parent)
     41            elif action in ('ATTACHMENT_CREATE','ATTACHMENT_DELETE'):
     42                return 'TICKET_ADMIN' in perm(resource.parent)
     43}}}
     44
     45== Available Implementations ==
     46
     47||= Plugin =||= maps attachment permissions to =||= for attachments to resources of realm =||= Notes =||
     48|| [https://malept.com/projects/trac-atompub.html AtomPub Plugin] || `ATOM_*` || `atompub` || ||
     49|| [bitten:WikiStart Bitten] || `BUILD_*` || `build` || ||
     50|| th:ExoWebCodeReviewPlugin || `CODE_REVIEW_*` || `CodeReview` || ||
     51|| th:FullBlogPlugin || `BLOG_*` || `blog` || Performs some additional logic. ||
     52|| [https://code.google.com/p/tracmailarchiveextplugin/ MailArchiveExtPlugin] || `MAILARCHIVE_*` || `mailarchive` || ||
     53|| [https://www.coderesort.com/p/open/wiki/TracTalkPlugin TracTalkPlugin] || `TALK_*` || `talk` || ||
     54|| [https://code.google.com/p/trac-testmanagement-plugin/ trac-testmanagement-plugin] || `TEST_*` || `test` || ||
     55|| th:ExtendedVersionPlugin || `VERSION_*` || `version` || ||
     56|| th:DiscussionPlugin || `DISCUSSION_ATTACH` || `discussion` || ||
     57
     58== Additional Information and References ==
     59
     60 * [http://www.edgewall.org/docs/trac-trunk/epydoc/trac.attachment.ILegacyAttachmentPolicyDelegate-class.html epydoc]
     61 * [http://www.edgewall.org/docs/trac-trunk/html/api/trac_attachment.html#trac.attachment.ILegacyAttachmentPolicyDelegate API Reference]
     62 * See [wiki:trac.perm.IPermissionPolicy IPermissionPolicy]
     63 * Initial development: [Trac-Dev:2783 mailing list archive]
     64 * Related tickets:
     65  * [query:status!=closed&component=attachment attachment component]
     66 * This interface is sometimes referred to as `ILegacyAttachmentDelegate` by mistake.
     67 * Why ''Legacy''?
     68   * The idea was that this mechanism would no longer be necessary once it becomes easier to setup fine-grained permissions in the default permission store.