Module: Collavre::Concerns::Shareable

Extended by:
ActiveSupport::Concern
Included in:
Collavre::CreativesController
Defined in:
app/controllers/collavre/concerns/shareable.rb

Instance Method Summary collapse

Instance Method Details

#request_permissionObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/collavre/concerns/shareable.rb', line 6

def request_permission
  creative = @creative.effective_origin
  if creative.user == Current.user || creative.has_permission?(Current.user, :read)
    return head :unprocessable_entity
  end

  short_title = helpers.strip_tags(creative.effective_origin.description).truncate(10)
  creative_path = Collavre::Engine.routes.url_helpers.creative_path(creative, open_comments: true)
  creative_link = "[#{short_title}](#{creative_path})"

  inbox_creative = Creative.inbox_for(creative.user)
  system_topic = inbox_creative.system_topic(fallback_user: creative.user)
  msg = I18n.t(
    "inbox.permission_requested",
    user: Current.user.display_name,
    short_title: creative_link,
    locale: creative.user.locale || "en"
  )
  Comment.create!(
    creative: inbox_creative,
    topic: system_topic,
    content: msg,
    user: nil,
    skip_default_user: true
  )

  head :ok
end