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
authorize! :schulden, :admins
@users = User.all
@users = User.members
respond_to do |format|
format.csv do
headers['Content-Disposition'] = "attachment; filename=\"zeus-schulden\""

View file

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

View file

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

View file

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

View file

@ -39,6 +39,8 @@ class User < ActiveRecord::Base
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"] }
scope :members, -> { where koelkast: false }
def full_name
"#{name} #{last_name}"
end

View file

@ -1,9 +1,15 @@
Rails.application.routes.draw do
root "orders#index"
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 :orders, only: [:new, :create, :index]
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.
ActiveRecord::Schema.define(version: 20141210200008) do
ActiveRecord::Schema.define(version: 20141217063222) do
create_table "order_products", force: true do |t|
t.integer "order_id"
@ -62,6 +62,7 @@ ActiveRecord::Schema.define(version: 20141210200008) do
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
t.integer "orders_count", default: 0
t.boolean "koelkast", default: false
end
end