rosa-build/app/controllers/api/v1/projects_controller.rb

66 lines
1.5 KiB
Ruby
Raw Permalink Normal View History

class Api::V1::ProjectsController < Api::V1::BaseController
2015-03-04 23:19:19 +00:00
before_action :authenticate_user!
skip_before_action :check_auth, only: [:get_id, :show] if APP_CONFIG['anonymous_access']
skip_before_action :authenticate_user!, only: [:get_id, :show] if APP_CONFIG['anonymous_access']
2014-01-21 04:51:49 +00:00
2015-03-26 23:52:57 +00:00
before_action :load_project, except: [:index, :create, :get_id]
def index
2015-03-19 23:31:41 +00:00
authorize :project
@projects = ProjectPolicy::Scope.new(current_user, Project).
membered.paginate(paginate_params)
end
def get_id
2015-03-19 23:31:41 +00:00
authorize @project = Project.find_by_owner_and_name!(params[:owner], params[:name])
end
def show
end
def update
update_subject @project
end
def destroy
destroy_subject @project
end
def create
@project = Project.new subject_params(Project)
2015-03-19 23:31:41 +00:00
p_params = params[:project] || {}
owner_type = %w(User Group).find{ |t| t == p_params[:owner_type] }
if owner_type.present?
@project.owner = owner_type.constantize.find_by(id: p_params[:owner_id])
else
@project.owner = nil
end
authorize @project
create_subject @project
end
def members
@members = @project.collaborators.order('uname').paginate(paginate_params)
end
2012-10-17 14:46:16 +01:00
def add_member
add_member_to_subject @project, params[:role]
end
def remove_member
remove_member_from_subject @project
end
def update_member
update_member_in_subject @project
end
2015-03-19 23:31:41 +00:00
private
# Private: before_action hook which loads Project.
def load_project
2015-03-26 23:52:57 +00:00
authorize @project = Project.find(params[:id])
2015-03-19 23:31:41 +00:00
end
end