Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ProjectsHelper, Workbench::SessionsHelper
Defined in:
app/controllers/application_controller.rb

Overview

this is the main controller

Direct Known Subclasses

AdministrationController, AlternateValuesController, AnnotationsController, Api::V1::TaxonNamesController, ApiController, AssertedDistributionsController, AuthorsController, BiocurationClassificationsController, BiologicalAssociationsController, BiologicalAssociationsGraphsController, BiologicalRelationshipsController, CitationTopicsController, CitationsController, CollectingEventsController, CollectionObjectObservationsController, CollectionObjectsController, CollectionProfilesController, CombinationsController, CommonNamesController, ConfidenceLevelsController, ConfidencesController, ContainerItemsController, ContainersController, ContentsController, ControlledVocabularyTermsController, CrashTestController, DashboardController, DataAttributesController, DepictionsController, DocumentationController, DocumentsController, GeographicAreaTypesController, GeographicAreasController, GeographicAreasGeographicItemsController, GeographicItemsController, Georeferences::GeoLocatesController, Georeferences::GoogleMapsController, GeoreferencesController, HubController, IdentifiersController, ImagesController, KeywordsController, LanguagesController, LoanItemsController, LoansController, NamespacesController, NotesController, OriginRelationshipsController, OtuPageLayoutSectionsController, OtuPageLayoutsController, OtusController, PeopleController, PinboardItemsController, PredicatesController, PreparationTypesController, ProjectMembersController, ProjectSourcesController, ProjectsController, ProtocolRelationshipsController, ProtocolsController, PublicContentsController, RangedLotCategoriesController, RepositoriesController, SerialChronologiesController, SerialsController, SessionsController, SourcesController, TaggedSectionKeywordsController, TagsController, Tasks::Accessions::Breakdown::BufferedDataController, Tasks::Accessions::Breakdown::SqedDepictionController, Tasks::Accessions::Quick::SimpleController, Tasks::Accessions::Quick::VerbatimMaterialController, Tasks::Accessions::Report::DwcController, Tasks::Accessions::Verify::MaterialController, Tasks::Bibliography::VerbatimReferenceController, Tasks::CollectionObjects::FilterController, Tasks::Content::PreviewController, Tasks::ControlledVocabularies::BiocurationController, Tasks::Gis::AssertedDistributionController, Tasks::Gis::DrawMapItemController, Tasks::Gis::DrawableMapController, Tasks::Gis::GeographicAreaLookupController, Tasks::Gis::LocalityController, Tasks::Gis::MatchGeoreferenceController, Tasks::Gis::OtuDistributionDataController, Tasks::Gis::ReportController, Tasks::LoansController, Tasks::Nomenclature::BrowseController, Tasks::Nomenclature::BySourceController, Tasks::Nomenclature::Catalog::BasisController, Tasks::Nomenclature::OriginalCombinationController, Tasks::People::AuthorController, Tasks::Serials::SimilarController, Tasks::Usage::UserActivityController, TaxonDeterminationsController, TaxonNameClassificationsController, TaxonNameRelationshipsController, TaxonNamesController, TopicsController, TypeMaterialsController, UserPreferencesController, UsersController

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Attribute Details

- (Object) is_data_controller=(value) (writeonly)

In use



12
13
14
# File 'app/controllers/application_controller.rb', line 12

def is_data_controller=(value)
  @is_data_controller = value
end

- (Object) is_task_controller=(value) (writeonly)

In use



12
13
14
# File 'app/controllers/application_controller.rb', line 12

def is_task_controller=(value)
  @is_task_controller = value
end

- (Object) meta_data



76
77
78
79
80
81
# File 'app/controllers/application_controller.rb', line 76

def 
  @meta_data ||= {
    description: @meta_description,
    keywords:    @meta_keywords
  }.delete_if { |_k, v| v.nil? }
end

- (Object) meta_description

Returns the value of attribute meta_description



16
17
18
# File 'app/controllers/application_controller.rb', line 16

def meta_description
  @meta_description
end

- (Object) meta_keywords

Returns the value of attribute meta_keywords



16
17
18
# File 'app/controllers/application_controller.rb', line 16

def meta_keywords
  @meta_keywords
end

- (Object) meta_title



