Project

General

Profile

Defect #34029 » patch.diff

Vincent Robert, 2020-09-24 15:06

View differences:

app/models/principal.rb
project.is_a?(Project) && project_ids.include?(project.id)
end
def roles
@roles ||= Role.joins(members: :project).where(["#{Project.table_name}.status <> ?", Project::STATUS_ARCHIVED]).where(Member.arel_table[:user_id].eq(id)).distinct
end
# Returns an array of the project ids that the principal is a member of
def project_ids
@project_ids ||= super.freeze
app/models/user.rb
@membership_by_project_id[project_id]
end
def roles
@roles ||= Role.joins(members: :project).where(["#{Project.table_name}.status <> ?", Project::STATUS_ARCHIVED]).where(Member.arel_table[:user_id].eq(id)).distinct
end
# Returns the user's bult-in role
def builtin_role
@builtin_role ||= Role.non_member
......
return true if admin?
# authorize if user has at least one role that has this permission
roles = self.roles.to_a | [builtin_role]
roles = self.roles.to_a | [builtin_role] | Group.non_member.roles.to_a | Group.anonymous.roles.to_a
roles.any? {|role|
role.allowed_to?(action) &&
(block_given? ? yield(role, self) : true)
test/system/issues_test.rb
assert_equal 'Some description', issue.attachments.first.description
end
def test_create_issue_with_attachment_when_user_is_not_a_member
set_tmp_attachments_directory
# Set no permission to non-member role
non_member_role = Role.where(:builtin => Role::BUILTIN_NON_MEMBER).first
non_member_role.permissions = []
non_member_role.save
# Set role "Reporter" to non-member users on project ecookbook
membership = Member.find_or_create_by(user_id: Group.non_member.id, project_id: 1)
membership.roles = [Role.find(3)] # Reporter
membership.save
log_user('someone', 'foo')
issue = new_record(Issue) do
visit '/projects/ecookbook/issues/new'
fill_in 'Subject', :with => 'Issue with attachment'
attach_file 'attachments[dummy][file]', Rails.root.join('test/fixtures/files/testfile.txt')
fill_in 'attachments[1][description]', :with => 'Some description'
click_on 'Create'
end
assert_equal 1, issue.attachments.count
assert_equal 'Some description', issue.attachments.first.description
end
def test_create_issue_with_new_target_version
log_user('jsmith', 'jsmith')
(2-2/3)