registered-sites/app/controllers/admin/registered_sites_controller.rb

59 lines
1.6 KiB
Ruby

# encoding: utf-8
class Admin::RegisteredSitesController < OrbitAdminController
before_action ->(module_app = @app_title) { set_variables module_app }
def index
@registeredsites = RegisteredSite.all.order_by(sort)
.with_categories(filters("category"))
.with_tags(filters("tag"))
@table_fields = table_fields
@tags = @module_app.tags
@categories = @module_app.categories.enabled
@filter_fields = filter_fields_without_status(@categories, @tags)
@registeredsites = search_data(@registeredsites,[:title]).page(params[:page]).per(10)
if request.xhr?
render :partial => "index"
end
end
def edit
@registered_site = RegisteredSite.find(params[:id])
if can_edit_or_delete?(@registered_site)
else
render_401
end
end
def update
uid = params[:id].split('-').last
registered_site = RegisteredSite.find_by(:uid => uid)
registered_site.update_attributes(registered_site_params)
registered_site.save
redirect_to params['referer_url']
end
def change_access_status
status = params[:status]
site = RegisteredSite.find_by(:uid => params[:uid])
case status
when "revoke"
site.access_granted = false
site.save
when "grant"
site.access_granted = true
site.save
end
@table_fields = table_fields
@registeredsites = RegisteredSite.all.page(params[:page]).per(10)
# render :partial => "index"
end
private
def table_fields
[:domain, :admin_email, :status, :category, :tags, :permission]
end
def registered_site_params
params.require(:registered_site).permit!
end
end