Created
May 3, 2020 03:20
-
-
Save anon987654321/4a5f5f4701ca5a59b7d967eee1298abc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 65d2ec3355e0d12f20d97480c9748e6276338bb3 | |
Author: dev <dev@dev.my.domain> | |
Date: Mon Mar 30 12:51:52 2020 +0200 | |
Add approval routes | |
diff --git a/config/routes.rb b/config/routes.rb | |
index 5786e6a..6b1bac1 100644 | |
--- a/config/routes.rb | |
+++ b/config/routes.rb | |
@@ -4,4 +4,9 @@ Rails.application.routes.draw do | |
root to: "incidents#index" | |
devise_for :users | |
+ | |
+ resources :admins, only: [:index] | |
+ resources :admins do | |
+ put :approve, on: :member | |
+ end | |
end | |
commit 01c32fc0c7f893d2f2c2fd4b19e1123c2d46b33d | |
Author: dev <dev@dev.my.domain> | |
Date: Mon Mar 30 13:48:11 2020 +0200 | |
Add approval link to main HTML | |
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb | |
index 8e83665..82a65f3 100644 | |
--- a/app/views/layouts/application.html.erb | |
+++ b/app/views/layouts/application.html.erb | |
@@ -27,6 +27,10 @@ | |
<%= link_to t("devise.sessions.log_in"), new_user_session_path, class: "button primary" %> | |
<%= link_to t("devise.registrations.register_now"), new_user_registration_path, class: "button" %> | |
<% else %> | |
+ <div class="options"> | |
+ <% if current_user.admin? %> | |
+ <%= link_to t("admin.approve_users"), admin_path %> | |
+ <% end %> | |
<% if current_user.approved? || current_user.admin? %> | |
<%= link_to t("app.new_incident"), new_incident_path %> | |
<% end %> | |
commit 12a5d256db5212c1fce4e80c635f3aaffe05e425 | |
Author: dev <dev@dev.my.domain> | |
Date: Mon Mar 30 13:46:35 2020 +0200 | |
Add approval index to admin HTML | |
diff --git a/app/views/admin/index.html.erb b/app/views/admin/index.html.erb | |
index e5328b7..171f72d 100644 | |
--- a/app/views/admin/index.html.erb | |
+++ b/app/views/admin/index.html.erb | |
@@ -1,2 +1,11 @@ | |
-<h1>Admin#index</h1> | |
-<p>Find me in app/views/admin/index.html.erb</p> | |
+<% content_for :page_title, t("admin.approve_users") %> | |
+<% @users.each do |user| %> | |
+ <div class="field"> | |
+ <p><%= user.first_name %> <%= user.last_name %>, <%= user.hospital %></p> | |
+ <% if user.approved? %> | |
+ <h4><%= link_to t("admin.revoke_approval"), approve_user_path(user), method: :put %></h4> | |
+ <% else %> | |
+ <h4><%= link_to t("admin.approve"), approve_user_path(user), method: :put %></h4> | |
+ <% end %> | |
+ </div> | |
+<% end %> | |
diff --git a/config/locales/en.yml b/config/locales/en.yml | |
index 58923ee..b28df84 100644 | |
--- a/config/locales/en.yml | |
+++ b/config/locales/en.yml | |
@@ -38,6 +38,9 @@ en: | |
user_approved: "{user} has been approved for posting." | |
approval_revoked: "Approval revoked from {user}." | |
not_allowed: "You're not allowed to do that." | |
+ approve_users: "Approve users" | |
+ approve: "Approve" | |
+ revoke_approval: "Revoke approval" | |
# Devise | |
devise: | |
diff --git a/config/locales/nb.yml b/config/locales/nb.yml | |
index 33db864..57f1b5a 100644 | |
--- a/config/locales/nb.yml | |
+++ b/config/locales/nb.yml | |
@@ -38,6 +38,9 @@ nb: | |
user_approved: "{user} er nå godkjent for innlegg." | |
approval_revoked: "{user} er nå fratatt godkjenning." | |
not_allowed: "Det der har du ikke lov til." | |
+ approve_users: "Godkjenn brukere" | |
+ approve: "Godkjenn" | |
+ revoke_approval: "Fjern godkjenning" | |
# Devise | |
devise: | |
commit 46d2894b71e538788474f57b5b3de83876b7ec96 | |
Author: dev <dev@dev.my.domain> | |
Date: Mon Mar 30 12:50:36 2020 +0200 | |
Add approval action to admin controller | |
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb | |
index 6cfaffd..d768e53 100644 | |
--- a/app/controllers/admin_controller.rb | |
+++ b/app/controllers/admin_controller.rb | |
@@ -1,7 +1,29 @@ | |
class AdminController < ApplicationController | |
+ before_action :authenticate_user! | |
+ before_action :authorize_admin | |
+ | |
def index | |
+ @users = User.all | |
end | |
def approve | |
+ @user = User.find(params[:id]) | |
+ | |
+ if !@user.approved? | |
+ flash.notice = t(:admin.user_approved, user: @user.first_name + " " + @user.last_name) | |
+ @user.update(approved: true) | |
+ else | |
+ flash.notice = t(:admin.approval_revoked, user: @user.first_name + " " + @user.last_name) | |
+ @user.update(approved: false) | |
+ end | |
+ | |
+ redirect_to users_path | |
end | |
+ | |
+ private | |
+ def authorize_admin | |
+ unless current_user.admin? | |
+ redirect_to new_user_session_path, warning: t(:admin.not_allowed) | |
+ end | |
+ end | |
end | |
diff --git a/config/locales/en.yml b/config/locales/en.yml | |
index 74f1323..58923ee 100644 | |
--- a/config/locales/en.yml | |
+++ b/config/locales/en.yml | |
@@ -34,6 +34,11 @@ en: | |
deleted: "Sletting vellykket." | |
not_allowed: "Det der har du ikke lov til." | |
+ admin: | |
+ user_approved: "{user} has been approved for posting." | |
+ approval_revoked: "Approval revoked from {user}." | |
+ not_allowed: "You're not allowed to do that." | |
+ | |
# Devise | |
devise: | |
new_fields: | |
diff --git a/config/locales/nb.yml b/config/locales/nb.yml | |
index 0ef7003..33db864 100644 | |
--- a/config/locales/nb.yml | |
+++ b/config/locales/nb.yml | |
@@ -34,6 +34,11 @@ nb: | |
deleted: "Sletting vellykket." | |
not_allowed: "Det der har du ikke lov til." | |
+ admin: | |
+ user_approved: "{user} er nå godkjent for innlegg." | |
+ approval_revoked: "{user} er nå fratatt godkjenning." | |
+ not_allowed: "Det der har du ikke lov til." | |
+ | |
# Devise | |
devise: | |
new_fields: | |
commit a24501d4ca89b7c4dc0e07fbf25573bb3a197443 | |
Author: dev <dev@dev.my.domain> | |
Date: Mon Mar 30 12:41:34 2020 +0200 | |
Sanitize admin generated files | |
diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss | |
deleted file mode 100644 | |
index a65cbd2..0000000 | |
--- a/app/assets/stylesheets/admin.scss | |
+++ /dev/null | |
@@ -1,3 +0,0 @@ | |
-// Place all the styles related to the Admin controller here. | |
-// They will automatically be included in application.css. | |
-// You can use Sass (SCSS) here: https://sass-lang.com/ | |
diff --git a/app/views/admin/approve.html.erb b/app/views/admin/approve.html.erb | |
deleted file mode 100644 | |
index 2e10d3e..0000000 | |
--- a/app/views/admin/approve.html.erb | |
+++ /dev/null | |
@@ -1,2 +0,0 @@ | |
-<h1>Admin#approve</h1> | |
-<p>Find me in app/views/admin/approve.html.erb</p> | |
diff --git a/config/routes.rb b/config/routes.rb | |
index 77d5faa..5786e6a 100644 | |
--- a/config/routes.rb | |
+++ b/config/routes.rb | |
@@ -1,6 +1,4 @@ | |
Rails.application.routes.draw do | |
- get 'admin/index' | |
- get 'admin/approve' | |
resources :incidents | |
root to: "incidents#index" | |
commit 2bf2928ec022e347f2e91768df9977c5575b6d59 | |
Author: dev <dev@dev.my.domain> | |
Date: Mon Mar 30 12:33:48 2020 +0200 | |
Generate admin controller | |
rails generate controller Admin index approve | |
diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss | |
new file mode 100644 | |
index 0000000..a65cbd2 | |
--- /dev/null | |
+++ b/app/assets/stylesheets/admin.scss | |
@@ -0,0 +1,3 @@ | |
+// Place all the styles related to the Admin controller here. | |
+// They will automatically be included in application.css. | |
+// You can use Sass (SCSS) here: https://sass-lang.com/ | |
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb | |
new file mode 100644 | |
index 0000000..6cfaffd | |
--- /dev/null | |
+++ b/app/controllers/admin_controller.rb | |
@@ -0,0 +1,7 @@ | |
+class AdminController < ApplicationController | |
+ def index | |
+ end | |
+ | |
+ def approve | |
+ end | |
+end | |
diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb | |
new file mode 100644 | |
index 0000000..d5c6d35 | |
--- /dev/null | |
+++ b/app/helpers/admin_helper.rb | |
@@ -0,0 +1,2 @@ | |
+module AdminHelper | |
+end | |
diff --git a/app/views/admin/approve.html.erb b/app/views/admin/approve.html.erb | |
new file mode 100644 | |
index 0000000..2e10d3e | |
--- /dev/null | |
+++ b/app/views/admin/approve.html.erb | |
@@ -0,0 +1,2 @@ | |
+<h1>Admin#approve</h1> | |
+<p>Find me in app/views/admin/approve.html.erb</p> | |
diff --git a/app/views/admin/index.html.erb b/app/views/admin/index.html.erb | |
new file mode 100644 | |
index 0000000..e5328b7 | |
--- /dev/null | |
+++ b/app/views/admin/index.html.erb | |
@@ -0,0 +1,2 @@ | |
+<h1>Admin#index</h1> | |
+<p>Find me in app/views/admin/index.html.erb</p> | |
diff --git a/config/routes.rb b/config/routes.rb | |
index 5786e6a..77d5faa 100644 | |
--- a/config/routes.rb | |
+++ b/config/routes.rb | |
@@ -1,4 +1,6 @@ | |
Rails.application.routes.draw do | |
+ get 'admin/index' | |
+ get 'admin/approve' | |
resources :incidents | |
root to: "incidents#index" | |
diff --git a/test/controllers/admin_controller_test.rb b/test/controllers/admin_controller_test.rb | |
new file mode 100644 | |
index 0000000..5fa7c03 | |
--- /dev/null | |
+++ b/test/controllers/admin_controller_test.rb | |
@@ -0,0 +1,14 @@ | |
+require 'test_helper' | |
+ | |
+class AdminControllerTest < ActionDispatch::IntegrationTest | |
+ test "should get index" do | |
+ get admin_index_url | |
+ assert_response :success | |
+ end | |
+ | |
+ test "should get approve" do | |
+ get admin_approve_url | |
+ assert_response :success | |
+ end | |
+ | |
+end | |
commit 1de2fd2bb91309a0269ccc1e9d3a734d6069d40f | |
Author: dev <dev@dev.my.domain> | |
Date: Mon Mar 30 12:23:45 2020 +0200 | |
Add approved database field to user | |
rails generate migration AddApprovedToUser approved:boolean | |
diff --git a/db/migrate/20200330102337_add_approved_to_user.rb b/db/migrate/20200330102337_add_approved_to_user.rb | |
new file mode 100644 | |
index 0000000..999fbf5 | |
--- /dev/null | |
+++ b/db/migrate/20200330102337_add_approved_to_user.rb | |
@@ -0,0 +1,5 @@ | |
+class AddApprovedToUser < ActiveRecord::Migration[6.0] | |
+ def change | |
+ add_column :users, :approved, :boolean | |
+ end | |
+end | |
diff --git a/db/schema.rb b/db/schema.rb | |
index 6aeada5..1c3b1f0 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: 2020_04_01_221550) do | |
+ActiveRecord::Schema.define(version: 2020_03_30_102337) do | |
create_table "incidents", force: :cascade do |t| | |
t.integer "status" | |
@@ -39,6 +39,7 @@ ActiveRecord::Schema.define(version: 2020_04_01_221550) do | |
t.string "department" | |
t.string "role" | |
t.boolean "admin" | |
+ t.boolean "approved" | |
t.index ["email"], name: "index_users_on_email", unique: true | |
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment