Category Archives: Uncategorized

0.4 and a new rebuilt

Station is to be rebuilt. After several years of building, the engine is a little big monster doing several things, sometimes pretty well, other times good enough or too much complicated.

At this time, several good plugins have appeared in Rails supporting authentication and authorization. Rails 3.0 is just around the corner. These plugins go in the same way of Station and already support Rails 3.0. In addition, we have started a refactorization of the Virtual Conference Center towards social networking.

So I think is time for a pruning. Delegation authentication and authorization on those plugins and focusing in social networking. The next version of Station will be built on Rails 3 and it will be focused on Activity Streams.

In the meantime, Station 0.4 is released. Several months of development with a lot of bug fixes and a bunch of new features, incluing:

  • Merge of Categories and Tags. Station 0.4 supports tags only.
  • Ability to initialize Resources with params in the query part of the URL: something like /posts/new?post[text]=Init+text will do what you expect
  • New SingularAgent: CronAgent.  Suitable for contents generated from cron tasks.
  • New rake tasks:
    • station:attachment_fu:db2file: Switch from database storage to filesystem storage and so on.
    • station:icons:oxygen:copy: Automate using Oxygen icons in your application
  • New method path_container: look up in all params to find a suitable container for a resource
  • Improved Content::Inquirer
  • Authorization delegate: rely authorization in a relation, for example from a post to its forum.
  • HTML inspection: special support for analysis of semantic in HTML documents, in order to extract data from user’s OpenID and personal web page. Switch to nokogiri/prism. This work comes from the OpenID Observatory project.

Introspecting Uris HTML

I have been working on the support for discovering several kinds of services and resources in HTML. This is part of a short research project we’ll hopefully launch soon.

Station now provides support for discovering this type of services:

Containers in the path

Coinciding with the submission of a paper for the ws://rest.2010, several controller methods have been refactorized.

We have made an intensive analysis of use cases of containers in the path, in cases like:


/spaces/global/events/meeting/agenda

/groups/3/tasks/4/turns

The following methods are now supported:

path_containers will return an array of all the containers in the path. In the last examples, well get [ spaces-global, events-meeting ] and [ groups-3, tasks-4 ]
current_container will search for a container both in path containers, as well as in the containers of current resource. Consider this example:


/spaces/global/events/meeting/agenda/agenda_entries/2
/events/meetings/agenda_entries/2
/agenda_entries/2

current_container(:type => :space) #=> returns space-global in all the former cases

Station 0.3

A new stable version of Rails Station is available. The Content Management System Engine reaches its 0.3 version. Although much work is still pending until the 1.0 release, the engine already provides much functionality. Furthermore, Station is the core of a couple of production websites, including the Virtual Conference Center

The major features of this release are:

There also are a bunch of minor features and fixes, which include:

  • Activate an Agent when resetting his password. Now a user can activate the account and reset the password simultaneously.
  • The Stage has a new method role(name) to find the roles easier.
  • ActionMailer is configured with the Site.current.domain automagically
  • vendor/plugins/station/app path is reloadable
  • Performance comes with two callbacks; avoid_downgrading_only_one_with_highest_role and avoid_destroying_only_one_with_highest_role. These will avoid the admin of a Stage leaves it without assigning a new admin first.

There is also included a database migration template for upgrading from version 0.2 to 0.3. It can be found at vendor/plugins/station/db/migrate/station_2_to_3.rb

Find installation instructions in Rails Station Homepage

New Authorization Framework

These days I’ve working in a new Authorization Framework for Rails Station.

After trying with ACLs and suffering from some scalability issues, the final version seems to be stable.

Like previous versions, you can protect your controller actions using authorization_filter

class PostsController
  authorization_filter :read, :post, :only => [ :show ]
end

Authorization is defined in each  model using authorizing declarations:

class Post
  authorizing do |user, permission|
    # Allow all actions to the author of the Post
    if user == agent
      true
    end
  end
end

You can define and chain all the authorizing declarations you need. These declarations build an authorization chain, which is evaluated from the first one until one of the declarations returns true or false.

This is the response you get when calling:

post.authorize? :read, :to => user

Station comes with two default declarations:

  • When a model acts_as_stage, the authorization queries will look for the permissions of the role the user is playing in the Stage
  • When a model acts_as_content, the authorization will query the Container

You can check the documentation for more information about authorization in Station

Admissions: Invitations and Join Requests

One of the new major features of Station 0.3 is Admissions.

Admissions gather the proccess of joining a Stage. There are two classes of Admissions:

  • Invitations: The new participant is contacted by email, providing a link where s/he can accept or deny the invitation. The role the new participant is playing in the Stage is preset in the Invitation request
  • Join Requests: The new participant requests the Stage admins s/he wants to participate in the Stage. The admins accept or deny the request.

Admissions basic support is already included in master and will be part of Station 0.3

Import Feeds to your Containers

Station provides basic (and still in development) support for Atom/RSS feeds. You can import feeds to your Containers and create new Contents from each Atom/RSS element.

A Container is any model that give context to other models. Lets take the following example:

class Space
  has_many :posts
end

The has_many relation indicates Space is probably a Container.  If a posts always belongs_to a space, then you have it. Space is a Container.

Station provides an easy way to import feeds to your Containers. This is achieved by the Sources support.

Add the sources table to your database.
The sources table is defined in station/db/migrate/station_2_to_3.rb and will be included in the next version of the Station migration schema.

Indicate Station that your Space is a Container and it supports Sources.

Just add the suitable option to the container declaration:

class Space
  has_many :posts
  acts_as_container :sources => true
end

Write the Atom Parser in your models

You’ll have to describe the conversion between the source feed elements and your models. This is easily achieved using the params_from_atom function


class Posts
  def self.params_from_atom(entry)
    { :title => entry.title.to_s,
       :text => entry.content.to_s }
  end
end

And that’s it! Now you can visit /spaces/1/sources and automatically add new Posts to your Spaces.

Named_scope clashing with ActiveSupport

One of the named_scope defined by Station was parents. It simply scoped searches in Resources to records that haven’t a parent_id defined. This is useful for Posts or AttachmentFu records (which makes thumbnails with the parent_id).

The name “parents” was unfortunate, as it clashes with a method in ActiveSupport::CoreExtensions::Module

So the named_scope has been renamed to “parent_scoped“. You are encourage to upgrade to the new stable version, Station 0.2.3

Getting several AR objects in one query: ActiveRecord::Content::Inquirer

There are some issues already included in Station I want to blog, because I think they are interesting.
One of them is ActiveRecord::Content::Inquirer

In Station, a container is an ActiveRecord model that have many contents, like posts, images, videos, bookmarks, etc.. What if you want to obtain all the contents in a Container using just one SQL query? And you also want to paginate them? And, of course, getting back instances of every Content!

ActiveRecord::Content::Inquirer does just this. You use it:


ActiveRecord::Content::Inquirer.all :container => somespace,
                                    :page => params[:page],
                                    :per_page => 10

It even accepts an Array in :container.

Some of the magic is under this hack:


class Inquirer < ActiveRecord::Base
  @colums = Array.new
  @columns_hash = { "type" => :fake }


  ...
end

This way, it’s possible to use ActiveRecord::Base goodies without a real table in the database.

Initializing…

I’ve opened this blog to write about Rails Station development.

Station is a Rails Engine (a plugin with app/, routes and more) focused on Content Management. Station provides your Rails application with a CMS framework, this means authentication, authorization, categories, tags, etc…

This development is part of the work in my Ph.D thesis, which is about distributed social software, so I plan to add more features following that way.