Allura is implemented as a collection of tool applications on top of a robust and open platform. Some of the services provided by the platform include:
Tools, on the other hand, provide the actual user interface and logic to manipulate forge artifacts. Some of the tools currently implemented include:
The TurboGears "context" object c has several properties which are automatically set for each request:
Allura platform provides the following functions to manage the context object, if you need to change the context for some situation:
We've mentioned artifacts a couple of times now without definition. An artifact, as used in Allura, is some object that a tool needs to store in the forge. The platform provides facilities for controlling access to individual artifacts if that's what the tool designer favors. For instance, the Discussion tool allows a user to edit or delete their own posts, but not to edit or delete others (unless the user has the 'moderate' permission on the forum itself). Some examples of artifacts in the current tools:
In order to implement your own artifact, you should override at least a few of the methods of the allura.model.artifact.Artifact class:
from ming.odm.property import FieldProperty from allura.model import Artifact class NewArtifact(Artifact): class __mongometa__: name='my_new_artifact' # collection where this artifact is stored type_s = 'My Artifact' # 'type' of the artifact used in search results # Add your own properties here (beyond those provided by Artifact) shortname = FieldProperty(str) def url(self): 'Each artifact should have its own URL ' return self.app.url + self.shortname + '/' def index(self): 'Return the fields you want indexed on this artifact' result = Artifact.index(self) result.update(type_s=self.type_s, name_s=self.shortname, text=self.shortname) return result def shorthand_id(self): 'Used in the generation of short links like [my_artifact]' return self.shortname
Whenever you create, modify, or delete an artifact, the platform does a couple of things for you:
Shortlinks work only within a project hierarchy (in order to link to some other project's page, you'll have to use the full URL). Sometimes, a shortlink may need to be differentiated based on its location in a subproject or in one of many tools of the same type within a project. In order to do this, shortlinks may be prefixed by either the tool mount point or a project ID and tool mount point.
For instance, suppose we have an ticket tracker called 'features' and one called 'bugs'. They both have many tickets in them. To distinguish, use the tracker mount point within the reference. For example [features:#3] or [bugs:#3]
Much of the actual functionality of Allura comes from code that runs outside the context of a web request, in the taskd server (invoked by running :command:`paster taskd development.ini`). Asynchronous processing is performed by two types of functions, tasks and events, differentiated as follows:
Tasks are module-level global functions. They are annotated with the @task decorator and are invoked with the .post method. For instance, to schedule a task foobar to execute in the taskd context, you would write:
@task def foobar(a,b,c=5): ... foobar.post(9,1,c=15)
Events are intended for "fan-out" types of events. Events have a string name, and are "listened" for by using the @event_handler decorator. The g.post_event() helper is provided to run the event handlers for a particular event in the taskd context. Multiple event handlers can be registered for each event:
@event_handler('event_name') def handler1(topic, *args, **kwargs): ... @event_handler('event_name') def handler2(topic, *args, **kwargs): ... g.post_event('event_name', 1,2,3, a=5)
The Allura platform provides easy-to-use email integration. Forge email addresses are of the form :samp:`<topic>@<mount_point>[.<subproject>].<project>.mysite.com`. When a message is received on such an email address, the address is parsed and the sending user is identified (if possible). Based on the parsed address, the TurboGears context attributes c.project and c.app are set, and the application is queried to determine whether the identified user has authority to send an email to the given app/topic combination by calling c.app.has_access(user, topic). If the user has access, the message is decomposed into its component parts (if a multipart MIME-encoded message) and c.app.handle_message(topic, message) is called for each part with the following components to the msg dict:
The Allura platform also provides full support for sending email without worrying about the specifics of SMTP or sendmail handling. In order to send an email, simply post a task for allura.tasks.mail_tasks.sendmail with the following arguments: