Project

General

Profile

Feature #29048 » restrict_access_macro_v2.rb

Bernhard Rohloff, 2018-06-22 13:45

 
1
Redmine::WikiFormatting::Macros.register do
2
  desc "Restricts content access to specific project role IDs. Example {{restrict_access(1,2,4) Only for DevOps team.}}"
3
  macro :restrict_access do |obj, args, text|
4
    if User.current.logged?
5
      membership = User.current.membership(@project)
6
      if ( membership != nil ) 
7

    
8
        permitted_roles = args.to_a
9
        permitted_roles.map!{ |e| e.to_i }
10

    
11
        project_roles = membership.roles.to_a
12
        project_roles.map!{ |e| e.id }
13

    
14
        matching_roles = project_roles & permitted_roles
15

    
16
        if matching_roles.any?
17
          out = h( textilizable( text, :attachments => obj.attachments ) ) 
18
        else
19
          out = h( "Access prohibited - role is not permitted" )
20
        end 
21
      elsif (User.current.admin?)
22
        out = h(textilizable(text))
23
      else
24
        out = h( "Access prohibited - no project member" )
25
      end 
26
    else
27
      out = h( "Access prohibited - not logged in" )
28
    end 
29
  end 
30
end
31

    
(2-2/2)