Class: PinnedLinksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pinned_links_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#dashboard, #keyboard_tools, #upload

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/pinned_links_controller.rb', line 28

def create
  @link = PinnedLink.create pinned_link_params

  attr = @link.attributes_print
  AuditLog.moderator_audit(event_type: 'pinned_link_create', related: @link, user: current_user,
                           comment: "<<PinnedLink #{attr}>>")

  flash[:success] = 'Your pinned link has been created. Due to caching, it may take some time until it is shown.'
  redirect_to pinned_links_path
end

#editObject



39
40
41
42
43
# File 'app/controllers/pinned_links_controller.rb', line 39

def edit
  if !current_user.is_global_moderator && @link.community_id != RequestContext.community_id
    not_found
  end
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/pinned_links_controller.rb', line 5

def index
  links = if current_user.is_global_moderator && params[:global] == '2'
            PinnedLink.unscoped
          elsif current_user.is_global_moderator && params[:global] == '1'
            PinnedLink.where(community: nil)
          else
            PinnedLink.where(community: @community)
          end
  @links = case params[:filter]
           when 'all'
             links.all
           when 'inactive'
             links.where(active: false).all
           else
             links.where(active: true).all
           end
  render layout: 'without_sidebar'
end

#newObject



24
25
26
# File 'app/controllers/pinned_links_controller.rb', line 24

def new
  @link = PinnedLink.new
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/pinned_links_controller.rb', line 45

def update
  if !current_user.is_global_moderator && @link.community_id != RequestContext.community_id
    return not_found
  end

  before = @link.attributes_print
  @link.update pinned_link_params
  after = @link.attributes_print
  AuditLog.moderator_audit(event_type: 'pinned_link_update', related: @link, user: current_user,
                           comment: "from <<PinnedLink #{before}>>\nto <<PinnedLink #{after}>>")

  flash[:success] = 'The pinned link has been updated. Due to caching, it may take some time until it is shown.'
  redirect_to pinned_links_path
end