Skip to content

Commit

Permalink
Merge pull request #9 from UCSB-CS-Using-GitHub-In-Courses/feature/us…
Browse files Browse the repository at this point in the history
…er-settings

Feature/user settings
  • Loading branch information
ncbrown1 authored Mar 3, 2017
2 parents be75d56 + 946c371 commit 7376880
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 16 deletions.
22 changes: 22 additions & 0 deletions app/assets/stylesheets/app.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.avatar {
display: inline-block;
overflow: hidden;
line-height: 1;
vertical-align: middle;
border-radius: 3px;
}
.user-nav .avatar {
float: left;
margin-right: 5px;
}
.dropdown-caret {
display: inline-block;
width: 0;
height: 0;
vertical-align: middle;
content: "";
border: 4px solid;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: transparent;
}
4 changes: 2 additions & 2 deletions app/controllers/course_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CourseController < ApplicationController
def show
@course_name = Setting.course
@course_org = nil
if @course_name
if !@course_name.blank?
mo = machine_octokit
@course_org = mo.org(@course_name)
else
Expand All @@ -14,7 +14,7 @@ def show
end

def setup
if Setting.course
if !Setting.course.blank?
redirect_to course_path, alert: "A course has already been set up for this application"
else
client = session_octokit
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class UsersController < ApplicationController
before_action :authenticate_user!
before_action :require_instructor!, :except => [:match_to_student]
before_action :correct_user?, :except => [:index, :set_as_instructor]
before_action :correct_user?, :only => [:show]

def index
@users = User.all
Expand All @@ -11,6 +11,15 @@ def show
@user = User.find(params[:id])
end

def settings
@user_settings = current_user.settings
end

def update_settings
current_user.settings.discoverable = params[:discoverable] == "1"
redirect_to settings_path, notice: "Settings have been updated"
end

def toggle_instructor_privilege
user = User.find(params[:id])
if is_instructor?
Expand Down
9 changes: 9 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
module ApplicationHelper
def github_profile_img_for(user, height=20, width=20)
image_tag(
"https://avatars2.githubusercontent.com/u/#{user.uid}?v=3&amp;s=40",
height: "#{height}",
width: "#{width}",
alt: "@#{user.username}",
class: "avatar"
)
end
end
9 changes: 9 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class User < ApplicationRecord
include RailsSettings::Extend

def self.create_with_omniauth(auth)
create! do |user|
Expand All @@ -11,6 +12,14 @@ def self.create_with_omniauth(auth)
end
end

def discoverable?
self.settings.discoverable == true
end

def self.discoverable_users
User.with_settings_for('discoverable').select {|u| u.discoverable? }
end

def attempt_match_to_student(client, machine)
course = Setting.course
return if not course
Expand Down
29 changes: 20 additions & 9 deletions app/views/layouts/_nav_links_for_auth.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<% if user_signed_in? %>
<li><%= link_to 'Sign out', signout_path %></li>
<li class="dropdown user-nav">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<%= github_profile_img_for current_user %>
<span class="dropdown-caret"></span>
</a>
<ul class="dropdown-menu">
<li class="dropdown-header">Signed in as <b><%= current_user.username %></b></li>
<li role="separator" class="divider"></li>
<li><a href="https://github.com/<%= current_user.username %>">GitHub Profile</a></li>
<li><a href="https://github.com/<%= @course %>">Course Organization</a></li>
<li role="separator" class="divider"></li>
<li><%= link_to 'Settings', settings_path %></li>
<li><%= link_to 'Sign out', signout_path %></li>
</ul>
</li>
<% else %>
<li><%= link_to 'Sign in', signin_path %></li>
<% end %>
<% if user_signed_in? %>
<li><%= link_to 'Course', course_path %></li>
<% end %>
<% if is_instructor? %>
<li><%= link_to 'Users', users_path %></li>
<li><%= link_to 'Course Roster', students_path %></li>
<li><p class="navbar-btn">
<%= link_to signin_path, class: 'btn btn-info' do %>
<%= fa_icon "github", text: "Sign in" %>
<% end %>
</p></li>
<% end %>
2 changes: 2 additions & 0 deletions app/views/layouts/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<%= render 'layouts/navigation_links' %>
</ul>
<ul class="nav navbar-nav navbar-right">
<%= render 'layouts/nav_links_for_auth' %>
</ul>
</div>
Expand Down
8 changes: 7 additions & 1 deletion app/views/layouts/_navigation_links.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
<%# add navigation links to this file %>
<!-- <li><%= link_to 'About', page_path('about') %></li> -->
<% if user_signed_in? %>
<li><%= link_to 'Course', course_path %></li>
<% end %>
<% if is_instructor? %>
<li><%= link_to 'Users', users_path %></li>
<li><%= link_to 'Course Roster', students_path %></li>
<% end %>
25 changes: 25 additions & 0 deletions app/views/users/settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="container">
<h1>User Settings</h1>

<%= form_tag(update_settings_path) do -%>
<p>In order to work in pairs or groups for your assignments, you must be "discoverable" by your classmates.</p>
<p>The information that becomes accessible to your fellow classmates if you become "discoverable" includes but is not limited to:
<ul>
<li>Your name</li>
<li>Your school email address</li>
<li>Your github username</li>
<li>The fact that you are enrolled in this course</li>
</ul>
</p>
<p>Do you wish to be set as "discoverable" so that you can be found by your classmates?</p>

<div class="checkbox">
<label>
<%= check_box_tag 'discoverable', 1, @user_settings.discoverable %>
Make me discoverable by classmates.
</label>
</div>

<div><%= button_tag 'Save Settings', class: "btn btn-primary" %></div>
<% end -%>
</div>
3 changes: 1 addition & 2 deletions config/app.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# config/app.yml for rails-settings-cached
defaults: &defaults
foo: "Foo"
bar: 123
discoverable: false
instructors: []

development:
Expand Down
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

post '/students/import'
resources :students

get '/settings' => 'users#settings'
post '/settings' => 'users#update_settings', :as => :update_settings
resources :users do
member do
post 'toggle_instructor_privilege'
post 'match' => 'users#match_to_student'
end
end

get '/auth/:provider/callback' => 'sessions#create'
get '/signin' => 'sessions#new', :as => :signin
get '/signout' => 'sessions#destroy', :as => :signout
Expand Down

0 comments on commit 7376880

Please sign in to comment.