-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Citizen science #381
Citizen science #381
Changes from all commits
db591f9
5bc312d
48f9947
745cc76
04b2d4a
6b48333
b960810
c41f5f0
ac9cf09
e6ae20d
b037115
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
class QuestionsController < ApplicationController | ||
|
||
include Api::ControllerHelper | ||
|
||
#skip_authorization_check | ||
|
||
# GET /questions | ||
# GET /studies/:study_id/questions | ||
def index | ||
do_authorize_class | ||
|
||
query = Question.all | ||
|
||
if params[:study_id] | ||
# todo: | ||
# check if this can be done better. We shouln't need to join | ||
# all the way to study, only to the join table. | ||
query = query.belonging_to_study(params[:study_id]) | ||
end | ||
|
||
@questions, opts = Settings.api_response.response_advanced( | ||
api_filter_params, | ||
query, | ||
Question, | ||
Question.filter_settings | ||
) | ||
respond_index(opts) | ||
end | ||
|
||
# GET /questions/:id | ||
def show | ||
do_load_resource | ||
do_authorize_instance | ||
respond_show | ||
end | ||
|
||
# GET /questions/filter | ||
def filter | ||
do_authorize_class | ||
|
||
filter_response, opts = Settings.api_response.response_advanced( | ||
api_filter_params, | ||
Question.all, | ||
Question, | ||
Question.filter_settings | ||
) | ||
respond_filter(filter_response, opts) | ||
end | ||
|
||
# GET /questions/new | ||
def new | ||
do_new_resource | ||
do_set_attributes | ||
do_authorize_instance | ||
respond_show | ||
end | ||
|
||
# POST /questions | ||
def create | ||
do_new_resource | ||
do_set_attributes(question_params) | ||
do_authorize_instance | ||
|
||
if @question.save | ||
respond_create_success(question_path(@question)) | ||
else | ||
respond_change_fail | ||
end | ||
end | ||
|
||
# PUT /questions/:id | ||
def update | ||
do_load_resource | ||
do_authorize_instance | ||
|
||
if @question.update_attributes(question_params) | ||
respond_show | ||
else | ||
respond_change_fail | ||
end | ||
end | ||
|
||
# DELETE /questions/:id | ||
def destroy | ||
do_load_resource | ||
do_authorize_instance | ||
@question.destroy | ||
respond_destroy | ||
end | ||
|
||
private | ||
|
||
def question_params | ||
# empty array is replaced with nil by rails. Revert to empty array | ||
# to avoid errors with strong parameters | ||
# https://github.com/rails/rails/issues/13766 | ||
if params.has_key?(:question) and params[:question].has_key?(:study_ids) and params[:question][:study_ids].nil? | ||
params[:question][:study_ids] = [] | ||
end | ||
permitted = [{study_ids: []}, :text, :data] | ||
params.require(:question).permit(permitted) | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
class ResponsesController < ApplicationController | ||
|
||
include Api::ControllerHelper | ||
|
||
# GET /responses | ||
# GET /studies/:study_id/responses | ||
def index | ||
do_authorize_class | ||
|
||
@responses, opts = Settings.api_response.response_advanced( | ||
api_filter_params, | ||
Access::ByPermission.responses(current_user, params[:study_id]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if You special-cased it in the Questions controller There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was only a problem in questions because it was an array (due to HABTM). |
||
Response, | ||
Response.filter_settings | ||
) | ||
respond_index(opts) | ||
end | ||
|
||
# GET /responses/:id | ||
def show | ||
do_load_resource | ||
do_authorize_instance | ||
respond_show | ||
end | ||
|
||
# GET /responses/filter | ||
def filter | ||
do_authorize_class | ||
|
||
filter_response, opts = Settings.api_response.response_advanced( | ||
api_filter_params, | ||
Access::ByPermission.responses(current_user, nil), | ||
Response, | ||
Response.filter_settings | ||
) | ||
respond_filter(filter_response, opts) | ||
end | ||
|
||
# GET /responses/new | ||
def new | ||
do_new_resource | ||
do_set_attributes | ||
do_authorize_instance | ||
respond_show | ||
end | ||
|
||
# POST /responses | ||
# POST /study/:study_id/questions/:question_id/responses | ||
def create | ||
do_new_resource | ||
do_set_attributes(response_params) | ||
do_authorize_instance | ||
|
||
if @response.save | ||
respond_create_success(response_path(@response)) | ||
else | ||
respond_change_fail | ||
end | ||
end | ||
|
||
# DELETE /responses/:id | ||
def destroy | ||
do_load_resource | ||
do_authorize_instance | ||
@response.destroy | ||
respond_destroy | ||
end | ||
|
||
|
||
private | ||
|
||
def response_params | ||
params.require(:response).permit(:study_id, :question_id, :dataset_item_id, :text, :data) | ||
end | ||
|
||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
class StudiesController < ApplicationController | ||
|
||
include Api::ControllerHelper | ||
|
||
# GET /studies | ||
def index | ||
do_authorize_class | ||
|
||
@studies, opts = Settings.api_response.response_advanced( | ||
api_filter_params, | ||
Study.all, | ||
Study, | ||
Study.filter_settings | ||
) | ||
respond_index(opts) | ||
end | ||
|
||
# GET /studies/:id | ||
def show | ||
do_load_resource | ||
do_authorize_instance | ||
respond_show | ||
end | ||
|
||
# GET /studies/filter | ||
def filter | ||
do_authorize_class | ||
|
||
filter_response, opts = Settings.api_response.response_advanced( | ||
api_filter_params, | ||
Study.all, | ||
Study, | ||
Study.filter_settings | ||
) | ||
respond_filter(filter_response, opts) | ||
end | ||
|
||
def new | ||
do_new_resource | ||
do_set_attributes | ||
do_authorize_instance | ||
|
||
respond_show | ||
end | ||
|
||
# POST /studies/ | ||
def create | ||
do_new_resource | ||
do_set_attributes(study_params) | ||
do_authorize_instance | ||
|
||
if @study.save | ||
respond_create_success(study_path(@study)) | ||
else | ||
respond_change_fail | ||
end | ||
end | ||
|
||
# PUT /studies/:id | ||
def update | ||
do_load_resource | ||
do_authorize_instance | ||
|
||
if @study.update_attributes(study_params) | ||
respond_show | ||
else | ||
respond_change_fail | ||
end | ||
end | ||
|
||
# DELETE /studies/:id | ||
def destroy | ||
do_load_resource | ||
do_authorize_instance | ||
@study.destroy | ||
respond_destroy | ||
end | ||
|
||
private | ||
|
||
def study_params | ||
# params[:study] = params[:study] || {} | ||
# params[:study][:dataset_id] = params[:dataset_id] | ||
params.require(:study).permit(:dataset_id, :name) | ||
end | ||
|
||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ class Dataset < ActiveRecord::Base | |
belongs_to :creator, class_name: 'User', foreign_key: :creator_id, inverse_of: :created_datasets | ||
belongs_to :updater, class_name: 'User', foreign_key: :updater_id, inverse_of: :updated_datasets | ||
has_many :dataset_items | ||
has_many :study | ||
|
||
# We have not enabled soft deletes yet since we do not support deleting datasets | ||
# This may change in the future | ||
|
@@ -23,6 +24,7 @@ class Dataset < ActiveRecord::Base | |
# This will potentially be hit very often, maybe multiple times per request | ||
# and therefore is a possible avenue for future optimization if necessary | ||
def self.default_dataset_id | ||
# note: this may cause db:create and db:migrate to fail | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? can we code around this edge case? |
||
Dataset.where(name: 'default').first.id | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add in that link to the rails issue that describes this problem and the recommended work around?