Skip to content

Commit

Permalink
[api] Get rid of the webui/requests routes and controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs authored and coolo committed Oct 22, 2013
1 parent 8641fb6 commit 9253702
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 160 deletions.
64 changes: 0 additions & 64 deletions src/api/app/controllers/webui/requests_controller.rb

This file was deleted.

13 changes: 0 additions & 13 deletions src/api/config/routes.rb
Expand Up @@ -326,19 +326,6 @@
get 'public/configuration.xml' => 'configurations#show'
get 'public/status/:action' => 'status#index'

#
# NOTE: webui routes are NOT stable and change together with the webui.
# DO NOT USE THEM IN YOUR TOOLS!
#
namespace :webui do
resources :requests, :only => [:index, :show] do
collection do
get :ids
get :by_class
end
end
end

get '/404' => 'main#notfound'

end
Expand Down
6 changes: 2 additions & 4 deletions src/api/test/functional/request_controller_test.rb
Expand Up @@ -2526,10 +2526,8 @@ def test_repository_delete_request
assert_response :success
id = Xmlhash.parse(@response.body)['id']

get "/webui/requests/#{id}"
assert_response :success
ret = Yajl::Parser.parse(@response.body)
assert !ret['is_target_maintainer'], 'tom is target maintainer'
infos = JSON.parse(BsRequest.find(id).webui_infos.to_json)
assert !infos['is_target_maintainer'], 'tom is target maintainer'
end

test 'cleanup from home' do
Expand Down
2 changes: 1 addition & 1 deletion src/api/webui/app/controllers/webui/project_controller.rb
Expand Up @@ -650,7 +650,7 @@ def packages
end

def requests
@requests = ApiDetails.read(:by_class_requests, project: @project.name)
@requests = @project.request_ids_by_class
@default_request_type = params[:type] if params[:type]
@default_request_state = params[:state] if params[:state]
end
Expand Down
7 changes: 4 additions & 3 deletions src/api/webui/app/controllers/webui/request_controller.rb
Expand Up @@ -59,14 +59,15 @@ def modify_review
def show
redirect_back_or_to :controller => 'home', :action => 'requests' and return if !params[:id]
begin
@req = ApiDetails.read(:request, params[:id])
rescue ApiDetails::NotFoundError
@req = ::BsRequest.find(params[:id])
rescue ActiveRecord::RecordNotFound
flash[:error] = "Can't find request #{params[:id]}"
redirect_back_or_to :controller => "home", :action => "requests" and return
end

@req = @req.webui_infos
@id = @req['id']
@state = @req['state']
@state = @req['state'].to_s
@accept_at = @req['accept_at']
@req['creator'] = User.find_by_login! @req['creator']
@is_author = @req['creator'] == User.current
Expand Down
6 changes: 3 additions & 3 deletions src/api/webui/app/helpers/webui/request_helper.rb
Expand Up @@ -2,7 +2,7 @@ module Webui::RequestHelper

# for a simplified view on a request, must be used only for lists
def reqtype(req)
type = req['type']
type = req[:type].to_s
type = "chgdev" if type == "change_devel"
type = "bugowner" if type == "set_bugowner"
type = "addrole" if type == "add_role"
Expand All @@ -18,7 +18,7 @@ def reqtype(req)
}

def map_request_state_to_flag(state)
STATE_ICONS[state] || ''
STATE_ICONS[state.to_s] || ''
end

STATE_COLORS = {
Expand All @@ -28,7 +28,7 @@ def map_request_state_to_flag(state)
}

def request_state_color(state)
STATE_COLORS[state] || ''
STATE_COLORS[state.to_s] || ''
end

end
33 changes: 25 additions & 8 deletions src/api/webui/app/models/webui/bs_request.rb
Expand Up @@ -175,10 +175,12 @@ def find_last_request(opts)
# FIXME very bad method name
def ids(ids)
return [] if ids.blank?
logger.debug "Fetching request list from api"
logger.debug "Fetching request list from db"
ret = []
ids.each_slice(50) do |a|
ret.concat(ApiDetails.read(:requests, ids: a))
rel = ::BsRequest.where(id: ids).order('bs_requests.id')
rel = rel.includes({ bs_request_actions: :bs_request_action_accept_info }, :bs_request_histories)
rel.each do |r|
ret << r.webui_infos(diffs: false)
end
return ret
end
Expand All @@ -203,11 +205,27 @@ def prepare_list_path(path, opts)
end

def list_ids(opts)
# All types means don't pass 'type' to backend
# All types means don't pass 'type'
if opts[:types] == 'all' || (opts[:types].respond_to?(:include?) && opts[:types].include?('all'))
opts.delete(:types)
end
Webui::ApiDetails.read(:ids_requests, opts)
# Do not allow a full collection to avoid server load
if opts[:project].blank? && opts[:user].blank? && opts[:package].blank?
raise RuntimeError, "This call requires at least one filter, either by user, project or package"
end
roles = opts[:roles] || []
states = opts[:states] || []

