Fix flash notifies display bug. Add admin section link. Move controller to admin namspace. Refactor and fix notifies controller. Refs #576

This commit is contained in:
Pavel Chipiga 2012-07-25 21:05:25 +03:00
parent c0036a1bb5
commit e09a9467e2
13 changed files with 77 additions and 85 deletions

View File

@ -1,8 +1,4 @@
class FlashNotifiesController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource
class Admin::FlashNotifiesController < Admin::BaseController
def index
@flash_notifies = FlashNotify.paginate(:page => params[:page], :per_page => 20)
end
@ -15,7 +11,7 @@ class FlashNotifiesController < ApplicationController
@flash_notify = FlashNotify.new(params[:flash_notify])
if @flash_notify.save
flash[:notice] = t("flash.flash_notify.saved")
redirect_to flash_notifies_path
redirect_to admin_flash_notifies_path
else
flash[:error] = t("flash.flash_notify.save_error")
flash[:warning] = @flash_notify.errors.full_messages.join('. ')
@ -26,7 +22,7 @@ class FlashNotifiesController < ApplicationController
def update
if @flash_notify.update_attributes(params[:flash_notify])
flash[:notice] = t("flash.flash_notify.saved")
redirect_to flash_notifies_path
redirect_to admin_flash_notifies_path
else
flash[:error] = t("flash.flash_notify.save_error")
flash[:warning] = @flash_notify.errors.full_messages.join('. ')
@ -37,10 +33,9 @@ class FlashNotifiesController < ApplicationController
def destroy
if @flash_notify.destroy
flash[:notice] = t("flash.flash_notify.destroyed")
redirect_to flash_notifies_path
else
flash[:error] = t("flash.flash_notify.destroy_error")
redirect_to flash_notifies_path
end
redirect_to admin_flash_notifies_path
end
end

View File

@ -17,5 +17,5 @@
.button_block
= submit_tag t("layout.save")
%span.text_button_padding= t("layout.or")
= link_to t("layout.cancel"), flash_notifies_path, :class => "button"
= link_to t("layout.cancel"), admin_flash_notifies_path, :class => "button"

View File

@ -0,0 +1,4 @@
%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

View File

@ -1,4 +1,4 @@
= link_to t("layout.flash_notifies.new"), new_flash_notify_path, :class => 'button' if can? :create, FlashNotify
= 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
@ -14,8 +14,8 @@
%td= flash_notify.body_ru.truncate 18
%td= flash_notify.published
%td
= link_to t("layout.flash_notifies.edit"), edit_flash_notify_path(flash_notify)
= link_to t("layout.flash_notifies.delete"), flash_notify_path(flash_notify), :method => :delete, :confirm => t("layout.mass_builds.cancel_confirm") if can?(:delete, flash_notify)
= 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, :confirm => t("layout.mass_builds.cancel_confirm") if can?(:delete, flash_notify)
= will_paginate @flash_notifies

View File

@ -0,0 +1,4 @@
%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

View File

@ -1,4 +0,0 @@
%h3= t("layout.flash_notifies.edit_header")
= form_for @flash_notify, :url => flash_notify_path(@flash_notify), :html => { :class => :form } do |f|
= render "form", :f => f

View File

@ -1,4 +0,0 @@
%h3= t("layout.flash_notifies.new_header")
= form_for @flash_notify, :url => flash_notifies_path, :html => { :class => :form } do |f|
= render "form", :f => f

View File

@ -1,10 +1,9 @@
- if current_user || APP_CONFIG['anonymous_access']
.flash_notify
- flash_notify = FlashNotify.published.first
- if flash_notify && flash_notify.should_show?(cookies[:flash_notify_hash])
- if (flash_notify = FlashNotify.published.first) && flash_notify.should_show?(cookies[:flash_notify_hash])
.alert{:class => "alert-#{flash_notify.status}"}
= flash_notify.body current_user.language
%a{:class=>"close", :'data-dismiss'=>"alert", :href=>"#", :id => 'close-alert'} &times;
%a.close#close-alert{:'data-dismiss'=>"alert", :href=>"#"} &times;
:javascript
var FLASH_HASH_ID = "#{flash_notify.hash_id}";

View File

@ -37,5 +37,6 @@ en:
admins_menu:
users: Users
register_requests: Invites
flash_notifies: Notifies
event_logs: Event log
resque_server: Resque

View File

@ -37,5 +37,6 @@ ru:
admins_menu:
users: Пользователи
register_requests: Инвайты
flash_notifies: Оповещения
event_logs: Лог событий
resque_server: Resque

View File

