|
@@ -1,21 +1,27 @@
|
|
1
|
+# Provides read-only access to Activities.
|
1
|
2
|
class Api::ActivitiesController < ApiController
|
2
|
|
- before_action :set_activity, only: [:show, :response_summary]
|
3
|
|
- before_action :require_membership!, only: [:show, :reponse_summary]
|
4
|
|
- before_action :api_require_admin!, only: [:index]
|
|
3
|
+ has_no_activity = [:index]
|
|
4
|
+
|
|
5
|
+ # Session-based authentication/authorization
|
|
6
|
+ before_action :set_activity, except: has_no_activity
|
|
7
|
+ before_action :require_membership!, except: has_no_activity
|
|
8
|
+ before_action :api_require_admin!, only: has_no_activity
|
|
9
|
+ skip_before_action :api_require_authentication!, :set_activity, :require_membership!, if: 'request.authorization'
|
|
10
|
+
|
|
11
|
+ # Group API-key-based authentication/authorization
|
|
12
|
+ before_action :api_auth_group_token, if: 'request.authorization'
|
|
13
|
+ before_action :set_activity_from_group, if: 'request.authorization'
|
5
|
14
|
|
6
|
15
|
# GET /api/activities
|
7
|
|
- # GET /api/activities.json
|
8
|
16
|
def index
|
9
|
17
|
@activities = Activity.all
|
10
|
18
|
end
|
11
|
19
|
|
12
|
20
|
# GET /api/activities/1
|
13
|
|
- # GET /api/activities/1.json
|
14
|
21
|
def show
|
15
|
22
|
end
|
16
|
23
|
|
17
|
24
|
# GET /api/activities/1/response_summary
|
18
|
|
- # GET /api/activities/1/response_summary.json
|
19
|
25
|
def response_summary
|
20
|
26
|
as = @activity
|
21
|
27
|
.participants
|
|
@@ -78,9 +84,16 @@ class Api::ActivitiesController < ApiController
|
78
|
84
|
end
|
79
|
85
|
|
80
|
86
|
private
|
81
|
|
- # Use callbacks to share common setup or constraints between actions.
|
82
|
|
- def set_activity
|
83
|
|
- @activity = Activity.find(params[:id])
|
84
|
|
- @group = @activity.group
|
85
|
|
- end
|
|
87
|
+
|
|
88
|
+ # Set activity from the :id-parameter
|
|
89
|
+ def set_activity
|
|
90
|
+ @activity = Activity.find(params[:id])
|
|
91
|
+ @group = @activity.group
|
|
92
|
+ end
|
|
93
|
+
|
|
94
|
+ # Set activity from the :id-parameter, and assert that it belongs to the set @group.
|
|
95
|
+ def set_activity_from_group
|
|
96
|
+ @activity = Activity.find(params[:id])
|
|
97
|
+ head :unauthorized unless @activity.group == @group
|
|
98
|
+ end
|
86
|
99
|
end
|