71
72
73
74
# File 'app/controllers/application_controller.rb', line 71

def meta_title
  @meta_title ||= [@meta_title.presence || @page_title.presence, site_name].
    compact.join(' | ')
end

- (Object) page_title

Returns the value of attribute page_title



16
17
18
# File 'app/controllers/application_controller.rb', line 16

def page_title
  @page_title
end

- (Object) site_name



83
84
85
# File 'app/controllers/application_controller.rb', line 83

def site_name
  @site_name ||= 'TaxonWorks'
end

Instance Method Details

- (Object) clear_project_and_user_variables



54
55
56
57
# File 'app/controllers/application_controller.rb', line 54

def clear_project_and_user_variables
  $project_id = nil
  $user_id    = nil
end


87
88
89
90
# File 'app/controllers/application_controller.rb', line 87

def digest_cookie(file, key)
  sha256       = Digest::SHA256.file(file)
  cookies[key] = sha256.hexdigest
end

Returns:

  • (Boolean)


92
93
94
95
# File 'app/controllers/application_controller.rb', line 92

def digested_cookie_exists?(file, key)
  sha256 = Digest::SHA256.file(file)
  cookies[key] == sha256.hexdigest
end


112
113
114
# File 'app/controllers/application_controller.rb', line 112

def disable_turbolinks
  @no_turbolinks = true
end

- (Object) intercept_api



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/application_controller.rb', line 33

def intercept_api
  if /^\/api/ =~ request.path # rubocop:disable Style/RegexpLiteral
    if token_authenticate
      render(json: {success: false}, status: :bad_request) && return unless set_project_from_params
    else
      render(json: {success: false}, status: :unauthorized) && return
    end
  end
  true
end

- (Object) invalid_object(object) (private)



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

def invalid_object(object)
  !(!object.try(:project_id) || project_matches(object))
end

- (Boolean) is_data_controller?

Returns true if the controller is that of data class. See controllers/concerns/data_controller_configuration/ concern. Data controllers can not be task controllers.

Returns:

  • (Boolean)


61
62
63
# File 'app/controllers/application_controller.rb', line 61

def is_data_controller?
  @is_data_controller
end

- (Boolean) is_task_controller?

Returns true if the controller is a task controller. See controllers/concerns/task_controller_configuration/ concern. Task controllers can not be data controllers.

Returns:

  • (Boolean)


67
68
69
# File 'app/controllers/application_controller.rb', line 67

def is_task_controller?
  @is_task_controller
end

- (Object) log_user_recent_route

TODO: Make RecenRoutes modules that handles exceptions, only etc.



45
46
47
# File 'app/controllers/application_controller.rb', line 45

def log_user_recent_route
  @sessions_current_user.add_recently_visited_to_footprint(request.fullpath, @recent_object) if @sessions_current_user
end

- (Object) notice_user (private)



99
100
101
102
103
# File 'app/controllers/application_controller.rb', line 99

def notice_user 
  if sessions_current_user
    sessions_current_user.update_last_seen_at
  end
end

- (Object) project_matches(object) (private)



136
137
138
# File 'app/controllers/application_controller.rb', line 136

def project_matches(object)
  object.try(:project_id) == sessions_current_project_id
end

- (Object) record_not_found (private)



105
106
107
108
109
110
# File 'app/controllers/application_controller.rb', line 105

def record_not_found
  respond_to do |format|
    format.html { render plain: '404 Not Found', status: 404 }
    format.json { render json: {success: false}, status: 404 }
  end
end

- (Object) set_project_and_user_variables



49
50
51
52
# File 'app/controllers/application_controller.rb', line 49

def set_project_and_user_variables
  $project_id = sessions_current_project_id # This also sets @sessions_current_project_id
  $user_id    = sessions_current_user_id
end

- (Object) set_project_from_params (private)



128
129
130
# File 'app/controllers/application_controller.rb', line 128

def set_project_from_params
  self.sessions_current_project_id = params[:project_id]
end

- (Object) token_authenticate (private)



116
117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/application_controller.rb', line 116

def token_authenticate
  t = params[:token]

  unless t
    authenticate_with_http_token do |token, _options|
      t = token
    end
  end

  @sessions_current_user = User.find_by_api_access_token(t) if t
end