Skip to content

Commit

Permalink
[webui] avoid links to 404
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Nov 30, 2012
1 parent 3635d74 commit 1c43635
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
18 changes: 18 additions & 0 deletions src/webui/app/helpers/application_helper.rb
Expand Up @@ -438,5 +438,23 @@ def setup_codemirror_editor(opts = {})

end

def link_to_project(prj, linktext=nil)
linktext = prj if linktext.blank?
if Project.exists?(prj)
link_to(linktext, {:controller => :project, :action => :show, :project => prj}, title: prj )
else
linktext
end
end

def link_to_package(prj, pkg, linktext=nil)
linktext = pkg if linktext.blank?
if Package.exists?(prj, pkg)
link_to(linktext, { controller: :package, action: :show, project: prj, package: pkg}, title: pkg)
else
linktext
end
end

end

2 changes: 1 addition & 1 deletion src/webui/app/models/bs_request.rb
Expand Up @@ -119,7 +119,7 @@ def set_incident(id, incident_project)
ActiveXML::transport.direct_http URI(path), :method => "POST", :data => ''
BsRequest.free_cache(id)
return true
rescue ActiveXML::Transport::ForbiddenError, ActiveXML::Transport::NotFoundError, ActiveXML::Transport::Error => e
rescue ActiveXML::Transport::Error => e
raise ModifyError, e.summary
end
raise ModifyError, "Unable to merge with incident #{incident_project}"
Expand Down
20 changes: 7 additions & 13 deletions src/webui/app/views/shared/_requests.html.erb
Expand Up @@ -38,17 +38,12 @@
<% end %>
<td class="request_source">
<% if ae['spkg'] %>
<% src_proj = format_projectname(ae['sprj'], req['creator'])
src_pack = elide(ae['spkg'], elide_len >> 1) %>
<%= link_to(src_proj, {:controller => :project, :action => :show, :project => ae['sprj']}, { :title => ae['sprj']} ) %> /
<% if Package.exists?(ae['sprj'], ae['spkg']) %>
<%= link_to(src_pack, :controller => :package, :action => :show, :project => ae['sprj'], :package => ae['spkg']) %>
<% else %>
<%= src_pack %>
<% end %>
<% src_proj = format_projectname(ae['sprj'], req['creator'])
src_pack = elide(ae['spkg'], elide_len >> 1) %>
<%= link_to_project(ae['sprj'], src_proj) %> / <%= link_to_package(ae['sprj'], ae['spkg'], src_pack) %>
<% elsif ae['sprj'] %>
<%# Happens for maintenance requests, no source package there %>
<%= link_to(elide(ae['sprj'], elide_len), :controller => :project, :action => :show, :project => ae['sprj']) %>
<%= link_to_project(ae['sprj'], elide(ae['sprj'], elide_len)) %>
<% end %>
</td>
<% if !no_target%>
Expand All @@ -57,14 +52,13 @@
<% if not @project or @project.name != ae['tprj'] %><!-- <%= ae['tprj'] %> -->
<% if ae['tpkg'] and not (ae.has_key?('source') and Package.exists?(ae['sprj'], ae['spkg']) and ae['spkg'] == ae['tpkg']) %> <!-- /<%= ae['tpkg'] %> -->
<% tgt_proj, tgt_pack = elide_two(ae['tprj'], ae['tpkg'], elide_len) %>
<%= link_to(tgt_proj, :controller => :project, :action => :show, :project => ae['tprj']) %> /
<%= link_to(tgt_pack, :controller => :package, :action => :show, :project => ae['tprj'], :package => ae['tpkg']) %>
<%= link_to_project(ae['tprj'], tgt_proj) %> / <%= link_to_package(ae['tprj'], ae['tpkg'], tgt_pack) %>
<% else %>
<%= link_to(elide(ae['tprj'], elide_len), :controller => :project, :action => :show, :project => ae['tprj']) %>
<%= link_to_project(ae['tprj'], elide(ae['tprj'], elide_len)) %>
<% end %>
<% else %>
<% if ae['tpkg'] and Package.exists?(@project.name, ae['tpkg']) %> <!-- <%= ae['tpkg'] %> -->
<%= link_to(elide(ae['tpkg'], elide_len), :controller => :package, :action => :show, :project => ae['tprj'], :package => ae['tpkg']) %>
<%= link_to_package(ae['tprj'], ae['tpkg'], elide(ae['tpkg'], elide_len)) %>
<% elsif ae['type'] == "delete" %>
This project
<% end %>
Expand Down
4 changes: 1 addition & 3 deletions src/webui/test/functional/spider_test.rb
Expand Up @@ -43,11 +43,8 @@ def raiseit(message, url)
return if url.end_with? "/package/view_file?file=myfile&package=pack2_linked&project=BaseDistro2.0%3ALinkedUpdateProject&rev=1"
return if url.end_with? "/package/view_file?file=package.spec&package=pack2_linked&project=BaseDistro2.0%3ALinkedUpdateProject&rev=1"
return if url =~ %r{/package/binary\?.*project=BinaryprotectedProject}
return if url.end_with? "/package/show?package=notthere&project=NotExisiting"
return if url.end_with? "/package/view_file?file=my_file&package=remotepackage&project=LocalProject&rev=1"
return if url.end_with? "/project/show?project=HiddenRemoteInstance"
return if url.end_with? "/project/show?project=HiddenProject"
return if url.end_with? "/project/show?project=NotExisiting"
return if url.end_with? "/package/files?package=target&project=SourceprotectedProject"
return if url =~ %r{/package/binary\?.*project=BinaryprotectedProject}
return if url.end_with? "/package/revisions?package=pack&project=SourceprotectedProject"
Expand Down Expand Up @@ -88,6 +85,7 @@ def crawl
next unless body
if !body.css("div#flash-messages div.ui-state-error").empty?
raiseit("flash alert", theone)
raise "Flash"
end
body.css('h1').each do |h|
if h.content == 'Internal Server Error'
Expand Down

0 comments on commit 1c43635

Please sign in to comment.