rosa-build/app/controllers/application_controller.rb

64 lines
1.6 KiB
Ruby
Raw Normal View History

2011-10-18 19:31:59 +01:00
# coding: UTF-8
2011-03-09 13:13:36 +00:00
class ApplicationController < ActionController::Base
protect_from_forgery
layout :layout_by_resource
2011-10-18 19:31:59 +01:00
private
def checkright(role_id)
@role=Role.find(role_id)
if @role.name.downcase!="admin"
@c = self.controller_name
@a = self.action_name
case @c
when "projects"
case @a
when "new", "show", "create"
@right=1,2
when "build", "process_build"
@right=3
end
when "repositories"
case @a
when "show"
@right=4
when "add_project", "remove_project"
@right=5
when "new", "create"
@right=6
end
when "platforms"
case @a
when "edit", "update", "freeze", "unfreeze"
@right=7
end
else return true
end
Permission.where(:role_id => @role.id, :right_id => @right).first
@ok=false if @permission.nil?
if not @ok
flash[:notice] = t('layout.not_access')
redirect_to(:back)
end
end
end
protected
def layout_by_resource
if devise_controller?
"sessions"
else
"application"
end
end
2011-04-11 13:56:22 +01:00
def authenticate_build_service!
if request.remote_ip != APP_CONFIG['build_service_ip']
render :nothing => true, :status => 403
end
end
def authenticate_product_builder!
if request.remote_ip != APP_CONFIG['product_builder_ip']
2011-04-11 13:56:22 +01:00
render :nothing => true, :status => 403
end
end
2011-03-09 13:13:36 +00:00
end