@ -21,8 +21,6 @@ Rosa::Application.routes.draw do
root :to => 'activity_feeds#index'
end
resources :flash_notifies
namespace :admin do
resources :users do
get :list, :on => :collection
@ -34,6 +32,7 @@ Rosa::Application.routes.draw do
get :reject
end
end
resources :flash_notifies
resources :event_logs, :only => :index
constraints AdminAccess do
mount Resque::Server => 'resque'

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120703101719) do
ActiveRecord::Schema.define(:version => 20120719045806) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
create_table "arches", :force => true do |t|
t.string "name", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true
@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.integer "user_id"
t.string "provider"
t.string "uid"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true
@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.integer "level"
t.integer "status"
t.integer "build_list_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "version"
end
@ -107,8 +107,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.integer "project_id"
t.integer "arch_id"
t.datetime "notified_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "is_circle", :default => false
t.text "additional_repos"
t.string "name"
@ -137,8 +137,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.string "commentable_type"
t.integer "user_id"
t.text "body"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.decimal "commentable_id", :precision => 50, :scale => 0
t.integer "project_id"
end
@ -155,8 +155,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.string "controller"
t.string "action"
t.text "message"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "flash_notifies", :force => true do |t|
@ -170,8 +170,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
create_table "groups", :force => true do |t|
t.integer "owner_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "uname"
t.integer "own_projects_count", :default => 0, :null => false
t.text "description"
@ -184,8 +184,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.string "title"
t.text "body"
t.string "status", :default => "open"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
t.datetime "closed_at"
t.integer "closed_by"
@ -234,14 +234,14 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.string "description"
t.string "name", :null => false
t.integer "parent_platform_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "released", :default => false, :null => false
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main", :null => false
t.string "distrib_type"
t.string "distrib_type", :null => false
end
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false
@ -250,8 +250,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.integer "platform_id"
t.string "login"
t.string "password"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
@ -267,8 +267,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
create_table "products", :force => true do |t|
t.string "name", :null => false
t.integer "platform_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.text "build_script"
t.text "counter"
t.text "ks"
@ -287,8 +287,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.string "name"
t.string "version"
t.datetime "file_mtime"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "platform_id"
end
@ -297,25 +297,25 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
create_table "project_to_repositories", :force => true do |t|
t.integer "project_id"
t.integer "repository_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "projects", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", :default => "open"
t.text "description"
t.string "ancestry"
t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master"
t.boolean "is_package", :default => true, :null => false
t.integer "average_build_time", :default => 0, :null => false
@ -330,8 +330,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.string "token"
t.boolean "approved", :default => false
t.boolean "rejected", :default => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "interest"
t.text "more"
end
@ -344,16 +344,16 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.string "actor_type"
t.integer "target_id"
t.string "target_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "role"
end
create_table "repositories", :force => true do |t|
t.string "description", :null => false
t.integer "platform_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "name", :null => false
end
@ -364,8 +364,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.boolean "new_comment_reply", :default => true
t.boolean "new_issue", :default => true
t.boolean "issue_assign", :default => true
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "new_comment_commit_owner", :default => true
t.boolean "new_comment_commit_repo_owner", :default => true
t.boolean "new_comment_commit_commentor", :default => true
@ -374,8 +374,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
create_table "subscribes", :force => true do |t|
t.string "subscribeable_type"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "status", :default => true
t.integer "project_id"
t.decimal "subscribeable_id", :precision => 50, :scale => 0
@ -385,21 +385,15 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.string "name"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "ssh_key"
t.datetime "created_at"
t.datetime "updated_at"
t.string "uname"
t.string "role"
t.string "language", :default => "en"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.integer "own_projects_count", :default => 0, :null => false
t.datetime "reset_password_sent_at"
t.integer "own_projects_count", :default => 0, :null => false
t.text "professional_experience"
t.string "site"
t.string "company"
@ -411,6 +405,9 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.integer "failed_attempts", :default => 0
t.string "unlock_token"
t.datetime "locked_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "authentication_token"
t.integer "build_priority", :default => 50
end

View File

@ -1,6 +1,6 @@
require 'spec_helper'
describe FlashNotifiesController do
describe Admin::FlashNotifiesController do
before(:each) do
stub_symlink_methods
@ -68,7 +68,7 @@ describe FlashNotifiesController do
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(flash_notifies_path)
response.should redirect_to(admin_flash_notifies_path)
end
it 'should change objects count on create' do
@ -77,7 +77,7 @@ describe FlashNotifiesController do
it 'should be able to perform destroy action' do
delete :destroy, :id => @flash_notify
response.should redirect_to(flash_notifies_path)
response.should redirect_to(admin_flash_notifies_path)
end
it 'should change objects count on destroy' do
@ -86,7 +86,7 @@ describe FlashNotifiesController do
it 'should be able to perform update action' do
put :update, @update_params
response.should redirect_to(flash_notifies_path)
response.should redirect_to(admin_flash_notifies_path)
end
it 'should change flash notify body on update' do