From e87f7fb7312080ad5014ba78fb50209ae0115dfc Mon Sep 17 00:00:00 2001 From: Adrian Hinz Date: Thu, 12 Dec 2019 11:35:40 +0100 Subject: [PATCH] added role to user --- app/helpers/application_helper.rb | 6 ++++++ app/models/user.rb | 2 +- config/environments/development.rb | 6 +++--- db/migrate/20191210124145_add_role_to_users.rb | 5 +++++ db/schema.rb | 3 ++- 5 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20191210124145_add_role_to_users.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..002850b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,8 @@ +# frozen_string_literal: true + +# Main ApplicationHelper module ApplicationHelper + def admin? + current_user.radmin? + end end diff --git a/app/models/user.rb b/app/models/user.rb index 6fe1681..d3d67b1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,7 +5,7 @@ class User < ApplicationRecord # == Constants ============================================================ # == Attributes =========================================================== - + enum role: %i[ruser radmin] # == Extensions =========================================================== # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable, diff --git a/config/environments/development.rb b/config/environments/development.rb index 721ae36..41723d5 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -36,9 +36,9 @@ Rails.application.configure do config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', port: 587, - domain: 'akadeniatechnologii.pl', - user_name: 'akadeniatechnologii@gmail.com', - password: '12345%$#@!Adi', + domain: 'akademiatechnologii.pl', + user_name: 'akademiatechnologii.pl@gmail.com', + password: '123456%$#@!Adi', authentication: 'plain', enable_starttls_auto: true } diff --git a/db/migrate/20191210124145_add_role_to_users.rb b/db/migrate/20191210124145_add_role_to_users.rb new file mode 100644 index 0000000..6f66a41 --- /dev/null +++ b/db/migrate/20191210124145_add_role_to_users.rb @@ -0,0 +1,5 @@ +class AddRoleToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :role, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 677ed68..ca65a3b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_05_02_114629) do +ActiveRecord::Schema.define(version: 2019_12_10_124145) do create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.string "name", null: false @@ -129,6 +129,7 @@ ActiveRecord::Schema.define(version: 2019_05_02_114629) do t.datetime "locked_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "role", default: 0 t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true