Skip to content

Commit

Permalink
generate-project-membership
Browse files Browse the repository at this point in the history
# Granting read access to others

Now that we've got users owning their own projects, it seems wrong that any signed-up user can view any project. On the other hand it wouldn't make any sense to hide the project from everyone. What we need is a way for the project owner to grant others access.

We can model this with a ProjectMembership model that represents access for a specific user and project:

    $ hobo generate resource project_membership
  • Loading branch information
bryanlarsen authored and iox committed Aug 12, 2013
1 parent b060468 commit 22555ba
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/project_memberships_controller.rb
@@ -0,0 +1,7 @@
class ProjectMembershipsController < ApplicationController

hobo_model_controller

auto_actions :all

end
28 changes: 28 additions & 0 deletions app/models/project_membership.rb
@@ -0,0 +1,28 @@
class ProjectMembership < ActiveRecord::Base

hobo_model # Don't put anything above this

fields do
timestamps
end
attr_accessible

# --- Permissions --- #

def create_permitted?
acting_user.administrator?
end

def update_permitted?
acting_user.administrator?
end

def destroy_permitted?
acting_user.administrator?
end

def view_permitted?(field)
true
end

end
11 changes: 11 additions & 0 deletions test/fixtures/project_memberships.yml
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
7 changes: 7 additions & 0 deletions test/functional/project_memberships_controller_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class ProjectMembershipsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/unit/project_membership_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class ProjectMembershipTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 22555ba

Please sign in to comment.