Sha256: 8e73a351d3e02661b8cc20b8c728886baefdbb80108ed004d1ced94a6dbb2bb9

Contents?: true

Size: 633 Bytes

Versions: 2

Compression:

Stored size: 633 Bytes

Contents

module Lita
  module Authorization
    class << self
      def add_user_to_group(user, group)
        return unless user_is_admin?(user)
        redis.sadd(group, user.id)
      end

      def remove_user_from_group(user, group)
        return unless user_is_admin?(user)
        redis.srem(group, user.id)
      end

      def user_in_group?(user, group)
        redis.sismember(group, user.id)
      end

      def user_is_admin?(user)
        Array(Lita.config.robot.admins).include?(user.id)
      end

      private

      def redis
        @redis ||= Redis::Namespace.new("auth", redis: Lita.redis)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lita-1.1.0 lib/lita/authorization.rb
lita-1.0.0 lib/lita/authorization.rb