Add private option to users
This commit is contained in:
parent
97fdd2e24c
commit
2f71e95a81
8 changed files with 23 additions and 6 deletions
|
@ -40,7 +40,7 @@ class OrdersController < ApplicationController
|
|||
end
|
||||
|
||||
def overview
|
||||
@users = User.members.order(:uid)
|
||||
@users = User.members.publik.order(:uid)
|
||||
end
|
||||
|
||||
def quickpay
|
||||
|
@ -65,6 +65,11 @@ class OrdersController < ApplicationController
|
|||
redirect_to root_path
|
||||
end
|
||||
|
||||
if @user.private && current_user != @user
|
||||
flash[:error] = "You can't order stuff for this person."
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
unless current_user.koelkast? || current_user.admin? || current_user == @user
|
||||
flash[:error] = "Please don't order stuff for other people"
|
||||
redirect_to root_path
|
||||
|
|
|
@ -79,6 +79,6 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def user_params
|
||||
params.permit(:user).permit(:avatar)
|
||||
params.fetch(:user, {}).permit(:avatar, :private)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
class Order < ActiveRecord::Base
|
||||
include ActionView::Helpers::TextHelper
|
||||
|
||||
after_create { self.user.increment!(:debt_cents, price_cents) }
|
||||
after_create { self.user.increment!(:debt_cents, price_cents) }
|
||||
|
||||
belongs_to :user, counter_cache: true
|
||||
has_many :order_items, dependent: :destroy
|
||||
|
|
|
@ -13,9 +13,9 @@ class OrderItem < ActiveRecord::Base
|
|||
belongs_to :product
|
||||
|
||||
validates :product, presence: true
|
||||
validates :count, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||
validates :count, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||
|
||||
after_create :remove_from_stock
|
||||
after_create :remove_from_stock
|
||||
|
||||
accepts_nested_attributes_for :product
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ class User < ActiveRecord::Base
|
|||
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
||||
|
||||
scope :members, -> { where koelkast: false }
|
||||
scope :publik, -> { where private: false }
|
||||
|
||||
def self.from_omniauth(auth)
|
||||
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
<%= f.error_messages %>
|
||||
|
||||
<%= f.file_field :avatar %>
|
||||
<p>
|
||||
If you check this option, nobody will be able to order stuff for you through koelkast.
|
||||
Only on your account things can be ordered.
|
||||
<p>
|
||||
<%= f.check_box :private %>
|
||||
|
||||
<%= f.submit "Update" %>
|
||||
<% end %>
|
||||
|
|
5
db/migrate/20150630183223_add_private_to_users.rb
Normal file
5
db/migrate/20150630183223_add_private_to_users.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddPrivateToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :private, :boolean, default: false
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150325154600) do
|
||||
ActiveRecord::Schema.define(version: 20150630183223) do
|
||||
|
||||
create_table "order_items", force: :cascade do |t|
|
||||
t.integer "order_id"
|
||||
|
@ -64,6 +64,7 @@ ActiveRecord::Schema.define(version: 20150325154600) do
|
|||
t.string "provider"
|
||||
t.string "uid"
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
t.boolean "private", default: false
|
||||
end
|
||||
|
||||
add_index "users", ["koelkast"], name: "index_users_on_koelkast"
|
||||
|
|
Loading…
Reference in a new issue