/
main_controller.rb
139 lines (120 loc) · 4.68 KB
/
main_controller.rb
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
class Webui::MainController < Webui::WebuiController
include Webui::WebuiHelper
include StatisticsCalculations
# permissions.status_message_create
before_filter :require_admin, only: [:delete_message, :add_news]
def index
@news = StatusMessage.alive.limit(4)
unless @spider_bot
@latest_updates = get_latest_updated(6)
end
rescue ActiveXML::Transport::UnauthorizedError
@anonymous_forbidden = true
logger.error 'Could not load all frontpage data, probably due to forbidden anonymous access in the api.'
end
# This action does the heavy lifting for the index method and is only invoked by an AJAX request
def systemstatus
check_ajax
if @spider_bot
@workerstatus = Xmlhash::XMLHash.new
else
@workerstatus = WorkerStatus.hidden.to_hash
end
@waiting_packages = 0
@workerstatus.elements('waiting') {|waiting| @waiting_packages += waiting['jobs'].to_i}
@global_counters = find_cached(Webui::GlobalCounters, :expires_in => 15.minutes, :shared => true)
@busy = nil
require_available_architectures unless @spider_bot
if @available_architectures
@available_architectures.each.map {|arch| map_to_workers(arch.name) }.uniq.each do |arch|
archret = frontend.gethistory('building_' + arch, 168).map {|time,value| [time,value]}
if archret.length > 0
if @busy
@busy = Webui::MonitorController.addarrays(@busy, archret)
else
@busy = archret
end
end
end
end
render :partial => 'webui/main/systemstatus'
rescue ActiveXML::Transport::UnauthorizedError
@anonymous_forbidden = true
render :text => '' # AJAX-request means no 'flash' available, don't render anything if we aren't allowed
end
def news
@news = StatusMessage.alive.limit(5)
raise ActionController::RoutingError.new('expected application/rss') unless request.format == Mime::RSS
render layout: false
end
def latest_updates
raise ActionController::RoutingError.new('expected application/rss') unless request.format == Mime::RSS
@latest_updates = get_latest_updated(10)
render layout: false
end
def sitemap
render :layout => false, :content_type => 'application/xml'
end
def require_projects
@projects = Array.new
find_cached(Webui::Collection, :id, :what => 'project').each_project do |p|
@projects << p.value(:name)
end
end
def sitemap_projects
require_projects
render :layout => false, :content_type => 'application/xml'
end
def sitemap_projects_subpage(action, changefreq, priority)
require_projects
render :template => 'webui/main/sitemap_projects_subpage', :layout => false, :locals => { :action => action, :changefreq => changefreq, :priority => priority }, :content_type => 'application/xml'
end
def sitemap_projects_packages
sitemap_projects_subpage(:packages, 'monthly', 0.7)
end
def sitemap_projects_prjconf
sitemap_projects_subpage(:prjconf, 'monthly', 0.1)
end
def sitemap_packages
category = params[:category].to_s
@packages = Array.new
predicate = ''
if category =~ %r{home}
predicate = "starts-with(@project,'#{category}')"
elsif category == 'opensuse'
predicate = "starts-with(@project,'openSUSE:')"
elsif category == 'main'
predicate = "not(starts-with(@project,'home:')) and not(starts-with(@project,'DISCONTINUED:')) and not(starts-with(@project,'openSUSE:'))"
end
find_cached(Webui::Collection, :id, :what => 'package', :predicate => predicate).each_package do |p|
@packages << [p.value(:project), p.value(:name)]
end
render :template => 'webui/main/sitemap_packages', :layout => false, :locals => {:action => params[:listaction]}, :content_type => 'application/xml'
end
def add_news_dialog
render_dialog
end
def add_news
if params[:message].nil? or params[:severity].empty?
flash[:error] = 'Please provide a message and severity'
redirect_to(:action => 'index') and return
end
#TODO - make use of permissions.status_message_create
StatusMessage.create!(message: params[:message], severity: params[:severity], user: @user.api_user)
redirect_to(:action => 'index')
end
def delete_message_dialog
render_dialog
end
def delete_message
required_parameters :message_id
StatusMessage.find(params[:message_id]).delete
redirect_to(:action => 'index')
end
def require_available_architectures
super # Call ApplicationController implementation, but catch an additional exception
rescue ActiveXML::Transport::UnauthorizedError
@anonymous_forbidden = true
logger.error 'Could not load all frontpage data, probably due to forbidden anonymous access in the api.'
end
end