Skip to content

Commit

Permalink
Merge pull request #7 from DawnPaladin/user_accounts
Browse files Browse the repository at this point in the history
User accounts
  • Loading branch information
DawnPaladin committed Feb 13, 2017
2 parents 98b109c + 9bd88e1 commit 55abd7b
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 45 deletions.
4 changes: 4 additions & 0 deletions app/assets/javascripts/app.js
Expand Up @@ -20,6 +20,7 @@ planner.run(['$rootScope', function($rootScope){
planner.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/students');
$stateProvider

.state('dashboard', {
url: '',
views: {
Expand All @@ -32,6 +33,7 @@ planner.config(['$stateProvider', '$urlRouterProvider', function($stateProvider,
}
}
})

.state('dashboard.students', {
url: '/students',
resolve: {
Expand All @@ -49,6 +51,7 @@ planner.config(['$stateProvider', '$urlRouterProvider', function($stateProvider,
}
}
})

.state('dashboard.meetings', {
url: '/classes',
views: {
Expand All @@ -58,4 +61,5 @@ planner.config(['$stateProvider', '$urlRouterProvider', function($stateProvider,
}
}
});

}]);
17 changes: 10 additions & 7 deletions app/controllers/advisors/registrations_controller.rb
Expand Up @@ -4,6 +4,7 @@ class Advisors::RegistrationsController < Devise::RegistrationsController

skip_before_action :require_no_authentication, only: [:new, :create]
before_action :require_admin, only: [:new, :create]
before_action :require_current_advisor, only: [:edit]

# GET /resource/sign_up
def new
Expand All @@ -30,7 +31,9 @@ def create
# Commented Out to Override Devise's Automatic Login Upon Creation
# sign_up(resource_name, resource)

respond_with resource, location: after_sign_up_path_for(resource)
redirect_to advisors_path

# respond_with resource, location: after_sign_up_path_for(resource)
else
set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
expire_data_after_sign_in!
Expand All @@ -44,14 +47,14 @@ def create
end

# GET /resource/edit
# def edit
# super
# end
def edit
super
end

# PUT /resource
# def update
# super
# end
def update
super
end

# DELETE /resource
# def destroy
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -21,4 +21,10 @@ def require_admin
end
end

def require_current_advisor
unless current_advisor.id == params[:id].to_i
redirect_back(fallback_location: root_path)
end
end

end
2 changes: 1 addition & 1 deletion app/views/advisors/_delete_advisor.html.erb
@@ -1 +1 @@
<%= link_to "Delete Advisor?", advisor_path(advisor), method: :delete, data: { confirm: "Are you sure you want to delete #{ advisor.name }?" } %>
<%= button_to "Delete", advisor_path(advisor), method: :delete, data: { confirm: "Are you sure you want to delete #{ advisor.name }?"} %>
10 changes: 8 additions & 2 deletions app/views/advisors/index.html.erb
Expand Up @@ -6,7 +6,7 @@
<th>Last Name</th>
<th>Email</th>
<th>Admin Status</th>
<th>Delete</th>
<th>Delete?</th>
</tr>
<% @advisors.each do |advisor| %>
<tr>
Expand All @@ -15,11 +15,17 @@
<td><%= advisor.email %></td>
<td>
<%= advisor_status(advisor) %>

</td>
<td>
<%= advisor_deletion(advisor) %>
</td>
</tr>
<% end %>
</table>
</table>

<a href="/advisors/sign_up" id="add-advisor" class="btn btn-primary">Add new admin or advisor</a>




2 changes: 1 addition & 1 deletion app/views/angular_app/index.html.erb
@@ -1,4 +1,4 @@
<div ui-view="dashboardHeader"></div>
<div class="container">
<div ui-view="dashboardHeader"></div>
<div ui-view="dashboardMain"></div>
</div>
2 changes: 1 addition & 1 deletion app/views/devise/registrations/edit.html.erb
@@ -1,4 +1,4 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<h2>Edit Your Account</h2>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
Expand Down
6 changes: 4 additions & 2 deletions app/views/devise/registrations/new.html.erb
@@ -1,4 +1,4 @@
<h2>Sign up</h2>
<h2>Add An Advisor</h2>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
Expand Down Expand Up @@ -37,8 +37,10 @@
</div>

<div class="actions">
<%= f.submit "Sign up" %>
<%= f.submit "Create Advisor" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
<%= link_to "Back", :back %>
8 changes: 0 additions & 8 deletions app/views/devise/shared/_links.html.erb
@@ -1,11 +1,3 @@
<%- if controller_name != 'sessions' %>
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end -%>

<!-- <%#- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%#= link_to "Sign up", new_registration_path(resource_name) %><br />
<%# end -%> -->

<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
Expand Down
5 changes: 4 additions & 1 deletion app/views/layouts/application.html.erb
Expand Up @@ -9,7 +9,10 @@
</head>

<body>
<%= render 'shared/navbar' %>
<%= render "shared/flash" %>
<%= yield %>
<div class="container">
<%= yield %>
</div>
</body>
</html>
8 changes: 5 additions & 3 deletions app/views/shared/_flash.html.erb
@@ -1,7 +1,9 @@
<% if flash.any? %>
<div id="flash">
<% flash.each do |k, v| %>
<p><%= v %></p>
<% end %>
<div class="container-fluid">
<% flash.each do |k, v| %>
<p><%= v %></p>
<% end %>
</div>
</div>
<% end %>
13 changes: 13 additions & 0 deletions app/views/shared/_navbar.html.erb
@@ -0,0 +1,13 @@
<nav class="navbar navbar-default">
<div class="container-fluid">
<span class="navbar-brand">GIAL Degree Planner</span>
<p class="navbar-text"><%= link_to "Go To Dashboard", root_path, class: "navbar-link" %></p>
<% if signed_in? %>
<div class="navbar-right">
<p class="navbar-text">Welcome, <%= current_advisor.name %>!</p>
<p class="navbar-text"><%= link_to "Edit Account", edit_advisor_registration_path(id: current_advisor.id), class: "navbar-link" %></p>
<p class="navbar-text"><%= link_to "Log Out", destroy_advisor_session_path, class: "navbar-link" %></p>
</div>
<% end %>
</div>
</nav>
2 changes: 1 addition & 1 deletion config/locales/devise.en.yml
Expand Up @@ -38,7 +38,7 @@ en:
destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
signed_up_as_admin: "Admin successfully added."
signed_up_as_advisor: "Advisor successfully added."
signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
signed_up_but_inactive: "Advisor successfully signed up. However, we could not sign advisor in because their account is not yet activated."
signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address."
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Expand Up @@ -6,6 +6,8 @@
get 'advisors/sign_out', to: 'advisors/sessions#destroy'
end

resources :advisors, only: [:index, :update, :destroy]

scope :api do
scope :v1 do
resources :students
Expand All @@ -19,6 +21,6 @@

get 'angular_app/index'

resources :advisors, only: [:index, :update, :destroy]


end
16 changes: 5 additions & 11 deletions public/templates/dashboard-header.html
@@ -1,15 +1,9 @@
<div class="container">

<h1>Welcome, admin_name!</h1>
<h2>Dashboard</h2>

<p><a href="/advisors/sign_out">Sign Out</a></p>
<p><a href="/advisors/edit">Edit my account settings</a></p>
<a ui-sref="dashboard.students">Students</a>
<a ui-sref="dashboard.meetings">Classes</a>
<a href="/advisors" ng-if="currentAdvisor.is_admin">Advisors</a>

<div ng-if="currentAdvisor.is_admin">
<p><a href="/advisors/sign_up" id="add-advisor">Add new admin or advisor</a></p>
<p><a href="/advisors">View advisors</a></p>
</div>

<h2>Dashboard</h2>

<a ui-sref="dashboard.students">Students</a>
<a ui-sref="dashboard.meetings">Classes</a>
1 change: 0 additions & 1 deletion public/templates/dashboard-main.html
@@ -1,2 +1 @@
Dashboard-main
<div ui-view></div>
13 changes: 8 additions & 5 deletions spec/features/advisor_spec.rb
Expand Up @@ -192,16 +192,16 @@
end

scenario 'it deletes the advisor', js: true do
expect{ click_on('Delete Advisor?') }.to change(Advisor, :count).by(-1)
expect{ click_on('Delete') }.to change(Advisor, :count).by(-1)
end

scenario 'it renders a flash message', js: true do
click_on('Delete Advisor?')
click_on('Delete')
expect(page).to have_css('#flash')
end

scenario 'it remains on the advisors index page', js: true do
click_on('Delete Advisor?')
click_on('Delete')
expect(current_path).to eq(advisors_path)
end

Expand All @@ -216,8 +216,11 @@
click_on('View advisors')
end

scenario 'it does not display a delete link', js: true do
expect(page).to_not have_content('Delete Advisor?')
scenario 'it does not display a delete link', js: true, test_me: true do

within(:css, "td:last-child") do
expect(page).to_not have_content('Delete')
end
end

end
Expand Down

0 comments on commit 55abd7b

Please sign in to comment.