Class: ProjectsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ProjectsController
- Defined in:
- app/controllers/projects_controller.rb
Overview
rubocop:todo Metrics/ClassLength
Constant Summary
Constants included from FlashTruncation
FlashTruncation::STRING_OVERHEAD
Instance Method Summary collapse
- #collaborators ⇒ Object
-
#create ⇒ Object
rubocop:todo Metrics/AbcSize, Metrics/MethodLength.
- #destroy ⇒ Object
- #edit ⇒ Object
-
#follow ⇒ Object
rubocop:todo Metrics/AbcSize.
-
#grant_role ⇒ Object
rubocop:todo Metrics/MethodLength.
-
#index ⇒ Object
TODO: before_action :redirect_if_not_owner_or_admin, :only => [:create, :update, :destroy, :edit, :new].
- #new ⇒ Object
- #related_studies ⇒ Object
-
#remove_role ⇒ Object
rubocop:todo Metrics/MethodLength.
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
#block_api_access, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!
Methods included from FlashTruncation
#max_flash_size, #truncate_flash, #truncate_flash_array
Instance Method Details
#collaborators ⇒ Object
104 105 106 107 108 109 |
# File 'app/controllers/projects_controller.rb', line 104 def collaborators @project = Project.find(params[:id]) @all_roles = %w[owner follower manager] @roles = Role.where(authorizable_id: @project.id, authorizable_type: 'Project') @users = User.order(:first_name) end |
#create ⇒ Object
rubocop:todo Metrics/AbcSize, Metrics/MethodLength
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 |
# File 'app/controllers/projects_controller.rb', line 45 def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength # TODO[5002667]: All of this code should be in a before_create/after_create callback in the Project model ... @project = Project.new(params[:project]) @project.save! current_user.grant_manager(@project) # Creates an event when a new Project is created EventFactory.new_project(@project, current_user) # TODO[5002667]: ... to here. flash[:notice] = 'Your project has been created' respond_to do |format| format.html { redirect_to project_path(@project) } format.xml { render xml: @project, status: :created, location: @project } format.json { render json: @project, status: :created, location: @project } end rescue ActiveRecord::RecordInvalid => e flash.now[:error] = 'Problems creating your new project' respond_to do |format| format.html { render action: 'new' } format.xml { render xml: @project.errors, status: :unprocessable_entity } format.json { render json: @project.errors, status: :unprocessable_entity } end end |
#destroy ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'app/controllers/projects_controller.rb', line 85 def destroy @project.destroy respond_to do |format| format.html { redirect_to(projects_url) } format.xml { head :ok } end end |
#edit ⇒ Object
40 41 42 43 |
# File 'app/controllers/projects_controller.rb', line 40 def edit @project = Project.find(params[:id]) @users = User.all end |
#follow ⇒ Object
rubocop:todo Metrics/AbcSize
111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/controllers/projects_controller.rb', line 111 def follow # rubocop:todo Metrics/AbcSize @project = Project.find(params[:id]) if current_user.follower_of?(@project) current_user.remove_role 'follower', @project flash[:notice] = "You have stopped following the '#{@project.name}' project." else current_user.grant_follower(@project) flash[:notice] = "You are now following the '#{@project.name}' project." end redirect_to project_path(@project) end |
#grant_role ⇒ Object
rubocop:todo Metrics/MethodLength
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/controllers/projects_controller.rb', line 124 def grant_role # rubocop:todo Metrics/AbcSize @user = User.find(params[:role][:user]) @project = Project.find(params[:id]) @role = Role.find_by(name: params[:role][:authorizable_type]) if request.xhr? if params[:role] @user.grant_role(params[:role][:authorizable_type].to_s, @project) @roles = @project.roles flash[:notice] = 'Role added' render partial: 'roles', status: 200 else @roles = @project.roles flash[:error] = 'A problem occurred while adding the role' render partial: 'roles', status: 500 end else @roles = @project.roles flash[:error] = 'A problem occurred while adding the role' render partial: 'roles', status: 401 end end |
#index ⇒ Object
TODO: before_action :redirect_if_not_owner_or_admin, :only => [:create, :update, :destroy, :edit, :new]
12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/projects_controller.rb', line 12 def index @projects = Project.alphabetical respond_to do |format| format.html format.xml { render xml: Project.alphabetical } format.json { render json: Project.alphabetical } end end |
#new ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/projects_controller.rb', line 30 def new @project = Project.new respond_to do |format| format.html format.xml { render xml: @project } format.json { render json: @project } end end |
#related_studies ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/projects_controller.rb', line 94 def @project = Project.find(params[:id]) @studies = @project.studies respond_to do |format| format.html format.xml end end |
#remove_role ⇒ Object
rubocop:todo Metrics/MethodLength
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'app/controllers/projects_controller.rb', line 150 def remove_role # rubocop:todo Metrics/AbcSize @user = User.find(params[:role][:user]) @project = Project.find(params[:id]) @role = Role.find_by(name: params[:role][:authorizable_type]) if request.xhr? if params[:role] @user.remove_role(params[:role][:authorizable_type].to_s, @project) @roles = @project.roles flash[:error] = 'Role was removed' render partial: 'roles', status: 200 else @roles = @project.roles flash[:error] = 'A problem occurred while removing the role' render partial: 'roles', status: 500 end else @roles = @project.roles flash[:error] = 'A problem occurred while removing the role' render partial: 'roles', status: 401 end end |
#show ⇒ Object
22 23 24 25 26 27 28 |
# File 'app/controllers/projects_controller.rb', line 22 def show respond_to do |format| format.html format.xml format.json { render json: @project } end end |
#update ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/projects_controller.rb', line 72 def update respond_to do |format| if @project.update(params[:project]) flash[:notice] = 'Project was successfully updated.' format.html { redirect_to(@project) } format.xml { head :ok } else format.html { render action: 'edit' } format.xml { render xml: @project.errors, status: :unprocessable_entity } end end end |