diff --git a/Gemfile b/Gemfile index 5a9d2bbca..b57ecdbce 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source 'https://rubygems.org' gem 'rails', '4.0.4' +gem 'activeadmin', github: 'gregbell/active_admin' gem 'pg', '~> 0.17.1' gem 'schema_plus', '~> 1.4.0' ######## diff --git a/Gemfile.lock b/Gemfile.lock index f071bdfcc..f157f1d21 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,6 +8,24 @@ GIT resque (> 1.25) resque-scheduler +GIT + remote: git://github.com/gregbell/active_admin.git + revision: 5ac883c59978799829a8c085fab47f858574c42f + specs: + activeadmin (1.0.0.pre) + arbre (~> 1.0) + bourbon + coffee-rails + devise (~> 3.2) + formtastic (~> 2.3.0.rc2) + inherited_resources (~> 1.3) + jquery-rails + jquery-ui-rails + kaminari (~> 0.15) + rails (>= 3.2, <= 4.1) + ransack (~> 1.0) + sass-rails + GIT remote: git://github.com/rosa-abf/cancan.git revision: fe1089b70c08d3ed11bac4f8e69ecb3d1d9adc29 @@ -65,6 +83,8 @@ GEM activerecord (>= 3.0.0) angular-i18n (0.1.2) angularjs-rails (1.2.14) + arbre (1.0.1) + activesupport (>= 3.0.0) arel (4.0.2) atomic (1.1.16) attr_encrypted (1.3.2) @@ -82,6 +102,9 @@ GEM daemons (~> 1.1.4) i18n (>= 0.5.0) state_machine (~> 1.1) + bourbon (3.1.8) + sass (>= 3.2.0) + thor builder (3.1.4) callsite (0.0.11) cape (1.8.0) @@ -138,6 +161,8 @@ GEM faraday (0.9.0) multipart-post (>= 1.2, < 3) ffi (1.9.3) + formtastic (2.3.0.rc2) + actionpack (>= 3.0) friendly_id (5.0.3) activerecord (>= 4.0.0) fssm (0.2.10) @@ -168,11 +193,17 @@ GEM activesupport (>= 4.0.1) haml (>= 3.1, < 5.0) railties (>= 4.0.1) + has_scope (0.6.0.rc) + actionpack (>= 3.2, < 5) + activesupport (>= 3.2, < 5) hashie (2.0.5) highline (1.6.21) hike (1.2.3) hirb (0.7.1) i18n (0.6.9) + inherited_resources (1.4.1) + has_scope (~> 0.6.0.rc) + responders (~> 1.0.0.rc) jbuilder (2.0.4) activesupport (>= 3.0.0) multi_json (>= 1.2.0) @@ -180,12 +211,17 @@ GEM jquery-rails (2.3.0) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) + jquery-ui-rails (4.2.0) + railties (>= 3.2.16) js-routes (0.9.7) railties (>= 3.2) sprockets-rails json (1.8.1) jwt (0.1.11) multi_json (>= 1.5) + kaminari (0.15.1) + actionpack (>= 3.0.0) + activesupport (>= 3.0.0) libv8 (3.16.14.3) localeapp (0.7.1) gli @@ -272,6 +308,8 @@ GEM cocaine (~> 0.5.3) mime-types pg (0.17.1) + polyamorous (0.6.4) + activerecord (>= 3.0) polyglot (0.3.4) posix-spawn (0.3.8) protected_attributes (1.0.7) @@ -308,6 +346,12 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.1.1) + ransack (1.2.1) + actionpack (>= 3.0) + activerecord (>= 3.0) + activesupport (>= 3.0) + i18n + polyamorous (~> 0.6.0) rdiscount (2.1.7) redcarpet (3.1.1) redis (3.0.7) @@ -330,6 +374,8 @@ GEM redis-store (1.1.4) redis (>= 2.2) ref (1.0.5) + responders (1.0.0) + railties (>= 3.2, < 5) resque (1.25.2) mono_logger (~> 1.0) multi_json (~> 1.0) @@ -463,6 +509,7 @@ PLATFORMS DEPENDENCIES RedCloth + activeadmin! airbrake (~> 3.1.2) ancestry (~> 2.0.0) angular-i18n (= 0.1.2) diff --git a/app/admin/dashboards.rb b/app/admin/dashboards.rb new file mode 100644 index 000000000..a19c8caec --- /dev/null +++ b/app/admin/dashboards.rb @@ -0,0 +1,30 @@ +ActiveAdmin.register_page 'Dashboard' do + + menu priority: 1 + + content do + + columns do + column do + panel "Deploy Information" do + require 'deploy_info' + + abf = "https://abf.io/abf/rosa-build/" + #jenkins = "https://ci.shuttlerock.com/" + + attributes_table_for DeployInfo do + row('Branch') { link_to DeployInfo::BRANCH, "#{abf}tree/#{DeployInfo::BRANCH}" } + row('Commit') { link_to DeployInfo::GIT_COMMIT, "#{abf}commit/#{DeployInfo::GIT_COMMIT}" } + row('Build Number') { DeployInfo::BUILD_NUMBER } + row('Build ID') { DeployInfo::BUILD_ID } + row('Deployer') { DeployInfo::DEPLOYER } + row(:message) { pre DeployInfo.message } + end + end # panel + end # column + end # columns + + + end # content + +end diff --git a/app/admin/event_logs.rb b/app/admin/event_logs.rb new file mode 100644 index 000000000..2359d6aba --- /dev/null +++ b/app/admin/event_logs.rb @@ -0,0 +1,37 @@ +ActiveAdmin.register EventLog do + + menu parent: 'Misc' + + actions :all, except: %i(create update new edit destroy) + + controller do + def scoped_collection + EventLog.includes(:user) + end + end + + index do + column :id + column :kind + column :created_at + column :user + column :ip + column :protocol + column('Description') do |el| + msg = %w([) + msg << I18n.t("event_log.controllers.#{el.controller.underscore}", default: el.controller) << "]" + msg << I18n.t("event_log.actions.#{el.controller.underscore}.#{el.action}", default: :"event_log.actions.#{el.action}") + if el.eventable_id.present? and el.eventable_type.present? + msg << '' << I18n.t("activerecord.models.#{el.eventable_type.underscore}") + msg << el.eventable_name + msg << "(id##{el.eventable_id})" # link_to "id##{el.eventable_id}", el.eventable + end + msg << el.message.to_s + msg.join(' ') + end + + + default_actions + end + +end diff --git a/app/admin/flash_notifies.rb b/app/admin/flash_notifies.rb new file mode 100644 index 000000000..957e0429e --- /dev/null +++ b/app/admin/flash_notifies.rb @@ -0,0 +1,28 @@ +ActiveAdmin.register FlashNotify do + + menu parent: 'Misc' + + index do + column :id + column(:body_en) do |fn| + fn.body_en.truncate(18) + end + column(:body_ru) do |fn| + fn.body_ru.truncate(18) + end + column :published + + default_actions + end + + form do |f| + f.inputs do + f.input :body_en + f.input :body_ru + f.input :status, as: :select, collection: FlashNotify::STATUSES, include_blank: false + f.input :published + end + f.actions + end + +end diff --git a/app/admin/register_requests.rb b/app/admin/register_requests.rb new file mode 100644 index 000000000..f2374d391 --- /dev/null +++ b/app/admin/register_requests.rb @@ -0,0 +1,20 @@ +ActiveAdmin.register RegisterRequest do + + menu parent: 'Misc' + + index do + column :id + column :name + + column('User') do |request| + user = User.find_by(email: request.email) if request.approved + link_to(user.uname, admin_user_path(user)) if user + end + column :interest + column :more + column :created_at + + default_actions + end + +end diff --git a/app/admin/resque.rb b/app/admin/resque.rb new file mode 100644 index 000000000..2dfdc7105 --- /dev/null +++ b/app/admin/resque.rb @@ -0,0 +1,3 @@ +ActiveAdmin.register_page 'Resque' do + menu priority: 100, label: 'Resque', url: '/admin/resque/overview' +end \ No newline at end of file diff --git a/app/admin/users.rb b/app/admin/users.rb new file mode 100644 index 000000000..2c712520b --- /dev/null +++ b/app/admin/users.rb @@ -0,0 +1,56 @@ +ActiveAdmin.register User do + + menu priority: 2 + + filter :uname + filter :email + filter :role, as: :select, collection: User::EXTENDED_ROLES + filter :created_at + + controller do + def update(options={}, &block) + user_params = params[:user] + resource.role = user_params.delete(:role) + user_params.delete(:password) if user_params[:password].blank? + user_params.delete(:password_confirmation) if user_params[:password_confirmation].blank? + super + end + end + + index do + column :id + column(:uname) do |user| + link_to(user.uname, user_path(user)) + end + column :email + column :created_at + column :role + + default_actions + end + + form do |f| + f.inputs do + f.input :name + f.input :email + f.input :uname + f.input :role, as: :select, collection: User::EXTENDED_ROLES, include_blank: false + f.input :password + f.input :password_confirmation + end + f.actions + end + + action_item only: %i(show edit) do + link_to 'Reset token', reset_token_admin_user_path(resource), + 'data-method' => :put, + data: { confirm: 'Are you sure you want to reset token?' } + end + + member_action :reset_token, :method => :put do + resource.reset_authentication_token! + flash[:info] = 'User token reseted successfully' + redirect_to admin_user_path(resource) + end + +end diff --git a/app/assets/javascripts/active_admin.js.coffee b/app/assets/javascripts/active_admin.js.coffee new file mode 100644 index 000000000..3752dcef6 --- /dev/null +++ b/app/assets/javascripts/active_admin.js.coffee @@ -0,0 +1 @@ +#= require active_admin/base diff --git a/app/assets/stylesheets/active_admin.css.scss b/app/assets/stylesheets/active_admin.css.scss new file mode 100644 index 000000000..90ba1d475 --- /dev/null +++ b/app/assets/stylesheets/active_admin.css.scss @@ -0,0 +1,17 @@ +// SASS variable overrides must be declared before loading up Active Admin's styles. +// +// To view the variables that Active Admin provides, take a look at +// `app/assets/stylesheets/active_admin/mixins/_variables.css.scss` in the +// Active Admin source. +// +// For example, to change the sidebar width: +// $sidebar-width: 242px; + +// Active Admin's got SASS! +@import "active_admin/mixins"; +@import "active_admin/base"; + +// Overriding any non-variable SASS must be done after the fact. +// For example, to change the default status-tag color: +// +// .status_tag { background: #6090DB; } diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb deleted file mode 100644 index a1f559897..000000000 --- a/app/controllers/admin/base_controller.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Admin::BaseController < ApplicationController - before_filter :authenticate_user! - load_and_authorize_resource -end diff --git a/app/controllers/admin/event_logs_controller.rb b/app/controllers/admin/event_logs_controller.rb deleted file mode 100644 index e099acbb2..000000000 --- a/app/controllers/admin/event_logs_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Admin::EventLogsController < Admin::BaseController - def index - @event_logs = EventLog.default_order.eager_loading.paginate page: params[:page] - end -end diff --git a/app/controllers/admin/flash_notifies_controller.rb b/app/controllers/admin/flash_notifies_controller.rb deleted file mode 100644 index 97f2ca7e9..000000000 --- a/app/controllers/admin/flash_notifies_controller.rb +++ /dev/null @@ -1,41 +0,0 @@ -class Admin::FlashNotifiesController < Admin::BaseController - def index - @flash_notifies = FlashNotify.paginate(page: params[:page], per_page: 20) - end - - def new - @flash_notify = FlashNotify.new(published: true) - end - - def create - @flash_notify = FlashNotify.new(params[:flash_notify]) - if @flash_notify.save - flash[:notice] = t("flash.flash_notify.saved") - redirect_to admin_flash_notifies_path - else - flash[:error] = t("flash.flash_notify.save_error") - flash[:warning] = @flash_notify.errors.full_messages.join('. ') - render :new - end - end - - def update - if @flash_notify.update_attributes(params[:flash_notify]) - flash[:notice] = t("flash.flash_notify.saved") - redirect_to admin_flash_notifies_path - else - flash[:error] = t("flash.flash_notify.save_error") - flash[:warning] = @flash_notify.errors.full_messages.join('. ') - render :edit - end - end - - def destroy - if @flash_notify.destroy - flash[:notice] = t("flash.flash_notify.destroyed") - else - flash[:error] = t("flash.flash_notify.destroy_error") - end - redirect_to admin_flash_notifies_path - end -end diff --git a/app/controllers/admin/register_requests_controller.rb b/app/controllers/admin/register_requests_controller.rb deleted file mode 100644 index 0dda01db0..000000000 --- a/app/controllers/admin/register_requests_controller.rb +++ /dev/null @@ -1,20 +0,0 @@ -class Admin::RegisterRequestsController < Admin::BaseController - def index - @register_requests = @register_requests.send((params[:scope] || 'unprocessed').to_sym).paginate(page: params[:page]) - end - - def update - RegisterRequest.where(id: params[:request_ids]).each(¶ms[:update_type].to_sym) if params[:update_type].present? && params[:request_ids].present? - redirect_to action: :index - end - - def approve - @register_request.approve - redirect_to action: :index - end - - def reject - @register_request.reject - redirect_to action: :index - end -end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb deleted file mode 100644 index 84984d612..000000000 --- a/app/controllers/admin/users_controller.rb +++ /dev/null @@ -1,92 +0,0 @@ -class Admin::UsersController < Admin::BaseController - include AvatarHelper - prepend_before_filter :find_user - load_and_authorize_resource collection: [:system, :list] - - def index - @filter = params[:filter] || 'all' - end - - def system - @users, @filter = @users.system, 'system' - render :index - end - - def new - @user.role = 'system' if params[:system] == 'true' - end - - def create - @user.role = params[:role] - @user.email, @user.password = "#{@user.uname}@rosalinux.ru", SecureRandom.base64 if @user.system? - @user.confirmed_at = Time.now.utc - if (@user.save rescue false) - flash[:notice] = t('flash.user.saved') - flash[:warning] = @user.authentication_token - redirect_to(@user.system? ? system_admin_users_path : admin_users_path) - else - flash[:error] = t('flash.user.save_error') - flash[:warning] = @user.errors.full_messages.join('. ') - @system = @user.system? - - render action: :new - end - end - - def edit - end - - def update - @user.role = params[:role] - if @user.update_without_password(params[:user]) - update_avatar(@user, params) - flash[:notice] = t('flash.user.saved') - redirect_to admin_users_path - else - flash[:error] = t('flash.user.save_error') - flash[:warning] = @user.errors.full_messages.join('. ') - render action: :edit - end - end - - def destroy - @user.destroy - flash[:notice] = t("flash.user.destroyed") - redirect_to(@user.system? ? system_admin_users_path : admin_users_path) - end - - def list - if params[:system] != 'true' - colName, @users = %w(name uname email created_at), @users.opened - else - colName, @users, @system_list = ['uname'], @users.system, true - end - sort_col = params[:iSortCol_0] || 0 - sort_dir = params[:sSortDir_0]=="asc" ? 'asc' : 'desc' - order = "users.#{colName[sort_col.to_i]} #{sort_dir}" - - @users = @users.paginate(page: (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i).to_i + 1, per_page: params[:iDisplayLength]) - @total_users = @users.count - if !params[:sSearch].blank? && search = "%#{params[:sSearch]}%" - @users = @users.where('users.name ILIKE ? or users.uname ILIKE ? or users.email ILIKE ?', search, search, search) - end - @filter = params[:filter] || 'all' - @users = @users.send(@filter) if ['real', 'admin', 'banned', 'tester'].include? @filter - @users = @users.order(order) - - render partial: 'users_ajax', layout: false - end - - def reset_auth_token - @user.reset_authentication_token! - flash[:notice] = t("flash.user.reset_auth_token") - flash[:warning] = @user.authentication_token - redirect_to system_admin_users_path - end - - protected - - def find_user - @user = User.find_by!(uname: params[:id]) if params[:id].present? - end -end diff --git a/app/helpers/active_admin/admin_helper.rb b/app/helpers/active_admin/admin_helper.rb new file mode 100644 index 000000000..4cc19f59c --- /dev/null +++ b/app/helpers/active_admin/admin_helper.rb @@ -0,0 +1,10 @@ +module ActiveAdmin::AdminHelper + + include ActiveAdmin::Views + + def admin_polymorphic_path(resource) + self.send("admin_#{resource.class.to_s.underscore}_path", resource) + end + +end + diff --git a/app/models/user.rb b/app/models/user.rb index 3e84c89ec..ed10519fd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,7 @@ class User < Avatar + extend FriendlyId + friendly_id :uname, use: [:finders] + include PersonalRepository include ActsLikeMember include Feed::User diff --git a/app/views/admin/register_requests/index.html.haml b/app/views/admin/_register_requests/index.html.haml similarity index 100% rename from app/views/admin/register_requests/index.html.haml rename to app/views/admin/_register_requests/index.html.haml diff --git a/app/views/admin/users/_sidebar.html.haml b/app/views/admin/_users/_sidebar.html.haml similarity index 100% rename from app/views/admin/users/_sidebar.html.haml rename to app/views/admin/_users/_sidebar.html.haml diff --git a/app/views/admin/users/_users_ajax.json.jbuilder b/app/views/admin/_users/_users_ajax.json.jbuilder similarity index 100% rename from app/views/admin/users/_users_ajax.json.jbuilder rename to app/views/admin/_users/_users_ajax.json.jbuilder diff --git a/app/views/admin/users/edit.html.haml b/app/views/admin/_users/edit.html.haml similarity index 100% rename from app/views/admin/users/edit.html.haml rename to app/views/admin/_users/edit.html.haml diff --git a/app/views/admin/users/index.html.haml b/app/views/admin/_users/index.html.haml similarity index 100% rename from app/views/admin/users/index.html.haml rename to app/views/admin/_users/index.html.haml diff --git a/app/views/admin/users/new.html.haml b/app/views/admin/_users/new.html.haml similarity index 100% rename from app/views/admin/users/new.html.haml rename to app/views/admin/_users/new.html.haml diff --git a/app/views/admin/event_logs/_description.html.haml b/app/views/admin/event_logs/_description.html.haml deleted file mode 100644 index 9c53f2405..000000000 --- a/app/views/admin/event_logs/_description.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -= surround '[', ']' do - = I18n.t "event_log.controllers.#{el.controller.underscore}", default: el.controller -= I18n.t "event_log.actions.#{el.controller.underscore}.#{el.action}", default: :"event_log.actions.#{el.action}" -- if el.eventable_id.present? and el.eventable_type.present? - = I18n.t "activerecord.models.#{el.eventable_type.underscore}" - = el.eventable_name - = "(id##{el.eventable_id})" # link_to "id##{el.eventable_id}", el.eventable -= el.message diff --git a/app/views/admin/event_logs/_event_log.html.haml b/app/views/admin/event_logs/_event_log.html.haml deleted file mode 100644 index 91e8562e4..000000000 --- a/app/views/admin/event_logs/_event_log.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -%tr{class: cycle("odd", "even")} - %td= event_log.kind - %td= event_log.created_at - %td= link_to_if event_log.user_id, event_log.user_name, event_log.user #{controller: "users", action: "show", id: event_log.user_id} - %td= event_log.ip - %td= event_log.protocol - %td= render 'description', el: event_log \ No newline at end of file diff --git a/app/views/admin/event_logs/index.html.haml b/app/views/admin/event_logs/index.html.haml deleted file mode 100644 index 66057901e..000000000 --- a/app/views/admin/event_logs/index.html.haml +++ /dev/null @@ -1,14 +0,0 @@ -%h3.fix= title t("layout.event_logs.list_header") - -%table#datatable.tablesorter.list-users - %tr - %th.first= t("activerecord.attributes.event_log.kind") - %th= t("activerecord.attributes.event_log.created_at") - %th= t("activerecord.attributes.event_log.user") - %th= t("activerecord.attributes.event_log.ip") - %th= t("activerecord.attributes.event_log.protocol") - %th.last= t("activerecord.attributes.event_log.description") - = render @event_logs -= will_paginate - -= render 'submenu' diff --git a/app/views/admin/flash_notifies/_form.html.haml b/app/views/admin/flash_notifies/_form.html.haml deleted file mode 100644 index 46b41be64..000000000 --- a/app/views/admin/flash_notifies/_form.html.haml +++ /dev/null @@ -1,21 +0,0 @@ -.leftlist= f.label :body_ru, t("activerecord.attributes.flash_notify.body_ru"), class: :label -.rightlist= f.text_area :body_ru, class: 'text_field' -.both - -.leftlist= f.label :body_en, t("activerecord.attributes.flash_notify.body_en"), class: :label -.rightlist= f.text_area :body_en, class: 'text_field' -.both - -.leftlist= f.label :status, t("activerecord.attributes.flash_notify.status"), class: :label -.rightlist= f.select :status, FlashNotify::STATUSES -.both - -.leftlist= f.label :published, t("activerecord.attributes.flash_notify.published"), class: :label -.rightlist= f.check_box :published -.both - -.button_block - = submit_tag t('layout.save'), data: {'disable-with' => t('layout.saving')} - %span.text_button_padding= t("layout.or") - = link_to t("layout.cancel"), admin_flash_notifies_path, class: "button" - diff --git a/app/views/admin/flash_notifies/edit.html.haml b/app/views/admin/flash_notifies/edit.html.haml deleted file mode 100644 index 240d1cad4..000000000 --- a/app/views/admin/flash_notifies/edit.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -%h3= t("layout.flash_notifies.edit_header") - -= form_for @flash_notify, url: admin_flash_notify_path(@flash_notify), html: { class: :form } do |f| - = render "form", f: f - -= render 'submenu' diff --git a/app/views/admin/flash_notifies/index.html.haml b/app/views/admin/flash_notifies/index.html.haml deleted file mode 100644 index cb2d66698..000000000 --- a/app/views/admin/flash_notifies/index.html.haml +++ /dev/null @@ -1,22 +0,0 @@ -= link_to t("layout.flash_notifies.new"), new_admin_flash_notify_path, class: 'button' if can? :create, FlashNotify - -%table#myTable.tablesorter.flash_notifys{cellspacing: "0", cellpadding: "0"} - %thead - %tr - %th.th1= t("activerecord.attributes.flash_notify.body_en") - %th.th2= t("activerecord.attributes.flash_notify.body_ru") - %th.th3= t("activerecord.attributes.flash_notify.published") - %th.th3= t("layout.flash_notifies.actions") - %tbody - - @flash_notifies.each do |flash_notify| - %tr{class: cycle("odd", "even")} - %td= flash_notify.body_en.truncate 18 - %td= flash_notify.body_ru.truncate 18 - %td= flash_notify.published - %td - = link_to t("layout.flash_notifies.edit"), edit_admin_flash_notify_path(flash_notify) - = link_to t("layout.flash_notifies.delete"), admin_flash_notify_path(flash_notify), method: :delete, data: { confirm: t("layout.mass_builds.cancel_confirm") } if can?(:delete, flash_notify) - -= will_paginate @flash_notifies - -= render 'submenu' diff --git a/app/views/admin/flash_notifies/new.html.haml b/app/views/admin/flash_notifies/new.html.haml deleted file mode 100644 index c1f9ec45d..000000000 --- a/app/views/admin/flash_notifies/new.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -%h3= t("layout.flash_notifies.new_header") - -= form_for @flash_notify, url: admin_flash_notifies_path, html: { class: :form } do |f| - = render "form", f: f - -= render 'submenu' diff --git a/app/views/layouts/menu/_top.html.haml b/app/views/layouts/menu/_top.html.haml index af327be48..936e7a767 100644 --- a/app/views/layouts/menu/_top.html.haml +++ b/app/views/layouts/menu/_top.html.haml @@ -4,4 +4,4 @@ - if can? :index, base.to_s.classify.constantize %li= link_to title, send(:"#{namespace}#{base}_path"), class: top_menu_class(base) - if current_user.try(:admin?) and which_menu == 'top_menu' - %li= link_to t('admins_menu_header'), admin_users_path, class: top_menu_class('admin') \ No newline at end of file + %li= link_to t('admins_menu_header'), admin_root_path, class: top_menu_class('admin') \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 08dfc07f9..0af3dcd24 100644 --- a/config/application.rb +++ b/config/application.rb @@ -50,7 +50,9 @@ module Rosa config.encoding = "utf-8" # Enable the asset pipeline - config.assets.enabled = true + config.assets.enabled = true + config.assets.initialize_on_precompile = false # http://bit.ly/u7pQKz + config.assets.precompile += %w(active_admin.js active_admin.css) # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' diff --git a/config/initializers/active_admin.rb b/config/initializers/active_admin.rb new file mode 100644 index 000000000..877101fd9 --- /dev/null +++ b/config/initializers/active_admin.rb @@ -0,0 +1,91 @@ +ActiveAdmin.setup do |config| + + # == Site Title + # + # Set the title that is displayed on the main layout + # for each of the active admin pages. + # + config.site_title = "ABF" + + + # == Default Namespace + # + # Set the default namespace each administration resource + # will be added to. + # + # eg: + # config.default_namespace = :hello_world + # + # This will create resources in the HelloWorld module and + # will namespace routes to /hello_world/* + # + # To set no namespace by default, use: + # config.default_namespace = false + config.default_namespace = :admin + + + # == User Authentication + # + # Active Admin will automatically call an authentication + # method in a before filter of all controller actions to + # ensure that there is a currently logged in admin user. + # + # This setting changes the method which Active Admin calls + # within the controller. + config.authentication_method = :authenticate_user! + + + # == Current User + # + # Active Admin will associate actions with the current + # user performing them. + # + # This setting changes the method which Active Admin calls + # to return the currently logged in user. + config.current_user_method = :current_user + + + # == Admin Comments + # + # Admin comments allow you to add comments to any model for admin use + # + # Admin comments are enabled by default in the default + # namespace only. You can turn them on in a namesapce + # by adding them to the comments array. + # + # config.allow_comments_in = [:admin] + config.allow_comments = false + + + # == Controller Filters + # + # You can add before, after and around filters to all of your + # Active Admin resources from here. + # + # config.before_filter :do_something_awesome + config.before_filter :check_admin_role + + + # == Register Stylesheets & Javascripts + # + # We recommend using the built in Active Admin layout and loading + # up your own stylesheets / javascripts to customize the look + # and feel. + # + # To load a stylesheet: + # config.register_stylesheet 'my_stylesheet.css' + # + # To load a javascript file: + # config.register_javascript 'my_javascript.js' + + config.logout_link_path = :destroy_user_session_path +end + +# Block admin access to non-admin-users. +ActiveAdmin::BaseController.class_eval do + # include ActionController::Caching::Sweeping + protected + def check_admin_role + raise ActiveRecord::RecordNotFound unless current_user.admin? + end +end diff --git a/config/initializers/kaminari.rb b/config/initializers/kaminari.rb new file mode 100644 index 000000000..25279cf5f --- /dev/null +++ b/config/initializers/kaminari.rb @@ -0,0 +1,3 @@ +Kaminari.configure do |config| + config.page_method_name = :per_page_kaminari +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index c7ad7cf84..54e5e8797 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,14 @@ Rosa::Application.routes.draw do + # ActiveAdmin routes. + ActiveAdmin.routes(self) + + namespace :admin do + constraints Rosa::Constraints::AdminAccess do + mount Resque::Server => 'resque' + end + end + # Redirect sitemap1.xml.gz file on AWS S3 match '/sitemap.xml.gz' => 'sitemap#show', via: [:get, :post, :head], as: :sitemap match '/robots.txt' => 'sitemap#robots', via: [:get, :post, :head], as: :robots @@ -147,28 +156,6 @@ Rosa::Application.routes.draw do root to: 'home#activity' end - namespace :admin do - resources :users do - collection do - get :list - get :system - end - put :reset_auth_token, on: :member - end - resources :register_requests, only: [:index] do - put :update, on: :collection - member do - get :approve - get :reject - end - end - resources :flash_notifies - resources :event_logs, only: :index - constraints Rosa::Constraints::AdminAccess do - mount Resque::Server => 'resque' - end - end - resources :advisories, only: [:index, :show, :search] do get :search, on: :collection end diff --git a/lib/deploy_info.rb b/lib/deploy_info.rb new file mode 100644 index 000000000..197ed80eb --- /dev/null +++ b/lib/deploy_info.rb @@ -0,0 +1,14 @@ +# This file gets overwritten during deploy process +module DeployInfo + BRANCH=`git rev-parse --abbrev-ref HEAD`.strip + GIT_COMMIT=`git rev-parse HEAD`.strip + BUILD_NUMBER='dev' + BUILD_ID='dev' + DEPLOYER=`git config user.name`.strip + + def message + `git log -1 --pretty=medium`.strip + end + + module_function :message +end diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb new file mode 100644 index 000000000..a83e0c3b7 --- /dev/null +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Admin::DashboardController do + it_should_behave_like 'an admin controller' +end diff --git a/spec/controllers/admin/event_logs_controller_spec.rb b/spec/controllers/admin/event_logs_controller_spec.rb new file mode 100644 index 000000000..836c560e1 --- /dev/null +++ b/spec/controllers/admin/event_logs_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Admin::EventLogsController do + it_should_behave_like 'an admin controller' +end diff --git a/spec/controllers/admin/flash_notifies_controller_spec.rb b/spec/controllers/admin/flash_notifies_controller_spec.rb index 73aa69a9d..f6f3a6d20 100644 --- a/spec/controllers/admin/flash_notifies_controller_spec.rb +++ b/spec/controllers/admin/flash_notifies_controller_spec.rb @@ -1,124 +1,5 @@ require 'spec_helper' describe Admin::FlashNotifiesController do - before(:each) do - stub_symlink_methods - - @user = FactoryGirl.create(:user) - @create_params = { - flash_notify: { - body_ru: "Hello! I`m ru body", - body_en: "Hello! I`m en body", - status: "error", - published: true - } - } - - @flash_notify = FactoryGirl.create(:flash_notify) - @flash_notify2 = FactoryGirl.create(:flash_notify) - - @update_params = { - id: @flash_notify, - flash_notify: { - body_ru: "updated!" - } - } - end - - context 'for guest' do - [:index, :create, :update, :edit, :new, :destroy].each do |action| - it "should not be able to perform #{ action } action" do - get action, id: @flash_notify - response.should redirect_to(new_user_session_path) - end - end - - it 'should not change objects count on create' do - lambda { post :create, @create_params }.should change{ FlashNotify.count }.by(0) - end - - it 'should not change objects count on destroy' do - lambda { delete :destroy, id: @flash_notify }.should change{ FlashNotify.count }.by(0) - end - - it 'should not change flash notify body on update' do - put :update, @update_params - @flash_notify.reload.body_ru.should_not == "updated!" - end - end - - context 'for global admin' do - before(:each) do - @admin = FactoryGirl.create(:admin) - @user = FactoryGirl.create(:user) - set_session_for(@admin) - end - - it 'should load 2 flash notifies objects on index' do - get :index - assigns[:flash_notifies].count.should == 2 - end - - [:index, :new, :edit].each do |action| - it "should be able to perform #{action} action" do - get action, id: @flash_notify - response.should render_template(action) - end - end - - it 'should be able to perform create action' do - post :create, @create_params - response.should redirect_to(admin_flash_notifies_path) - end - - it 'should change objects count on create' do - lambda { post :create, @create_params }.should change{ FlashNotify.count }.by(1) - end - - it 'should be able to perform destroy action' do - delete :destroy, id: @flash_notify - response.should redirect_to(admin_flash_notifies_path) - end - - it 'should change objects count on destroy' do - lambda { delete :destroy, id: @flash_notify }.should change{ FlashNotify.count }.by(-1) - end - - it 'should be able to perform update action' do - put :update, @update_params - response.should redirect_to(admin_flash_notifies_path) - end - - it 'should change flash notify body on update' do - put :update, @update_params - @flash_notify.reload.body_ru.should == "updated!" - end - end - - context 'for simple user' do - before(:each) do - @user = FactoryGirl.create(:user) - set_session_for(@user) - end - - [:index, :create, :update, :edit, :new, :destroy].each do |action| - it "should not be able to perform #{ action } action" do - get action, id: @flash_notify - response.should redirect_to(forbidden_path) - end - end - - it 'should not change objects count on create' do - lambda { post :create, @create_params }.should change{ FlashNotify.count }.by(0) - end - - it 'should not change objects count on destroy' do - lambda { delete :destroy, id: @flash_notify }.should change{ FlashNotify.count }.by(0) - end - - it 'should not change flash notify body on update' do - put :update, @update_params - @flash_notify.reload.body_ru.should_not == "updated!" - end - end + it_should_behave_like 'an admin controller' end diff --git a/spec/controllers/admin/register_requests_controller_spec.rb b/spec/controllers/admin/register_requests_controller_spec.rb new file mode 100644 index 000000000..6ecf3583a --- /dev/null +++ b/spec/controllers/admin/register_requests_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Admin::RegisterRequestsController do + it_should_behave_like 'an admin controller' +end diff --git a/spec/controllers/admin/resque_controller_spec.rb b/spec/controllers/admin/resque_controller_spec.rb new file mode 100644 index 000000000..820e4f955 --- /dev/null +++ b/spec/controllers/admin/resque_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Admin::ResqueController do + it_should_behave_like 'an admin controller' +end diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb new file mode 100644 index 000000000..86c5f0ae6 --- /dev/null +++ b/spec/controllers/admin/users_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Admin::UsersController do + it_should_behave_like 'an admin controller' +end diff --git a/spec/support/shared_examples/admin_examples.rb b/spec/support/shared_examples/admin_examples.rb new file mode 100644 index 000000000..88ca350cc --- /dev/null +++ b/spec/support/shared_examples/admin_examples.rb @@ -0,0 +1,22 @@ +shared_examples_for 'an admin controller' do + + it 'redirects to login when accessed unauthorised' do + get :index + response.should redirect_to(new_user_session_path) + end + + it 'raises a 404 for non-admin users' do + user = User.first || FactoryGirl.create(:user) + sign_in user + get :index + response.should redirect_to('/404.html') + end + + it 'is successful for admin users' do + user = User.first || FactoryGirl.create(:admin) + sign_in user + get :index + response.should be_success + end + +end \ No newline at end of file