Sha256: cc0857d308385bfde951eff7890c9437e92d85814d114b5d44a6502c930f6dc7

Contents?: true

Size: 1.5 KB

Versions: 83

Compression:

Stored size: 1.5 KB

Contents

module Tenon
  class UsersController < Tenon::ResourcesController
    before_filter :get_roles, only: [:new, :edit, :update, :create]

    def index
      respond_to do |format|
        format.html
        format.json do
          if current_user.is_super_admin?
            @users = Tenon::User.all
          elsif current_user.is_admin?
            @users = Tenon::User.exclude_super_admins
          end

          @users = @users.where(search_args) unless params[:q].blank?
          @users = @users.paginate(per_page: 20, page: params[:page])
          @users = Tenon::PaginatingDecorator.new(@users)
        end
      end
    end

    def update
      if params[:user][:password].blank?
        params[:user].delete('password')
        params[:user].delete('password_confirmation')
      end
      super
    end

    private

    def get_roles
      @roles = Tenon::Role.all
    end

    def search_args
      ['email ILIKE ?', "%#{params[:q]}%"]
    end

    def resource_params
      if current_user.is_admin? || current_user.is_super_admin?
        cleaned_role_ids(params.require(:user).permit!)
      else
        untrusted_params
      end
    end

    def cleaned_role_ids(rp)
      sa_role = Tenon::Role.find_by_title('Super Admin')
      if sa_role && rp[:role_ids] && !current_user.is_super_admin?
        rp[:role_ids].delete(sa_role.id.to_s)
      end
      rp
    end

    def untrusted_params
      params.require(:user).permit(
        :email,
        :password,
        :password_confirmation
      )
    end
  end
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
tenon-1.1.8 app/controllers/tenon/users_controller.rb
tenon-1.1.7 app/controllers/tenon/users_controller.rb
tenon-1.1.6 app/controllers/tenon/users_controller.rb
tenon-1.1.5 app/controllers/tenon/users_controller.rb
tenon-1.1.4 app/controllers/tenon/users_controller.rb
tenon-1.1.3 app/controllers/tenon/users_controller.rb
tenon-1.1.2 app/controllers/tenon/users_controller.rb
tenon-1.1.1 app/controllers/tenon/users_controller.rb
tenon-1.0.76 app/controllers/tenon/users_controller.rb
tenon-1.0.75 app/controllers/tenon/users_controller.rb
tenon-1.0.74 app/controllers/tenon/users_controller.rb
tenon-1.0.73 app/controllers/tenon/users_controller.rb
tenon-1.0.72 app/controllers/tenon/users_controller.rb
tenon-1.0.71 app/controllers/tenon/users_controller.rb
tenon-1.0.70 app/controllers/tenon/users_controller.rb
tenon-1.0.69 app/controllers/tenon/users_controller.rb
tenon-1.0.68 app/controllers/tenon/users_controller.rb
tenon-1.0.67 app/controllers/tenon/users_controller.rb
tenon-1.0.66 app/controllers/tenon/users_controller.rb
tenon-1.0.65 app/controllers/tenon/users_controller.rb