debian-mirror-gitlab/app/helpers/broadcast_messages_helper.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.5 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module BroadcastMessagesHelper
2022-05-07 20:08:51 +05:30
include Gitlab::Utils::StrongMemoize
2020-03-13 15:44:24 +05:30
def current_broadcast_banner_messages
2022-05-07 20:08:51 +05:30
BroadcastMessage.current_banner_messages(
current_path: request.path,
user_access_level: current_user_access_level_for_project_or_group
).select do |message|
2020-04-08 14:13:33 +05:30
cookies["hide_broadcast_message_#{message.id}"].blank?
end
2020-01-01 13:55:28 +05:30
end
2020-03-13 15:44:24 +05:30
def current_broadcast_notification_message
2022-05-07 20:08:51 +05:30
not_hidden_messages = BroadcastMessage.current_notification_messages(
current_path: request.path,
user_access_level: current_user_access_level_for_project_or_group
).select do |message|
2020-04-08 14:13:33 +05:30
cookies["hide_broadcast_message_#{message.id}"].blank?
2020-03-13 15:44:24 +05:30
end
not_hidden_messages.last
end
def broadcast_message(message, opts = {})
return unless message.present?
2022-06-21 17:19:12 +05:30
render "shared/broadcast_message", { message: message, **opts }
end
def broadcast_message_status(broadcast_message)
if broadcast_message.active?
'Active'
elsif broadcast_message.ended?
'Expired'
else
'Pending'
end
2014-09-02 18:07:02 +05:30
end
2016-04-02 18:10:28 +05:30
2016-11-03 12:29:30 +05:30
def render_broadcast_message(broadcast_message)
2020-04-22 19:07:51 +05:30
if broadcast_message.notification?
Banzai.render_field_and_post_process(broadcast_message, :message, {
2020-04-08 14:13:33 +05:30
current_user: current_user,
skip_project_check: true,
broadcast_message_placeholders: true
}).html_safe
else
Banzai.render_field(broadcast_message, :message).html_safe
end
2016-04-02 18:10:28 +05:30
end
2020-03-13 15:44:24 +05:30
def broadcast_type_options
BroadcastMessage.broadcast_types.keys.map { |w| [w.humanize, w] }
end
2022-05-07 20:08:51 +05:30
2022-06-21 17:19:12 +05:30
def broadcast_theme_options
BroadcastMessage.themes.keys
end
2022-05-07 20:08:51 +05:30
def target_access_level_options
BroadcastMessage::ALLOWED_TARGET_ACCESS_LEVELS.map do |access_level|
[Gitlab::Access.human_access(access_level), access_level]
end
end
def target_access_levels_display(access_levels)
access_levels.map do |access_level|
Gitlab::Access.human_access(access_level)
end.join(', ')
end
private
def current_user_access_level_for_project_or_group
2022-07-16 23:28:13 +05:30
return if Feature.disabled?(:role_targeted_broadcast_messages)
2022-05-07 20:08:51 +05:30
return unless current_user.present?
strong_memoize(:current_user_access_level_for_project_or_group) do
2023-01-13 00:05:48 +05:30
case controller
when Projects::ApplicationController
2022-05-07 20:08:51 +05:30
next unless @project
@project.team.max_member_access(current_user.id)
2023-01-13 00:05:48 +05:30
when Groups::ApplicationController
2022-05-07 20:08:51 +05:30
next unless @group
@group.max_member_access_for_user(current_user)
end
end
end
2014-09-02 18:07:02 +05:30
end