[#604] Add simple Liquid drops for Projects and Principals
This commit is contained in:
parent
7261622196
commit
91914cb877
|
@ -0,0 +1,3 @@
|
|||
class PrincipalDrop < BaseDrop
|
||||
allowed_methods :name
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
class ProjectDrop < BaseDrop
|
||||
allowed_methods :name, :identifier
|
||||
end
|
|
@ -31,6 +31,10 @@ class Principal < ActiveRecord::Base
|
|||
|
||||
before_create :set_default_empty_values
|
||||
|
||||
def to_liquid
|
||||
PrincipalDrop.new(self)
|
||||
end
|
||||
|
||||
def name(formatter = nil)
|
||||
to_s
|
||||
end
|
||||
|
|
|
@ -83,6 +83,10 @@ class Project < ActiveRecord::Base
|
|||
named_scope :all_public, { :conditions => { :is_public => true } }
|
||||
named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } }
|
||||
|
||||
def to_liquid
|
||||
ProjectDrop.new(self)
|
||||
end
|
||||
|
||||
def initialize(attributes = nil)
|
||||
super
|
||||
|
||||
|
@ -131,6 +135,11 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# Is the project visible to the current user
|
||||
def visible?
|
||||
User.current.allowed_to?(:view_project, self)
|
||||
end
|
||||
|
||||
def self.allowed_to_condition(user, permission, options={})
|
||||
base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
||||
if perm = Redmine::AccessControl.permission(permission)
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class PrincipalDropTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@principal = Principal.generate!
|
||||
@drop = @principal.to_liquid
|
||||
end
|
||||
|
||||
|
||||
context "#name" do
|
||||
should "return the name" do
|
||||
assert_equal @principal.name, @drop.name
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class ProjectDropTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@project = Project.generate!
|
||||
User.current = @user = User.generate!
|
||||
@role = Role.generate!
|
||||
Member.generate!(:principal => @user, :project => @project, :roles => [@role])
|
||||
@drop = @project.to_liquid
|
||||
end
|
||||
|
||||
context "drop" do
|
||||
should "be a ProjectDrop" do
|
||||
assert @drop.is_a?(ProjectDrop), "drop is not a ProjectDrop"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "#name" do
|
||||
should "return the project name" do
|
||||
assert_equal @project.name, @drop.name
|
||||
end
|
||||
end
|
||||
|
||||
context "#identifier" do
|
||||
should "return the project identifier" do
|
||||
assert_equal @project.identifier, @drop.identifier
|
||||
end
|
||||
end
|
||||
|
||||
should "only load an object if it's visible to the current user" do
|
||||
assert User.current.logged?
|
||||
assert @project.visible?
|
||||
|
||||
@private_project = Project.generate!(:is_public => false)
|
||||
|
||||
assert !@private_project.visible?, "Project is visible"
|
||||
@private_drop = ProjectDrop.new(@private_project)
|
||||
assert_equal nil, @private_drop.instance_variable_get("@object")
|
||||
assert_equal nil, @private_drop.name
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue