Skip to content

Commit

Permalink
WIP: rebuild refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
saraycp authored and Dany Marcoux committed Apr 26, 2021
1 parent fb01143 commit 3f80986
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
10 changes: 6 additions & 4 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def self.check_access?(package)
Project.check_access?(package.project)
end

# This returns a package or nil
def self.check_cache(project, package, opts)
@key = { 'get_by_project_and_name' => 1, :package => package, :opts => opts }

Expand All @@ -131,6 +132,7 @@ def self.check_cache(project, package, opts)
else
project
end
# pid means package id
pid, old_pkg_time, old_prj_time = Rails.cache.read(@key)
if pid
pkg = Package.where(id: pid).includes(:project).first
Expand Down Expand Up @@ -170,13 +172,13 @@ def self.get_by_project_and_name(project, package, opts = {})
return pkg if pkg

prj = internal_get_project(project)
return unless prj # remote prjs
return unless prj # remote projects or can't find the project

if pkg.nil? && opts[:follow_project_links]
if opts[:follow_project_links]
pkg = prj.find_package(package, opts[:check_update_project])
elsif pkg.nil?
else
pkg = prj.update_instance.packages.find_by_name(package) if opts[:check_update_project]
pkg = prj.packages.find_by_name(package) if pkg.nil?
pkg ||= prj.packages.find_by_name(package)
end

# FIXME: Why is this returning nil (the package is not found) if _ANY_ of the
Expand Down
17 changes: 0 additions & 17 deletions src/api/app/models/token/rebuild.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,6 @@ def call(params)

Backend::Api::Sources::Package.rebuild(project_name, package_name, params)
end

# authorization needs to check:
# sourceaccess => package.check_source_access?
# follow_multibuild => already handled by backend (packages names with '*:' in the name)

opts = if @token.instance_of?(Token::Rebuild)
{ use_source: false,
follow_project_links: true,
follow_multibuild: true }
else
{ use_source: true,
follow_project_links: false,
follow_multibuild: false }
end

@pkg = Package.get_by_project_and_name(params[:project].to_s, params[:package].to_s, opts)

end

####
Expand Down
27 changes: 27 additions & 0 deletions src/api/app/policies/token/rebuild_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Token
class RebuildPolicy < ApplicationPolicy

# When are people allowed to rebuild?
# - the token's user has access to the package

def initialize(user, record, opts = {})
super(user, record)
end

def create?
user.can_modify?(record)
end
end
end

# authorization needs to check:
# use_source => ends up checking sourceaccess (package.check_source_access?)
# follow_multibuild => already handled by backend (packages names with '*:' in the name)
# follow_project_links => only rebuild can follow the links, the inherited packages can also be rebuilt

# if not rebuilt then don't follow project links
# opts = { use_source: false,
# follow_project_links: true,
# follow_multibuild: true }
# Package.get_by_project_and_name(params[:project].to_s, params[:package].to_s, opts)

0 comments on commit 3f80986

Please sign in to comment.