From e071972c60e60dd2bf19c2f632186aafea0c38e4 Mon Sep 17 00:00:00 2001 From: Arka Ganguli Date: Mon, 13 Mar 2017 02:29:05 -0400 Subject: [PATCH 1/3] allow people to submit request to become exec --- app/assets/javascripts/exec_promotions.coffee | 3 ++ app/assets/stylesheets/exec_promotions.scss | 3 ++ app/controllers/exec_promotions_controller.rb | 37 +++++++++++++++++++ app/helpers/exec_promotions_helper.rb | 2 + app/models/exec_promotion.rb | 2 + app/models/user.rb | 4 +- app/views/devise/registrations/edit.html.erb | 19 +++++++++- app/views/events/_header.html.erb | 8 +++- .../_request_promotion.html.erb | 1 + app/views/exec_promotions/index.html.erb | 18 +++++++++ app/views/exec_promotions/new.html.erb | 9 +++++ config/routes.rb | 4 +- .../20170313051920_create_exec_promotions.rb | 8 ++++ ...13052632_add_columns_to_exec_promotions.rb | 5 +++ .../20170313053820_add_reason_to_exec.rb | 5 +++ db/schema.rb | 9 ++++- .../exec_promotions_controller_test.rb | 7 ++++ test/fixtures/exec_promotions.yml | 11 ++++++ test/models/exec_promotion_test.rb | 7 ++++ 19 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 app/assets/javascripts/exec_promotions.coffee create mode 100644 app/assets/stylesheets/exec_promotions.scss create mode 100644 app/controllers/exec_promotions_controller.rb create mode 100644 app/helpers/exec_promotions_helper.rb create mode 100644 app/models/exec_promotion.rb create mode 100644 app/views/exec_promotions/_request_promotion.html.erb create mode 100644 app/views/exec_promotions/index.html.erb create mode 100644 app/views/exec_promotions/new.html.erb create mode 100644 db/migrate/20170313051920_create_exec_promotions.rb create mode 100644 db/migrate/20170313052632_add_columns_to_exec_promotions.rb create mode 100644 db/migrate/20170313053820_add_reason_to_exec.rb create mode 100644 test/controllers/exec_promotions_controller_test.rb create mode 100644 test/fixtures/exec_promotions.yml create mode 100644 test/models/exec_promotion_test.rb diff --git a/app/assets/javascripts/exec_promotions.coffee b/app/assets/javascripts/exec_promotions.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/exec_promotions.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/exec_promotions.scss b/app/assets/stylesheets/exec_promotions.scss new file mode 100644 index 0000000..c8ca020 --- /dev/null +++ b/app/assets/stylesheets/exec_promotions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the exec_promotions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/exec_promotions_controller.rb b/app/controllers/exec_promotions_controller.rb new file mode 100644 index 0000000..5291bcf --- /dev/null +++ b/app/controllers/exec_promotions_controller.rb @@ -0,0 +1,37 @@ +# Custom exec admin controller + +class ExecPromotionsController < ApplicationController + before_action :authenticate_user! + before_action :authorized_president, only: [:index] + + def new + @exec_promotion = ExecPromotion.new + end + + def create + @exec_promotion = ExecPromotion.new + @exec_promotion['reason'] = exec_promotion_params['reason'] + @exec_promotion['user_id'] = current_user.id + @exec_promotion.save + + redirect_to edit_user_registration_path, notice: "Successfully sent request" + end + + def index + @exec_promotions = ExecPromotion.all + end + + private + + def authorized_president + if current_user.is_president? + return true + end + + redirect_back fallback_location: root_path, notice: "Restricted action" + end + + def exec_promotion_params + params.require(:exec_promotion).permit(:reason) + end +end diff --git a/app/helpers/exec_promotions_helper.rb b/app/helpers/exec_promotions_helper.rb new file mode 100644 index 0000000..1f34ac5 --- /dev/null +++ b/app/helpers/exec_promotions_helper.rb @@ -0,0 +1,2 @@ +module ExecPromotionsHelper +end diff --git a/app/models/exec_promotion.rb b/app/models/exec_promotion.rb new file mode 100644 index 0000000..89353a5 --- /dev/null +++ b/app/models/exec_promotion.rb @@ -0,0 +1,2 @@ +class ExecPromotion < ApplicationRecord +end diff --git a/app/models/user.rb b/app/models/user.rb index b2091f9..51b8bc9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable - devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable end diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 1e66f3d..72481ec 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -36,8 +36,23 @@ <% end %> -

