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, SoftValidationsController, 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::Citations::OtusController, Tasks::CollectingEvents::Parse::Stepwise::DatesController, Tasks::CollectingEvents::Parse::Stepwise::LatLongController, Tasks::CollectionObjects::BrowseController, Tasks::CollectionObjects::FilterController, Tasks::Content::EditorController, Tasks::Content::PreviewController, Tasks::ControlledVocabularies::BiocurationController, Tasks::Gis::AssertedDistributionController, Tasks::Gis::DrawableMapController, Tasks::Gis::GeographicAreaLookupController, Tasks::Gis::LocalityController, Tasks::Gis::MatchGeoreferenceController, Tasks::Gis::OtuDistributionDataController, Tasks::Gis::ReportController, Tasks::Import::Dwca::PsuImportController, Tasks::Loans::OverdueController, Tasks::LoansController, Tasks::Nomenclature::BrowseController, Tasks::Nomenclature::BySourceController, Tasks::Nomenclature::Catalog::BasisController, Tasks::Nomenclature::OriginalCombinationController, Tasks::People::AuthorController, Tasks::Serials::SimilarController, Tasks::Sources::BrowseController, 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)

Sets the attribute is_data_controller

Parameters:

  • value

    the value to set the attribute is_data_controller to.



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

def is_data_controller=(value)
  @is_data_controller = value
end

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

Sets the attribute is_task_controller

Parameters:

  • value

    the value to set the attribute is_task_controller to.



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

def is_task_controller=(value)
  @is_task_controller = value
end

- (Object) meta_data



72
73
74
75
76
77
# File 'app/controllers/application_controller.rb', line 72

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



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

def meta_description
  @meta_description
end

- (Object) meta_keywords

Returns the value of attribute meta_keywords



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

def meta_keywords
  @meta_keywords
end

- (Object) meta_title



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

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



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

def page_title
  @page_title
end

- (Object) site_name



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

def site_name
  @site_name ||= 'TaxonWorks'
end

Instance Method Details

- (Object) clear_project_and_user_variables



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

def clear_project_and_user_variables
  $project_id = nil
  $user_id    = nil
end


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

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

Returns:

  • (Boolean)


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

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


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

def disable_turbolinks
  @no_turbolinks = true
end

- (Object) intercept_api



29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/application_controller.rb', line 29

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)



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

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)


57
58
59
# File 'app/controllers/application_controller.rb', line 57

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)


63
64
65
# File 'app/controllers/application_controller.rb', line 63

def is_task_controller?
  @is_task_controller
end

- (Object) log_user_recent_route

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



41
42
43
# File 'app/controllers/application_controller.rb', line 41

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)



95
96
97
98
99
# File 'app/controllers/application_controller.rb', line 95

def notice_user 
  if sessions_current_user
    sessions_current_user.update_last_seen_at
  end
end

- (Object) project_matches(object) (private)



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

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

- (Object) record_not_found (private)



101
102
103
104
105
106
# File 'app/controllers/application_controller.rb', line 101

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



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

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)



124
125
126
# File 'app/controllers/application_controller.rb', line 124

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

- (Object) token_authenticate (private)



112
113
114
115
116
117
118
119
120
121
122
# File 'app/controllers/application_controller.rb', line 112

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