diff --git a/app/assets/stylesheets/app.scss b/app/assets/stylesheets/app.scss new file mode 100644 index 0000000..deb6210 --- /dev/null +++ b/app/assets/stylesheets/app.scss @@ -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; +} diff --git a/app/controllers/course_controller.rb b/app/controllers/course_controller.rb index 7f37cf6..e5fc01c 100644 --- a/app/controllers/course_controller.rb +++ b/app/controllers/course_controller.rb @@ -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 @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ef59381..dc5afcc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 @@ -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? diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..c9c9ab2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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&s=40", + height: "#{height}", + width: "#{width}", + alt: "@#{user.username}", + class: "avatar" + ) + end end diff --git a/app/models/user.rb b/app/models/user.rb index 4eadaab..6a6cf8d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ApplicationRecord + include RailsSettings::Extend def self.create_with_omniauth(auth) create! do |user| @@ -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 diff --git a/app/views/layouts/_nav_links_for_auth.html.erb b/app/views/layouts/_nav_links_for_auth.html.erb index 2b1155e..01f3cfe 100644 --- a/app/views/layouts/_nav_links_for_auth.html.erb +++ b/app/views/layouts/_nav_links_for_auth.html.erb @@ -1,12 +1,23 @@ <% if user_signed_in? %> -
In order to work in pairs or groups for your assignments, you must be "discoverable" by your classmates.
+The information that becomes accessible to your fellow classmates if you become "discoverable" includes but is not limited to: +
Do you wish to be set as "discoverable" so that you can be found by your classmates?
+ +