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
|
2011-03-31 00:10:23 +01:00
|
|
|
layout :layout_by_resource
|
2011-10-18 19:31:59 +01:00
|
|
|
private
|
2011-10-19 21:19:45 +01:00
|
|
|
def get_role(object_id, object_type, target_id, target_type)
|
|
|
|
rel=Relation.where(:object_id=>object_id, :object_type=>object_type, :target_id=>target_id, :target_type=>target_type).first
|
2011-10-20 18:01:01 +01:00
|
|
|
return (rel) ? rel.roles : nil
|
2011-10-19 21:19:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def checkaccess
|
|
|
|
@roles=current_user.roles+current.user.groups.roles
|
|
|
|
@ok=false
|
|
|
|
@roles.each { |role| @ok=checkright(role.id) unless @ok }
|
|
|
|
unless @ok
|
|
|
|
flash[:notice] = t('layout.not_access')
|
|
|
|
redirect_to(:back)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-18 19:31:59 +01:00
|
|
|
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
|
2011-10-19 21:19:45 +01:00
|
|
|
return false
|
2011-10-18 19:31:59 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-03-31 00:10:23 +01:00
|
|
|
|
2011-10-14 21:45:58 +01:00
|
|
|
before_filter lambda { EventLog.current_controller = self }, :only => [:create, :destroy, :open_id] # :update
|
|
|
|
after_filter lambda { EventLog.current_controller = nil }
|
|
|
|
|
2011-03-31 00:10:23 +01:00
|
|
|
protected
|
|
|
|
def layout_by_resource
|
|
|
|
if devise_controller?
|
|
|
|
"sessions"
|
|
|
|
else
|
|
|
|
"application"
|
|
|
|
end
|
|
|
|
end
|
2011-04-11 13:56:22 +01:00
|
|
|
|
2011-04-11 14:04:03 +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
|