# it's wiser to split the queries
if opts[:project] && roles.empty? && (states.empty? || states.include?('review'))
rel = BsRequestCollection.new(opts.merge({ roles: ['reviewer'] }))
ids = rel.ids
rel = BsRequestCollection.new(opts.merge({ roles: ['target', 'source'] }))
else
rel = BsRequestCollection.new(opts)
ids = []
end
ids.concat(rel.ids)
end

def list(opts)
Expand Down Expand Up @@ -249,12 +267,11 @@ def reviewer_for_history_item(item)

# return the login of the creator - to be obsoleted soon (FIXME2.4)
def creator
details = ApiDetails.read(:request, self.id)
return details['creator']
api_obj.creator
end

def api_obj
::BsRequest.find self.id
@api_obj ||= ::BsRequest.find self.id
end
end
end
Expand Up @@ -28,7 +28,7 @@
<% if rqs_out && rqs_out.length > 0 %>
<% rqs_out.each do |rq_out| %>
<% text = "Release request in state '#{rq_out['state']}'" %>
<%= link_to(sprite_tag(map_request_state_to_flag(rq_out['state']), title: text), controller: 'request', action: 'show', id: rq_out['id']) %>
<%= link_to(sprite_tag(map_request_state_to_flag(rq_out['state'].to_s), title: text), controller: 'request', action: 'show', id: rq_out['id']) %>
<% end %>
<% else %>
<% if incident.is_locked? %>
Expand Down
Expand Up @@ -7,23 +7,23 @@
<% @events.each do |event| %>
<tr>
<td class="nowrap" style="width: 1%;">
<%= render :partial => 'shared/user_with_realname_and_icon', :locals => {:user => User.find_by_login(event['who']), :short => true}%>
<%= render :partial => 'shared/user_with_realname_and_icon', :locals => {:user => User.find_by_login(event[:who]), :short => true}%>
</td>
<td>
<% if event['superseded_by'] %>
<%= link_to(event['what'], :id => event['superseded_by']) %>
<% if event[:superseded_by] %>
<%= link_to(event[:what], :id => event[:superseded_by]) %>
<% else %>
<span style="color: <%= event[:color] %>;"><%= event['what'] %></span>
<span style="color: <%= event[:color] %>;"><%= event[:what] %></span>
<% end %>
</td>
<td class="nowrap" style="width: 1%;">
<span class="hidden"><%= Time.parse(event['when']).to_i %></span>
<%= fuzzy_time_string(event['when']) %>
<span class="hidden"><%= event[:when].to_i %></span>
<%= fuzzy_time(event[:when]) %>
</td>
</tr>
<% if !event['comment'].blank? %>
<% if !event[:comment].blank? %>
<tr class="odd">
<td colspan="3" class="expandable_event_comment"><pre class="plain"><%= event['comment'] %></pre></td>
<td colspan="3" class="expandable_event_comment"><pre class="plain"><%= event[:comment] %></pre></td>
</tr>
<% end %>
<% end %>
Expand Down
16 changes: 8 additions & 8 deletions src/api/webui/app/views/webui/request/_reviewer.html.erb
Expand Up @@ -2,14 +2,14 @@
<% no_icon ||= false %>
<% logger.debug review.inspect
if review['by_user'] %>
<%= render :partial => 'shared/user_with_realname_and_icon', :locals => {:user => User.find_by_login(review['by_user']), :short => true, :no_link => no_link, :no_icon => no_icon} %>
<% elsif review['by_group'] %>
<%= link_to_if(!no_link, review['by_group'], :controller => 'group', :action => 'show', id: review['by_group']) %>
<% elsif review['by_project'] %>
<% if review['by_package'] %>
<%= link_to_if(!no_link, "#{review['by_project']} / #{review['by_package']}", :controller => 'package', :action => 'users', :project => review['by_project'], :package => review['by_package']) %>
if review[:by_user] %>
<%= render :partial => 'shared/user_with_realname_and_icon', :locals => {:user => User.find_by_login(review[:by_user]), :short => true, :no_link => no_link, :no_icon => no_icon} %>
<% elsif review[:by_group] %>
<%= link_to_if(!no_link, review[:by_group], :controller => 'group', :action => 'show', id: review[:by_group]) %>
<% elsif review[:by_project] %>
<% if review[:by_package] %>
<%= link_to_if(!no_link, "#{review[:by_project]} / #{review[:by_package]}", :controller => 'package', :action => 'users', :project => review[:by_project], :package => review[:by_package]) %>
<% else %>
<%= link_to_if(!no_link, review['by_project'], :controller => 'project', :action => 'users', :project => review['by_project']) %>
<%= link_to_if(!no_link, review[:by_project], :controller => 'project', :action => 'users', :project => review[:by_project]) %>
<% end %>
<% end %>

0 comments on commit 9253702

Please sign in to comment.