Hobo Tip: Define view_permitted so anyone can create but only some can view

Hobo is just great, so I’m going to publish a few tips I encounter from time to time.

In this case I want to set permissions in a way that anyone can create a user, but only some can view them. “self.id == nil” made the trick:

  def view_permitted?(field)
    user_is?(acting_user) || acting_user.administrator? || self.id == nil
  end

Thanks to https://groups.google.com/forum/?fromgroups#!searchin/hobousers/view_permitted/hobousers/DNZvWk80Mcs/EhuY4IEjYQgJ

More info about permissions in http://cookbook.hobocentral.net/manual/permissions

Update: Kevin improved the code a bit:

  def view_permitted?(field)
    return true if user_is? acting_user
    return true if acting_user.administrator
    return true if new_record?
  end

Post a comment.