2021-04-18 13:34:55 +02:00
# frozen_string_literal: true
2017-07-26 11:01:51 +02:00
module AdditionalsIssuesHelper
2020-08-03 15:08:33 +02:00
def author_options_for_select ( project , entity = nil , permission = nil )
scope = project . present? ? project . users . visible : User . active . visible
2021-04-18 13:34:55 +02:00
scope = scope . with_permission permission , project unless permission . nil?
2020-08-03 15:08:33 +02:00
authors = scope . sorted . to_a
unless entity . nil?
current_author_found = authors . detect { | u | u . id == entity . author_id_was }
if current_author_found . blank?
2020-08-09 10:11:52 +02:00
current_author = User . find_by id : entity . author_id_was
2020-08-03 15:08:33 +02:00
authors << current_author if current_author
end
end
2020-07-27 10:49:23 +02:00
2017-07-26 11:01:51 +02:00
s = [ ]
2018-09-24 11:28:20 +02:00
return s unless authors . any?
2021-04-18 13:34:55 +02:00
s << tag . option ( " << #{ l :label_me } >> " , value : User . current . id ) if authors . include? User . current
2017-07-26 11:01:51 +02:00
2020-08-03 15:08:33 +02:00
if entity . nil?
2017-07-26 11:01:51 +02:00
s << options_from_collection_for_select ( authors , 'id' , 'name' )
else
2020-08-03 15:08:33 +02:00
s << tag . option ( entity . author , value : entity . author_id , selected : true ) if entity . author && authors . exclude? ( entity . author )
s << options_from_collection_for_select ( authors , 'id' , 'name' , entity . author_id )
2017-07-26 11:01:51 +02:00
end
2020-08-09 10:11:52 +02:00
safe_join s
2017-07-26 11:01:51 +02:00
end
def show_issue_change_author? ( issue )
if issue . new_record? && User . current . allowed_to? ( :change_new_issue_author , issue . project ) ||
issue . persisted? && User . current . allowed_to? ( :edit_issue_author , issue . project )
true
end
end
end