Last active
December 15, 2015 15:10
-
-
Save mdeniz/8f6c74927cf6ce9dd756 to your computer and use it in GitHub Desktop.
RemoteProject and Project changes to manage them like same kind of objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Update this methods in the Project class | |
class Project | |
def is_remote? | |
false | |
end | |
# returns an object of project(local or remote) or raises an exception | |
def self.get_by_name(project_name, options = {}) | |
project = find_by(name: project_name) | |
project = RemoteProject.find_by(name: project_name) unless project | |
raise UnknownObjectError, project_name unless project | |
# TODO: Verify how should be check the access on remote projects | |
# This permissions checking should be outside the model | |
if options[:includeallpackages] && !project.is_remote? | |
Package.joins(:flags).where(project_id: project.id).where("flags.flag='sourceaccess'").each do |package| | |
raise ReadAccessError, project_name unless Package.check_access?(package) | |
end | |
end | |
raise ReadAccessError, project_name unless !project.is_remote? && check_access?(project.name) | |
project | |
end | |
def self.is_remote_project?(project_name, skip_access = false) | |
RemoteProject.exists?(project_name) | |
end | |
# check existence of a project (local or remote) | |
def self.exists_by_name(project_name) | |
local_project = find_by(name: project_name) | |
if local_project | |
check_access?(local_project.name) | |
else # TODO: Verify how should be check the access on remote projects | |
RemoteProject.exists?(project_name) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Remote projects: They are not in the DB, but we will have objects loaded from the backend that represent them | |
class RemoteProject | |
include ActiveModel::Model | |
include ActiveModel::Serializers::Xml | |
attr_accessor :name, :title, :description # TODO: put all the attributes needed for a remote project | |
# this is needed for the Xml Serializer | |
def attributes=(hash) | |
hash.each do |key, value| | |
send("#{key}=", value) | |
end | |
end | |
def attributes | |
{name: nil, title: nil, description: nil} # TODO: put all the attributes needed for a remote project | |
end | |
# Remote projects are readonly always, maybe they should raise an exception or just fill an error array | |
def destroy false end | |
def destroy! false end | |
def save false end | |
def save! false end | |
def is_remote? | |
true | |
end | |
def self.find_by(options = {}) | |
# TODO: Read from backend and fill attributes with that | |
project_name = options[:name] | |
xml = Suse::Backend.get() | |
self.from_xml(xml) | |
rescue ActiveXML::Transport::NotFoundError | |
nil | |
end | |
def self.exists?(project_name) | |
# TODO: Read from backend to check existence | |
name = options[:name] | |
Suse::Backend.get() | |
true | |
rescue ActiveXML::Transport::NotFoundError | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hm, which relationships are you talking about? A lot of them will be in the project XML you get from remote right? Can we make a list?