Sha256: be8f8fcd47d09861dfbe9fa519c854ad8cabae573101fe2cf0e469da1ed5f975

Contents?: true

Size: 1.4 KB

Versions: 23

Compression:

Stored size: 1.4 KB

Contents

module RedmineCrm
  module Liquid
    class UsersDrop < ::Liquid::Drop

      def self.default_drop
        self.new User.sorted
      end

      def initialize(users)
        @users = users
      end

      def before_method(login)
        user = @users.where(:login => login).first || User.new
        UserDrop.new user
      end

      def current
        UserDrop.new User.current
      end

      def all
        @all ||= @users.map do |user|
          UserDrop.new user
        end
      end

      def each(&block)
        all.each(&block)
      end

      def size
        @users.size
      end
    end

    class UserDrop < ::Liquid::Drop
      delegate :id, :name, :firstname, :lastname, :mail, :active?, :admin?, :logged?, :language, :to => :@user, allow_nil: true

      def initialize(user)
        @user = user
      end

      def avatar
        ApplicationController.helpers.avatar(@user)
      end

      def permissions
        roles = @user.memberships.collect { |m| m.roles }.flatten.uniq
        roles << (@user.logged? ? Role.non_member : Role.anonymous)
        roles.map(&:permissions).flatten.uniq.map(&:to_s)
      end

      def groups
        @user.groups.map(&:name)
      end

      def projects
        ProjectsDrop.new @user.memberships.map(&:project).flatten.select(&:visible?).uniq
      end

      def custom_field_values
        @user.custom_field_values
      end         
      
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
redmine_crm-0.0.63 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.62 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.61 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.60 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.59 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.58 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.57 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.56 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.55 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.54 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.53 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.52 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.51 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.50 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.49 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.48 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.47 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.46 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.45 lib/redmine_crm/liquid/drops/users_drop.rb
redmine_crm-0.0.44 lib/redmine_crm/liquid/drops/users_drop.rb