diff --git a/app/assets/stylesheets/widgets.css b/app/assets/stylesheets/widgets.css index eb66b33b..a44824c0 100644 --- a/app/assets/stylesheets/widgets.css +++ b/app/assets/stylesheets/widgets.css @@ -53,11 +53,11 @@ display:inline-block; margin-right: 5px; opacity: 0.8; - filter: alpha(opacity:80); + filter: alpha(opacity=80); } .action:hover { opacity: 1; - filter: alpha(opacity:80); + filter: alpha(opacity=80); cursor: pointer; } .select-role { diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb index 50bbd1aa..991f19af 100644 --- a/app/controllers/admin/dashboards_controller.rb +++ b/app/controllers/admin/dashboards_controller.rb @@ -30,7 +30,7 @@ class Admin::DashboardsController < ApplicationController module_app_class = module_app.classify.constantize objects = module_app_class.order_by(:updated_at, :desc).limit(10) objects.each do |object| - a.merge!(object => object.updated_at) + a.merge!(object => object.updated_at) unless (object.archived rescue nil) end end sorted_objects = a.sort {|a,b| b[1]<=>a[1]} @@ -43,7 +43,7 @@ class Admin::DashboardsController < ApplicationController module_app_class = module_app.classify.constantize objects = module_app_class.order_by(:view_count, :desc).limit(10) objects.each do |object| - a.merge!(object => object.view_count) if object.view_count > 0 + a.merge!(object => object.view_count) if object.view_count > 0 && (!object.archived rescue true) end end sorted_objects = a.sort {|a,b| b[1]<=>a[1]} diff --git a/app/controllers/admin/module_apps_new_interface_controller.rb b/app/controllers/admin/module_apps_new_interface_controller.rb index 404ac693..57767d5f 100644 --- a/app/controllers/admin/module_apps_new_interface_controller.rb +++ b/app/controllers/admin/module_apps_new_interface_controller.rb @@ -39,7 +39,7 @@ class Admin::ModuleAppsNewInterfaceController < OrbitBackendController def update_setting_by_params user_sat = [] ma = ModuleApp.find params[:module_app][:id] - user_sat = User.find params[:users].keys if params.has_key? :users + user_sat += User.find params[:users].keys if params.has_key?('users') users_to_new = user_sat - ma.managing_users users_to_remove = ma.managing_users - user_sat diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f9c1577f..1455619a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -43,9 +43,59 @@ class ApplicationController < ActionController::Base @parent_item = Item.first(:conditions => { :id => BSON::ObjectId(params[:parent_id]) }) rescue nil end + def auth_failed_in_backend + #redirect_to admin_dashboards_url + redirect_to root_path + end + # Check if the current_user is admin def is_admin? - redirect_to root_url unless current_user.admin? + current_user.admin? ? true : auth_failed_in_backend + end + + def is_manager? + @module_app.managing_users.include?(current_user) || is_admin? + end + + def for_admin_only + if is_admin? + true + else + flash[:error] = t("admin.access.denied.not_admin") + auth_failed_in_backend + end + end + + def for_app_manager + if is_manager? + true + else + flash[:error] = t("admin.access.denied.app.not_manager") + auth_failed_in_backend + end + end + + def for_app_sub_manager + if (@module_app.sub_managing_users.include?(current_user) || is_manager?) + true + else + flash[:error] = t("admin.access.denied.app.not_sub_manager") + auth_failed_in_backend + end + end + + def for_app_user + if (@module_app.app_auth.auth_users.include?(current_user) || for_app_sub_manager ) + true + else + flash[:error] = t("admin.access.denied.app.not_authed_user") + auth_failed_in_backend + end + end + + def check_object_premission(obj,title) + flash[:error] = t("admin.access.denied.object") + auth_failed_in_backend unless (obj.get_object_auth_by_title(title).auth_users.include?(current_user) || is_manager? || is_admin? ) end # Render the page @@ -82,8 +132,8 @@ class ApplicationController < ActionController::Base # set site if exist or create site @site = Site.first || Site.create({:valid_locales => [], :in_use_locales => []}) session[:site] = @site.id - @site_in_use_locales = @site.in_use_locales - @site_valid_locales = @site.valid_locales + @site_in_use_locales = site_locales_default_head(@site.in_use_locales) + @site_valid_locales = site_locales_default_head(@site.valid_locales) end def set_current_item @@ -118,4 +168,14 @@ class ApplicationController < ActionController::Base end end + def site_locales_default_head(locales) + if locales[0].eql? I18n.locale.to_s + locales + else + a = Array.new(locales) + shift_out = a.delete(I18n.locale.to_s) + [shift_out] + a + end + end + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fc93c29a..8f651392 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -181,7 +181,7 @@ module ApplicationHelper end def display_visitors(options={}) - Impression.where(options).distinct(:session_hash).count + Impression.where(options).and(:referrer.ne => nil).distinct(:session_hash).count end def display_visitors_today diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 31f6e483..9cbd9967 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -31,7 +31,14 @@ class User end scope :remote_account, where(:nccu_id.ne => nil) - + + def self.current + Thread.current[:user] + end + + def self.current=(user) + Thread.current[:user] = user + end def avb_apps sub_role_ids_ary=self.sub_roles.collect{|t| t.id} diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 8757fe31..13c428ab 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -2,8 +2,6 @@