-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathapplication_controller.rb
More file actions
142 lines (115 loc) · 4.44 KB
/
application_controller.rb
File metadata and controls
142 lines (115 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# The parent controller for all other controllers.
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :set_user, :set_user_configuration, :set_pinned_apps, :set_nav_groups, :set_announcements
before_action :set_my_balances, only: [:index, :new, :featured]
before_action :set_featured_group, :set_custom_navigation
before_action :check_required_announcements
def check_required_announcements
return if instance_of?(SettingsController)
render inline: '', layout: :default if @announcements.select(&:required?).reject(&:completed?).any?
end
def set_user
@user = CurrentUser
end
def set_user_configuration
@user_configuration ||= UserConfiguration.new(request_hostname: request.hostname)
end
def set_custom_navigation
@nav_bar = NavBar.items(@user_configuration.nav_bar)
@help_bar = NavBar.items(@user_configuration.help_bar)
end
def set_nav_groups
#TODO: for AweSim, what if we added the shared apps here?
@nav_groups = filter_groups(sys_app_groups)
end
def set_featured_group
apps = AppRecategorizer.recategorize(@pinned_apps, I18n.t("dashboard.pinned_apps_category"), I18n.t('dashboard.pinned_apps_title'))
group = OodAppGroup.groups_for(apps: apps, nav_limit: @user_configuration.pinned_apps_menu_length)
@featured_group = filter_groups(group).first # 1 single group called 'Apps'
end
def sys_apps
@sys_apps ||= SysRouter.apps
end
def dev_apps
@dev_apps ||= ::Configuration.app_development_enabled? ? DevRouter.apps : []
end
def usr_apps
@usr_apps ||= ::Configuration.app_sharing_enabled? ? UsrRouter.all_apps(owners: UsrRouter.owners) : []
end
def nav_all_apps
@nav_all_apps ||= nav_sys_apps + nav_usr_apps + nav_dev_apps
end
def nav_sys_apps
sys_apps.select(&:should_appear_in_nav?)
end
def nav_dev_apps
dev_apps.select(&:should_appear_in_nav?)
end
def nav_usr_apps
usr_apps.select(&:should_appear_in_nav?)
end
def sys_app_groups
OodAppGroup.groups_for(apps: nav_sys_apps)
end
def set_pinned_apps
@pinned_apps ||= Router.pinned_apps(@user_configuration.pinned_apps, nav_all_apps)
end
def set_announcements
all_announcements = Announcements.all(@user_configuration.announcement_path)
parse_errors, announcements = all_announcements.partition(&:parse_error?)
if parse_errors.any?
flash.now[:announcement_parse_errors] = helpers.safe_join(
parse_errors.map do |a|
source = a.source.presence || a.id.presence || 'unknown'
short_name =
begin
Pathname.new(source.to_s).basename.sub_ext('').to_s
rescue StandardError
source.to_s
end
headline = "Could not render announcement '#{short_name}' because of error"
details = [a.error_class.presence, a.error_message.presence].compact.join(': ')
details = a.message.presence || a.msg.presence || 'Error parsing announcement.' if details.blank?
helpers.content_tag(:div) do
helpers.safe_join(
[
helpers.content_tag(:div, headline, class: 'card-header bg-transparent'),
helpers.content_tag(:div, details.to_s, class: 'card-body py-2'),
]
)
end
end,
helpers.safe_join([helpers.tag.br, helpers.tag.br])
)
end
@announcements ||= announcements
rescue => e
logger.warn "Error parsing announcements: #{e.message}"
@announcements ||= []
end
# Set a list of my quotas which can be used to display warnings if there is
# an insufficient disk resource
def set_my_quotas
@my_quotas = []
::Configuration.quota_paths.each { |path| @my_quotas += Quota.find(path, OodSupport::User.new.name) }
@my_quotas
end
# Set a list of my balances which can be used to display warnings if there is
# an insufficient balance
def set_my_balances
@my_balances = []
::Configuration.balance_paths.each { |path| @my_balances += Balance.find(path, OodSupport::User.new.name) }
@my_balances
end
private
def filter_groups(groups)
if @user_configuration.filter_nav_categories?
OodAppGroup.select(titles: @user_configuration.nav_categories, groups: groups)
else
OodAppGroup.order(titles: @user_configuration.nav_categories, groups: groups)
end
end
end