Sha256: f851236d2805d55084c88e9d7ef9dd98460b7538cfb222450365ea6455f68b22

Contents?: true

Size: 1.89 KB

Versions: 36

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # Controller that allows managing user groups at the admin panel.
    #
    class UserGroupsController < Decidim::Admin::ApplicationController
      layout "decidim/admin/users"

      def index
        authorize! :index, UserGroup
        @query = params[:q]
        @state = params[:state]

        @user_groups = Decidim::Admin::UserGroupsEvaluation.for(collection, @query, @state)
                                                           .page(params[:page]).per(15)
      end

      def verify
        @user_group = collection.find(params[:id])
        authorize! :verify, @user_group

        VerifyUserGroup.call(@user_group) do
          on(:ok) do
            flash[:notice] = I18n.t("user_group.verify.success", scope: "decidim.admin")
            redirect_back(fallback_location: decidim_admin.user_groups_path)
          end

          on(:invalid) do
            flash[:alert] = I18n.t("user_group.verify.invalid", scope: "decidim.admin")
            redirect_back(fallback_location: decidim_admin.user_groups_path)
          end
        end
      end

      def reject
        @user_group = collection.find(params[:id])
        authorize! :reject, @user_group

        RejectUserGroup.call(@user_group) do
          on(:ok) do
            flash[:notice] = I18n.t("user_group.reject.success", scope: "decidim.admin")
            redirect_back(fallback_location: decidim_admin.user_groups_path)
          end

          on(:invalid) do
            flash[:alert] = I18n.t("user_group.reject.invalid", scope: "decidim.admin")
            redirect_back(fallback_location: decidim_admin.user_groups_path)
          end
        end
      end

      private

      def collection
        UserGroup
          .includes(:memberships)
          .where(decidim_user_group_memberships: { decidim_user_id: current_organization.users })
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
decidim-admin-0.9.3 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.9.2 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.9.1 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.9.0 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.8.4 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.8.3 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.8.2 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.8.1 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.8.0 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.7.4 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.7.3 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.7.2 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.7.1 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.7.0 app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.6.8 app/controllers/decidim/admin/user_groups_controller.rb
decidim-0.6.8 decidim-admin/app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.6.7 app/controllers/decidim/admin/user_groups_controller.rb
decidim-0.6.7 decidim-admin/app/controllers/decidim/admin/user_groups_controller.rb
decidim-admin-0.6.6 app/controllers/decidim/admin/user_groups_controller.rb
decidim-0.6.6 decidim-admin/app/controllers/decidim/admin/user_groups_controller.rb