forked from saurabh/orbit4-5
authorizations for users done
This commit is contained in:
parent
33edfd779c
commit
399b519bea
|
@ -68,4 +68,5 @@ class OrbitAdminController < ApplicationController
|
|||
@user_authenticated_categories = current_user.is_admin? ? ["all"] : current_user.approved_categories.collect{|c| c.id}
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -136,6 +136,10 @@ module OrbitBackendHelper
|
|||
@user_authenticated_categories.include?obj.category_id
|
||||
end
|
||||
end
|
||||
|
||||
def render_401
|
||||
render "public/401"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
gem 'announcement', git: 'git@gitlab.tp.rulingcom.com:saurabh/announcement-test.git'
|
||||
gem 'ad_banner', git: 'git@gitlab.tp.rulingcom.com:saurabh/adbanner-test.git'
|
||||
gem 'announcement', path: '/Volumes/MyData/github/orbit4.5/new_modules/announcement'
|
||||
gem 'ad_banner', path: '/Volumes/MyData/github/orbit4.5/new_modules/adbanner-test'
|
||||
gem "archive", git: 'git@gitlab.tp.rulingcom.com:saurabh/archive.git'
|
||||
gem 'gallery', git: 'git@gitlab.tp.rulingcom.com:saurabh/gallery.git'
|
||||
gem 'gallery', path: '/Volumes/MyData/github/orbit4.5/new_modules/gallery'
|
||||
gem 'links', git: 'git@gitlab.tp.rulingcom.com:saurabh/links.git'
|
||||
gem 'page_content', git: 'git@gitlab.tp.rulingcom.com:saurabh/pagecontent.git'
|
||||
gem 'faq', git: 'git@gitlab.tp.rulingcom.com:saurabh/faq.git'
|
||||
|
|
|
@ -20,6 +20,15 @@ module OrbitApp
|
|||
return nil
|
||||
end
|
||||
|
||||
def find_by_url(url)
|
||||
@@registrations.each{|t|
|
||||
sb = t.get_side_bar
|
||||
links = sb.get_active_for_controllers rescue []
|
||||
return t if links.include?url
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def all
|
||||
return @@registrations
|
||||
end
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
module OrbitCoreLib
|
||||
module Preview
|
||||
def self.included(base)
|
||||
|
||||
# base.instance_eval("field :is_preview,type: Boolean,:default => false")
|
||||
# base.instance_eval("scope :not_preview,where(:is_preview=>false)")
|
||||
base.class_eval ("
|
||||
def to_preview
|
||||
raise 'Developer,please override to_preview method'
|
||||
|
@ -38,67 +35,7 @@ module OrbitCoreLib
|
|||
|
||||
end
|
||||
end
|
||||
# module ObjectAuthable
|
||||
# def self.included(base)
|
||||
# base.instance_eval("has_many :object_auths,as: :obj_authable,dependent: :delete")
|
||||
|
||||
# base.define_singleton_method :authed_for_user do |user,title = nil|
|
||||
# sub_role_ids_ary=user.sub_roles.collect{|t| t.id}
|
||||
# if title.nil?
|
||||
# auth_object_space = ObjectAuth.where(obj_authable_type: self.to_s)
|
||||
# else
|
||||
# auth_object_space = ObjectAuth.where(obj_authable_type: self.to_s,title: title)
|
||||
# end
|
||||
# query1 = auth_object_space.any_in({sub_role_ids: sub_role_ids_ary}).excludes(blocked_user_ids: user.id)
|
||||
# query2 = auth_object_space.any_of({all: true},{privilege_user_ids: user.id}).excludes(blocked_user_ids: user.id)
|
||||
# # query2 = auth_object_space.any_of({all: true},{privilege_user_ids: user.id},{role_ids: user.role_ids}).excludes(blocked_user_ids: user.id) #save for backup if something went wrong (0626 Matt)
|
||||
|
||||
# result = (query1 + query2).uniq
|
||||
# result.collect{|t| t.obj_authable}.delete_if{|val| val==nil}
|
||||
# end
|
||||
|
||||
# end
|
||||
|
||||
# def cur_user_is_sub_manager_of(title)
|
||||
# authed_users(title).include?(User.current)
|
||||
# end
|
||||
|
||||
# def module_app
|
||||
# ModuleApp.first(conditions: {:title => self.class::APP_NAME} )
|
||||
# end
|
||||
|
||||
# def pp_object
|
||||
# "Object Auth method 'pp_object' need to be defined for class #{self.class}"
|
||||
# end
|
||||
|
||||
# def get_object_auth_by_title(title)
|
||||
# oa = self.object_auths.where({title: title }).first
|
||||
# if oa.nil? #&& (self.class::ObjectAuthTitlesOptions.include? title)
|
||||
# oa = self.object_auths.create title: title
|
||||
# end
|
||||
# oa
|
||||
# end
|
||||
|
||||
# def authed_users(title=nil)
|
||||
# users = []
|
||||
# users = case title
|
||||
# when :all
|
||||
# ary = self.object_auths.collect{|t| t.auth_users}
|
||||
# ary.flatten!
|
||||
# when nil
|
||||
# if self.object_auths.count ==1
|
||||
# self.object_auths.first.auth_users_after_block_list rescue []
|
||||
# else
|
||||
# logger.info "Warning calling a auth commend without specificed value( has multi-auths ), return empty"
|
||||
# []
|
||||
# end
|
||||
# else
|
||||
# get_object_auth_by_title(title).auth_users rescue []
|
||||
# end
|
||||
# users
|
||||
# end
|
||||
|
||||
# end
|
||||
module ObjectTokenUtility
|
||||
def self.included(base)
|
||||
base.instance_eval("field :s_token")
|
||||
|
@ -129,6 +66,11 @@ module OrbitCoreLib
|
|||
def can_use
|
||||
@app_title ||= controller_path.split('/')[1].singularize rescue nil
|
||||
@module_app ||= ModuleApp.find_by(key: @app_title) rescue nil
|
||||
if @module_app.nil?
|
||||
o = OrbitApp::Module::Registration.find_by_url(controller_path)
|
||||
@app_title = o.key rescue nil
|
||||
@module_app ||= ModuleApp.find_by(key: @app_title) rescue nil
|
||||
end
|
||||
@module_authorized_users ||= Authorization.module_authorized_users(@module_app.id).pluck(:user_id) rescue nil
|
||||
authenticate_user
|
||||
check_user_can_use
|
||||
|
@ -144,7 +86,7 @@ module OrbitCoreLib
|
|||
permissions = {}
|
||||
@module_app.get_registration.get_side_bar.get_context_links.each do |link|
|
||||
l = (Rails.application.routes.url_helpers.send(link.path) rescue Rails.application.routes.url_helpers.send(link.path, {:module_app_id => @module_app.id}))
|
||||
if l == request.path
|
||||
if l == request.path.sub("/" + I18n.locale.to_s,"")
|
||||
permissions["link"] = l
|
||||
permissions["available_for"] = link.available_for
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue