Skip to content

Commit

Permalink
[webui] rename Project.is_remote? to defines_remote?
Browse files Browse the repository at this point in the history
The Project database object for remote usages is always the project
defining the remote instance. find_remote delivers an additional string
identifing the remote project name.

We could have a is_remote? for repositories, because they can be indeed
local active record objects for remote projects, but it seems we don't
have the use case yet for adding this.

Cleaning up some misleaded code which just crashes so far when operating
on a remote project.
  • Loading branch information
adrianschroeter committed Apr 14, 2016
1 parent 7cd1df5 commit a06b1ad
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/api/app/controllers/webui/package_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,11 @@ def live_build_log
end

begin
@package = Package.get_by_project_and_name(params[:project], params[:package],
@package = Package.get_by_project_and_name(@project, params[:package],
use_source: false, follow_project_links: true)
rescue Package::UnknownObjectError
flash[:error] = "Couldn't find package '#{params[:package]}' in project '#{params[:project]}'. Are you sure it exists?"
redirect_to project_show_path(@project.name)
flash[:error] = "Couldn't find package '#{params[:package]}' in project '#{@project.to_param}'. Are you sure it exists?"
redirect_to project_show_path(@project.to_param)
return
end

Expand All @@ -811,7 +811,7 @@ def live_build_log
return
end

@package = params[:package] unless @package
@package ||= params[:package] # for remote package
@arch = params[:arch]
@repo = params[:repository]
@offset = 0
Expand Down
7 changes: 4 additions & 3 deletions src/api/app/controllers/webui/patchinfo_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,14 @@ def get_binaries

def require_exists
unless params[:package].blank?
@package = Package.get_by_project_and_name(@project.to_param, params[:package], use_source: false)
@package = Package.get_by_project_and_name(params[:project], params[:package], use_source: false)
end
@patchinfo = @file = @package.patchinfo

unless @file
unless @package && @package.patchinfo
# FIXME: should work for remote packages
flash[:error] = "Patchinfo not found for #{params[:project]}"
redirect_to controller: 'package', action: 'show', project: @project, package: @package and return
end
@patchinfo = @file = @package.patchinfo
end
end
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def update_target
end

def repositories
if @project.is_remote?
unless @project
# TODO support flagdetails for remote instances in the API
flash[:error] = "You can't show repositories for remote instances"
redirect_to :action => :show, :project => params[:project]
Expand Down
7 changes: 2 additions & 5 deletions src/api/app/helpers/webui/project_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ def show_status_comment(comment, package, firstfail, comments_to_clear)
def project_bread_crumb(*args)
@crumb_list = [link_to('Projects', project_list_public_path)]
return if @spider_bot
# Sometimes @project is a WebuiProject and sometimes a Project
# We need to check this before calling new_record?
unless @project.nil? ||
(@project.kind_of?(Project) && @project.new_record?) ||
@project.is_remote?
# FIXME: should also work for remote
if @project && @project.kind_of?(Project) && !@project.new_record?
prj_parents = nil
if @namespace # corner case where no project object is available
prj_parents = Project.parent_projects(@namespace)
Expand Down
10 changes: 5 additions & 5 deletions src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def cleanup_linking_targets
def self.is_remote_project?(name, skip_access = false)
lpro = find_remote_project(name, skip_access)

lpro && lpro[0].is_remote?
lpro && lpro[0].defines_remote_instance?
end

def self.check_access?(dbp = self)
Expand Down Expand Up @@ -391,8 +391,8 @@ def self.find_remote_project(name, skip_access = false)
logger.debug "Trying to find local project #{local_project}, remote_project #{remote_project}"

project = Project.find_by(name: local_project)
if project && check_access?(project) && project.is_remote?
logger.debug "Found local project #{project.name} with remoteurl #{project.remoteurl}"
if project && check_access?(project) && project.defines_remote_instance?
logger.debug "Found local project #{project.name} for #{remote_project} with remoteurl #{project.remoteurl}"
return project, remote_project
end
end
Expand Down Expand Up @@ -456,7 +456,7 @@ def is_standard?
self.kind == 'standard'
end

def is_remote?
def defines_remote_instance?
self.remoteurl.present?
end

Expand Down Expand Up @@ -694,7 +694,7 @@ def update_release_targets(current_repo, xml_hash)
repository = release_target['repository']
trigger = release_target['trigger']

if Project.find_by(name: project).is_remote?
if Project.find_by(name: project).defines_remote_instance?
raise SaveError, "Can not use remote repository as release target '#{project}/#{repository}'"
else
target_repo = Repository.find_by_project_and_name(project, repository)
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/policies/project_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def update?
return true if @user.is_admin?

# Regular users are not allowed to modify projects with remote references
!@record.is_remote? && !@record.has_remote_repositories?
!@record.defines_remote_instance? && !@record.has_remote_repositories?
end

def destroy?
Expand Down
4 changes: 4 additions & 0 deletions src/api/app/views/webui/package/_live_log_controls.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<% end %>
</p>

<% if @package.kind_of?(Package)%>
<%= render :partial => "tabs" %>
<% end %>
<% if @package.kind_of?(Package) && User.current.can_modify_package?(@package) %>
<p>
<span class="link_trigger_rebuild hidden">
Expand Down
4 changes: 0 additions & 4 deletions src/api/app/views/webui/package/live_build_log.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
package_bread_crumb 'Build Log'
-%>
<% if !@project.is_remote? && @package.kind_of?(Package)%>
<%= render :partial => "tabs" %>
<% end %>
<%= content_for :ready_function do %>
live_build_log_ready();
<% end -%>
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/views/webui/project/_packages_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<p><i>This project does not contain any packages</i></p>
<% end %>
<% if User.current.can_modify_project?(@project) %>
<% if !@project.is_remote? && !(@is_incident_project && !@packages.blank? && @has_patchinfo && @open_release_requests.length == 0) && !@is_maintenance_project %>
<% if @project.kind_of?(Project) && User.current.can_modify_project?(@project) %>
<% if !@project.defines_remote_instance? && !(@is_incident_project && !@packages.blank? && @has_patchinfo && @open_release_requests.length == 0) && !@is_maintenance_project %>
<ul class="horizontal-list">
<li>
<%= link_to(sprited_text('package_add', 'Create package'), controller: 'project', action: 'new_package', project: @project) %>
Expand Down
10 changes: 5 additions & 5 deletions src/api/app/views/webui/project/_tabs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<%= tab 'incidents', 'Incidents', :controller => :project, :action => :maintenance_incidents %>
<%= tab 'maintained', 'Maintained Projects', :controller => :project, :action => :maintained_projects %>
<% else %> <!-- also for incident project -->
<%= tab 'repositories', "Repositories", :controller => :project, :action => :repositories unless @project.is_remote? or @spider_bot %>
<%= tab 'repositories', "Repositories", :controller => :project, :action => :repositories unless @project.defines_remote_instance? or @spider_bot %>
<% end %>
<% if @project.repositories.any? && !@spider_bot -%>
<%= tab 'monitor', "Monitor", :controller => :project, :action => :monitor %>
<% end -%>
<% unless @spider_bot -%>
<%= tab 'requests', "Requests", :controller => :project, :action => 'requests' %>
<%= tab 'users', 'Users', :controller => :project, :action => :users unless @project.is_remote? %>
<%= tab 'subprojects', 'Subprojects', :controller => :project, :action => :subprojects unless @project.is_remote? or @is_maintenance_project %>
<%= tab 'users', 'Users', :controller => :project, :action => :users unless @project.defines_remote_instance? %>
<%= tab 'subprojects', 'Subprojects', :controller => :project, :action => :subprojects unless @project.defines_remote_instance? or @is_maintenance_project %>
<% end -%>
<% if is_advanced_tab? %>
Expand All @@ -33,11 +33,11 @@
</ul>
<div id="advanced_tabs" class="hidden">
<ul>
<%= tab 'projectconfig', 'Project Config', :controller => :project, :action => :prjconf unless @project.is_remote? or @is_maintenance_project %>
<%= tab 'projectconfig', 'Project Config', :controller => :project, :action => :prjconf unless @project.defines_remote_instance? or @is_maintenance_project %>
<% unless @spider_bot -%>
<%= tab 'attribute', 'Attributes', :controller => :attribute, :project => @project, :action => 'index' %>
<%= tab 'meta', "Meta", :controller => :project, :action => :meta %>
<%= tab 'status', 'Status', :controller => :project, :action => :status unless @project.is_remote? or @is_maintenance_project %>
<%= tab 'status', 'Status', :controller => :project, :action => :status unless @project.defines_remote_instance? or @is_maintenance_project %>
<% end -%>
</ul>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/views/webui/project/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<%= render partial: 'shared/open_requests' %>
<% if @project.is_remote? %>
<% if @project.defines_remote_instance? %>
<li>
<%= sprite_tag 'information' %>
Links against the remote OBS instance at: <i><%= link_to_if(@project.remoteurl,
Expand Down Expand Up @@ -110,7 +110,7 @@
</li>
<% end -%>
<% if User.current.can_modify_project?(@project, true) %>
<% unless @project.is_remote? %>
<% unless @project.defines_remote_instance? %>
<% if @is_incident_project && @packages.present? && @has_patchinfo && @open_release_requests.blank? %>
<li>
<%= link_to(sprited_text('brick_go', 'Request to release'), { controller: 'project', action: 'release_request_dialog', project: @project }, remote: true) %>
Expand Down

0 comments on commit a06b1ad

Please sign in to comment.