Cancel my account

+

Other options

+

<%= notice %>

-

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+
+ <% if current_user.is_president %> + <%= link_to "Approve exec requests", exec_promotions_path %> + <% end %> +
+ +
+ <% if !current_user.is_exec %> + <%= render partial: "exec_promotions/request_promotion" %> + <% end %> +
+ +
+ <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %> +
<%= link_to "Back", :back %> diff --git a/app/views/events/_header.html.erb b/app/views/events/_header.html.erb index 0077e5a..b5fe099 100644 --- a/app/views/events/_header.html.erb +++ b/app/views/events/_header.html.erb @@ -3,6 +3,12 @@ diff --git a/app/views/exec_promotions/_request_promotion.html.erb b/app/views/exec_promotions/_request_promotion.html.erb new file mode 100644 index 0000000..e07462e --- /dev/null +++ b/app/views/exec_promotions/_request_promotion.html.erb @@ -0,0 +1 @@ +<%= link_to "Request exec privileges", new_exec_promotion_path %> diff --git a/app/views/exec_promotions/index.html.erb b/app/views/exec_promotions/index.html.erb new file mode 100644 index 0000000..12d8f0f --- /dev/null +++ b/app/views/exec_promotions/index.html.erb @@ -0,0 +1,18 @@ +

All exec promotion requests

+ + + + + + + + + + <% @exec_promotions.each do |promotion| %> + + + + + <% end %> + +
User IDReason
<%= promotion.user_id %><%= promotion.reason %>
diff --git a/app/views/exec_promotions/new.html.erb b/app/views/exec_promotions/new.html.erb new file mode 100644 index 0000000..b509227 --- /dev/null +++ b/app/views/exec_promotions/new.html.erb @@ -0,0 +1,9 @@ +<%= form_for(@exec_promotion) do |f| %> +

+ <%= f.label :reason %>
+ <%= f.text_area :reason %> +

+

+ <%= f.submit %> +

