Class: ProjectsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/projects_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#autocompleteObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/controllers/projects_controller.rb', line 115

def autocomplete
  @projects = Project.find_for_autocomplete(params)

  data = @projects.collect do |t|
    {id: t.id,
     label: ApplicationController.helpers.project_tag(t),
     response_values: {
       params[:method] => t.id
     },
     label_html: ApplicationController.helpers.project_tag(t)
    }
  end

  render json: data
end

#createObject

POST /projects POST /projects.json



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/projects_controller.rb', line 39

def create
  # can't use project_params here because :create_with_current_user param will be rejected
  # (as it should, it's a one off that shouldn't be accepted anywhere else)
  create_with_current_user = params.dig(:project, :create_with_current_user)

  @project = Project.new(project_params)

  respond_to do |format|
    if @project.save

      if create_with_current_user
        ProjectMember.create(project_id: @project.id, user_id: Current.user_id)
      end

      format.html { redirect_to @project, notice: 'Project was successfully created.' }
      format.json { render action: 'show', status: :created, location: @project }
    else
      format.html { render action: 'new' }
      format.json { render json: @project.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /projects/1 DELETE /projects/1.json



78
79
80
# File 'app/controllers/projects_controller.rb', line 78

def destroy
  redirect_to projects_url, notice: 'Nice try, not this time.'
end

#editObject

GET /projects/1/edit



34
35
# File 'app/controllers/projects_controller.rb', line 34

def edit
end

#go_toObject (private)



148
149
150
# File 'app/controllers/projects_controller.rb', line 148

def go_to
  @project.workbench_starting_path
end

#indexObject

GET /projects GET /projects.json



11
12
13
# File 'app/controllers/projects_controller.rb', line 11

def index
  @projects = Project.all
end

#listObject



103
104
105
# File 'app/controllers/projects_controller.rb', line 103

def list
  @projects = Project.order(:id).page(params[:page]) #.per(10) #.per(3)
end

#newObject

GET /projects/new



29
30
31
# File 'app/controllers/projects_controller.rb', line 29

def new
  @project = Project.new
end

#preferencesObject



82
83
84
85
86
87
# File 'app/controllers/projects_controller.rb', line 82

def preferences
  @project = sessions_current_project
  if @project.nil?
    render json: {success: false}, status: :not_found and return
  end
end

#project_paramsObject (private)



143
144
145
146
# File 'app/controllers/projects_controller.rb', line 143

def project_params
  params.require(:project).permit(
    :name, :set_new_api_access_token, :clear_api_access_token, :data_curation_issue_tracker_url, Project.key_value_preferences, Project.array_preferences, Project.hash_preferences)
end

#recently_created_statsObject



131
132
133
134
# File 'app/controllers/projects_controller.rb', line 131

def recently_created_stats
  redirect_to hub_path, notice: 'Select a project first.' if @project.nil?
  render json: @project.data_breakdown_for_chartkick_recent
end

#searchObject



107
108
109
110
111
112
113
# File 'app/controllers/projects_controller.rb', line 107

def search
  if params[:id].blank?
    redirect_to projects_path, alert: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to project_path(params[:id])
  end
end

#selectObject



89
90
91
92
93
94
95
96
97
# File 'app/controllers/projects_controller.rb', line 89

def select
  set_project
  if authorize_project_selection(sessions_current_user, @project)
    sessions_select_project(@project)
    redirect_to go_to # see def go_to for unprotected redirect mitigation
  else
    redirect_to root_path, notice: 'You are not a member of that project!'
  end
end

#set_projectObject (private)



138
139
140
141
# File 'app/controllers/projects_controller.rb', line 138

def set_project
  @project = Project.find(params[:id])
  @recent_object = @project
end

#settings_forObject



99
100
101
# File 'app/controllers/projects_controller.rb', line 99

def settings_for
  redirect_to edit_project_path(sessions_current_project)
end

#showObject

GET /projects/1 GET /projects/1.json



25
26
# File 'app/controllers/projects_controller.rb', line 25

def show
end

#updateObject

PATCH/PUT /projects/1 PATCH/PUT /projects/1.json



64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/projects_controller.rb', line 64

def update
  respond_to do |format|
    if @project.update(project_params)
      format.html { redirect_to @project, notice: 'Project was successfully updated.' }
      format.json { render :show, status: :ok, location: @project }
    else
      format.html { render action: 'edit' }
      format.json { render json: @project.errors, status: :unprocessable_entity }
    end
  end
end

#user_projectsObject

GET /users/1/projects



16
17
18
19
20
21
# File 'app/controllers/projects_controller.rb', line 16

def user_projects
  @projects = Project.joins(:project_members)
    .where(project_members: {user_id: sessions_current_user_id})
    .order('projects.name')
   render :index
end