Sha256: 42a5a2b0f6e4d286a3ce62c816e8ca56e1053e5c3e7bba8427e52ae8063c4a6e

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    class Permissions < Decidim::DefaultPermissions
      def permissions
        return permission_action unless user

        # Delegate the admin permission checks to the admin permissions class
        return Decidim::Meetings::Admin::Permissions.new(user, permission_action, context).permissions if permission_action.scope == :admin
        return permission_action if permission_action.scope != :public

        return permission_action if permission_action.subject != :meeting

        case permission_action.action
        when :join
          toggle_allow(can_join_meeting?)
        when :leave
          toggle_allow(can_leave_meeting?)
        end

        permission_action
      end

      private

      def meeting
        @meeting ||= context.fetch(:meeting, nil)
      end

      def can_join_meeting?
        meeting.can_be_joined_by?(user) &&
          authorized?(:join)
      end

      def can_leave_meeting?
        meeting.registrations_enabled?
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-meetings-0.13.1 app/permissions/decidim/meetings/permissions.rb
decidim-meetings-0.12.2 app/permissions/decidim/meetings/permissions.rb
decidim-meetings-0.13.0 app/permissions/decidim/meetings/permissions.rb
decidim-meetings-0.12.1 app/permissions/decidim/meetings/permissions.rb
decidim-meetings-0.13.0.pre1 app/permissions/decidim/meetings/permissions.rb
decidim-meetings-0.12.0 app/permissions/decidim/meetings/permissions.rb
decidim-meetings-0.12.0.pre app/permissions/decidim/meetings/permissions.rb