+<% end %> diff --git a/config/routes.rb b/config/routes.rb index 6a9a302..93c9a73 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,5 +3,7 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root to: 'events#index' get '/index', to: 'events#index' - get "/events", to: 'events#events' + get '/events', to: 'events#events' + + resources :exec_promotions end diff --git a/db/migrate/20170313051920_create_exec_promotions.rb b/db/migrate/20170313051920_create_exec_promotions.rb new file mode 100644 index 0000000..d8452a6 --- /dev/null +++ b/db/migrate/20170313051920_create_exec_promotions.rb @@ -0,0 +1,8 @@ +class CreateExecPromotions < ActiveRecord::Migration[5.0] + def change + create_table :exec_promotions do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20170313052632_add_columns_to_exec_promotions.rb b/db/migrate/20170313052632_add_columns_to_exec_promotions.rb new file mode 100644 index 0000000..ce7d62f --- /dev/null +++ b/db/migrate/20170313052632_add_columns_to_exec_promotions.rb @@ -0,0 +1,5 @@ +class AddColumnsToExecPromotions < ActiveRecord::Migration[5.0] + def change + add_column :exec_promotions, :user_id, :string + end +end diff --git a/db/migrate/20170313053820_add_reason_to_exec.rb b/db/migrate/20170313053820_add_reason_to_exec.rb new file mode 100644 index 0000000..a71f963 --- /dev/null +++ b/db/migrate/20170313053820_add_reason_to_exec.rb @@ -0,0 +1,5 @@ +class AddReasonToExec < ActiveRecord::Migration[5.0] + def change + add_column :exec_promotions, :reason, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 623e82e..99d4cd4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,14 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170308001010) do +ActiveRecord::Schema.define(version: 20170313053820) do + + create_table "exec_promotions", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "user_id" + t.text "reason" + end create_table "love_letters", force: :cascade do |t| t.string "title" diff --git a/test/controllers/exec_promotions_controller_test.rb b/test/controllers/exec_promotions_controller_test.rb new file mode 100644 index 0000000..be6993a --- /dev/null +++ b/test/controllers/exec_promotions_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ExecPromotionsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/exec_promotions.yml b/test/fixtures/exec_promotions.yml new file mode 100644 index 0000000..80aed36 --- /dev/null +++ b/test/fixtures/exec_promotions.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/exec_promotion_test.rb b/test/models/exec_promotion_test.rb new file mode 100644 index 0000000..28f73f0 --- /dev/null +++ b/test/models/exec_promotion_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ExecPromotionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 524c2750b8d683ba0872e0a0aba83b125dc8c017 Mon Sep 17 00:00:00 2001 From: Arka Ganguli Date: Wed, 15 Mar 2017 18:35:23 -0400 Subject: [PATCH 2/3] add a pending column and only let someone submit exec request if theyre not pending --- app/helpers/exec_promotions_helper.rb | 10 ++++++++++ app/views/devise/registrations/edit.html.erb | 2 +- app/views/exec_promotions/new.html.erb | 2 +- .../20170315222839_add_resolved_to_exec_promotion.rb | 5 +++++ db/schema.rb | 7 ++++--- 5 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20170315222839_add_resolved_to_exec_promotion.rb diff --git a/app/helpers/exec_promotions_helper.rb b/app/helpers/exec_promotions_helper.rb index 1f34ac5..af0aba3 100644 --- a/app/helpers/exec_promotions_helper.rb +++ b/app/helpers/exec_promotions_helper.rb @@ -1,2 +1,12 @@ module ExecPromotionsHelper + + def pending_requests(user) + pending = ExecPromotion.where(user_id: user.id, resolved: false) + + if pending.empty? + return false + end + + return true + end end diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 72481ec..bc5d206 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -46,7 +46,7 @@
- <% if !current_user.is_exec %> + <% if !current_user.is_exec && !pending_requests(current_user) %> <%= render partial: "exec_promotions/request_promotion" %> <% end %>
diff --git a/app/views/exec_promotions/new.html.erb b/app/views/exec_promotions/new.html.erb index b509227..f6847ff 100644 --- a/app/views/exec_promotions/new.html.erb +++ b/app/views/exec_promotions/new.html.erb @@ -4,6 +4,6 @@ <%= f.text_area :reason %>

- <%= f.submit %> + <%= f.submit "Submit Request"%>

<% end %> diff --git a/db/migrate/20170315222839_add_resolved_to_exec_promotion.rb b/db/migrate/20170315222839_add_resolved_to_exec_promotion.rb new file mode 100644 index 0000000..38713a6 --- /dev/null +++ b/db/migrate/20170315222839_add_resolved_to_exec_promotion.rb @@ -0,0 +1,5 @@ +class AddResolvedToExecPromotion < ActiveRecord::Migration[5.0] + def change + add_column :exec_promotions, :resolved, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 99d4cd4..1648714 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,13 +10,14 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170313053820) do +ActiveRecord::Schema.define(version: 20170315222839) do create_table "exec_promotions", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "user_id" t.text "reason" + t.boolean "resolved", default: false end create_table "love_letters", force: :cascade do |t| From 3c375244baa231004ee23e25fb9002a516a0543f Mon Sep 17 00:00:00 2001 From: Arka Ganguli Date: Wed, 15 Mar 2017 18:38:02 -0400 Subject: [PATCH 3/3] add resolved column --- app/views/exec_promotions/index.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/exec_promotions/index.html.erb b/app/views/exec_promotions/index.html.erb index 12d8f0f..fa4eb55 100644 --- a/app/views/exec_promotions/index.html.erb +++ b/app/views/exec_promotions/index.html.erb @@ -5,6 +5,7 @@ User ID Reason + Resolved @@ -12,6 +13,7 @@ <%= promotion.user_id %> <%= promotion.reason %> + <%= promotion.resolved %> <% end %>