Add koelkast to users

This commit is contained in:
benji 2015-01-06 20:18:01 +01:00
parent b0fec45150
commit db23fd2181
8 changed files with 28 additions and 10 deletions

View file

@ -3,7 +3,7 @@ class AdminsController < ApplicationController
def schulden def schulden
authorize! :schulden, :admins authorize! :schulden, :admins
@users = User.all @users = User.members
respond_to do |format| respond_to do |format|
format.csv do format.csv do
headers['Content-Disposition'] = "attachment; filename=\"zeus-schulden\"" headers['Content-Disposition'] = "attachment; filename=\"zeus-schulden\""

View file

@ -1,6 +1,8 @@
class OrdersController < ApplicationController class OrdersController < ApplicationController
include OrdersHelper include OrdersHelper
load_and_authorize_resource
def new def new
@user = User.find(params[:user_id]) @user = User.find(params[:user_id])
@order = @user.orders.build @order = @user.orders.build
@ -26,8 +28,8 @@ class OrdersController < ApplicationController
end end
def index def index
@users_by_name = User.all.order(:name) @users_by_name = User.members.order(:name)
@users_by_order = User.all.order(:orders_count).reverse_order @users_by_order = User.members.order(:orders_count).reverse_order
end end
def quickpay def quickpay

View file

@ -7,7 +7,7 @@ class UsersController < ApplicationController
end end
def index def index
@users = User.all @users = User.members
end end
def destroy def destroy

View file

@ -6,6 +6,8 @@ class Ability
if user.admin? if user.admin?
can :manage, :all can :manage, :all
can :schulden, :admins can :schulden, :admins
elsif user.koelkast?
can :manage, Order
else else
can :read, :all can :read, :all
end end

View file

@ -39,6 +39,8 @@ class User < ActiveRecord::Base
validates :password, length: { in: 8..128 }, confirmation: true, on: :create validates :password, length: { in: 8..128 }, confirmation: true, on: :create
validates_attachment :avatar, presence: true, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] } validates_attachment :avatar, presence: true, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
scope :members, -> { where koelkast: false }
def full_name def full_name
"#{name} #{last_name}" "#{name} #{last_name}"
end end

View file

@ -1,9 +1,15 @@
Rails.application.routes.draw do Rails.application.routes.draw do
root "orders#index"
devise_for :users devise_for :users
devise_scope :user do
authenticated :user do
root to: 'orders#index'
end
unauthenticated :user do
root to: 'devise/sessions#new', as: 'unauth_root'
end
end
resources :users do resources :users do
resources :orders, only: [:new, :create, :index] resources :orders, only: [:new, :create, :index]
get 'quickpay' => 'orders#quickpay' get 'quickpay' => 'orders#quickpay'

View file

@ -0,0 +1,5 @@
class AddKoelkastToUsers < ActiveRecord::Migration
def change
add_column :users, :koelkast, :boolean, default: false
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141210200008) do ActiveRecord::Schema.define(version: 20141217063222) do
create_table "order_products", force: true do |t| create_table "order_products", force: true do |t|
t.integer "order_id" t.integer "order_id"
@ -48,9 +48,9 @@ ActiveRecord::Schema.define(version: 20141210200008) do
t.string "nickname" t.string "nickname"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at" t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
@ -62,6 +62,7 @@ ActiveRecord::Schema.define(version: 20141210200008) do
t.integer "avatar_file_size" t.integer "avatar_file_size"
t.datetime "avatar_updated_at" t.datetime "avatar_updated_at"
t.integer "orders_count", default: 0 t.integer "orders_count", default: 0
t.boolean "koelkast", default: false
end end
end end