Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook up user stuff #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/assets/javascripts/exec_promotions.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/exec_promotions.scss
Original file line number Diff line number Diff line change
@@ -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/
37 changes: 37 additions & 0 deletions app/controllers/exec_promotions_controller.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions app/helpers/exec_promotions_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +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
2 changes: 2 additions & 0 deletions app/models/exec_promotion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ExecPromotion < ApplicationRecord
end
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 17 additions & 2 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@
</div>
<% end %>

<h3>Cancel my account</h3>
<h2>Other options</h2>
<p id="notice"><%= notice %></p>

<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<div>
<% if current_user.is_president %>
<%= link_to "Approve exec requests", exec_promotions_path %>
<% end %>
</div>

<div>
<% if !current_user.is_exec && !pending_requests(current_user) %>
<%= render partial: "exec_promotions/request_promotion" %>
<% end %>
</div>

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

<%= link_to "Back", :back %>
8 changes: 7 additions & 1 deletion app/views/events/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<ul>
<li class="current"><a href="index.html">Home</a></li>
<li><a href="events.html">Events</a></li>
<li><a href="#" class="button special">Sign Up</a></li>
<% if user_signed_in? %>
<li><%= link_to 'Account', edit_user_registration_path %></li>
<li><%= link_to 'Sign out', destroy_user_session_path, :method => :delete %></li>
<% else %>
<li><%= link_to 'Sign up', new_user_registration_path %></li>
<li><%= link_to 'Sign in', new_user_session_path %></li>
<% end %>
</ul>
</nav>
1 change: 1 addition & 0 deletions app/views/exec_promotions/_request_promotion.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= link_to "Request exec privileges", new_exec_promotion_path %>
20 changes: 20 additions & 0 deletions app/views/exec_promotions/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h1>All exec promotion requests</h1>

<table>
<thead>
<tr>
<th>User ID</th>
<th>Reason</th>
<th>Resolved</th>
</tr>
</thead>
<tbody>
<% @exec_promotions.each do |promotion| %>
<tr>
<td><%= promotion.user_id %></td>
<td><%= promotion.reason %></td>
<td><%= promotion.resolved %></td>
</tr>
<% end %>
</tbody>
</table>
9 changes: 9 additions & 0 deletions app/views/exec_promotions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= form_for(@exec_promotion) do |f| %>
<p>
<%= f.label :reason %><br />
<%= f.text_area :reason %>
</p>
<p>
<%= f.submit "Submit Request"%>
</p>
<% end %>
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions db/migrate/20170313051920_create_exec_promotions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateExecPromotions < ActiveRecord::Migration[5.0]
def change
create_table :exec_promotions do |t|

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170313052632_add_columns_to_exec_promotions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddColumnsToExecPromotions < ActiveRecord::Migration[5.0]
def change
add_column :exec_promotions, :user_id, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170313053820_add_reason_to_exec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddReasonToExec < ActiveRecord::Migration[5.0]
def change
add_column :exec_promotions, :reason, :text
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170315222839_add_resolved_to_exec_promotion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddResolvedToExecPromotion < ActiveRecord::Migration[5.0]
def change
add_column :exec_promotions, :resolved, :boolean, default: false
end
end
10 changes: 9 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170308001010) 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.string "user_id"
t.text "reason"
t.boolean "resolved", default: false
end

create_table "love_letters", force: :cascade do |t|
t.string "title"
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/exec_promotions_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class ExecPromotionsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
11 changes: 11 additions & 0 deletions test/fixtures/exec_promotions.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/models/exec_promotion_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class ExecPromotionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end