forked from bryanlarsen/agility-gitorial-patches
-
Notifications
You must be signed in to change notification settings - Fork 1
/
51-generate-project-membership.patch
114 lines (108 loc) · 3.45 KB
/
51-generate-project-membership.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
generate-project-membership
From: Bryan Larsen <[email protected]>
# 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
---
app/controllers/project_memberships_controller.rb | 7 +++++
app/models/project_membership.rb | 28 ++++++++++++++++++++
test/fixtures/project_memberships.yml | 11 ++++++++
.../project_memberships_controller_test.rb | 7 +++++
test/unit/project_membership_test.rb | 7 +++++
5 files changed, 60 insertions(+)
create mode 100644 app/controllers/project_memberships_controller.rb
create mode 100644 app/models/project_membership.rb
create mode 100644 test/fixtures/project_memberships.yml
create mode 100644 test/functional/project_memberships_controller_test.rb
create mode 100644 test/unit/project_membership_test.rb
diff --git a/app/controllers/project_memberships_controller.rb b/app/controllers/project_memberships_controller.rb
new file mode 100644
index 0000000..aa14a80
--- /dev/null
+++ b/app/controllers/project_memberships_controller.rb
@@ -0,0 +1,7 @@
+class ProjectMembershipsController < ApplicationController
+
+ hobo_model_controller
+
+ auto_actions :all
+
+end
diff --git a/app/models/project_membership.rb b/app/models/project_membership.rb
new file mode 100644
index 0000000..982242c
--- /dev/null
+++ b/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
diff --git a/test/fixtures/project_memberships.yml b/test/fixtures/project_memberships.yml
new file mode 100644
index 0000000..c63aac0
--- /dev/null
+++ b/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
diff --git a/test/functional/project_memberships_controller_test.rb b/test/functional/project_memberships_controller_test.rb
new file mode 100644
index 0000000..03ed478
--- /dev/null
+++ b/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
diff --git a/test/unit/project_membership_test.rb b/test/unit/project_membership_test.rb
new file mode 100644
index 0000000..82a2274
--- /dev/null
+++ b/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