Skip to content

Commit

Permalink
Fixed Merging Conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
BenFan1002 committed Oct 8, 2024
2 parents 0ec685a + 9422e6c commit bbe10d7
Show file tree
Hide file tree
Showing 54 changed files with 457 additions and 337 deletions.
39 changes: 22 additions & 17 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
source "https://rubygems.org"
# frozen_string_literal: true

source 'https://rubygems.org'

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.2.1"
gem 'rails', '~> 7.2.1'
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"
gem 'sprockets-rails'
# Use sqlite3 as the database for Active Record
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"
gem 'puma', '>= 5.0'
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"
gem 'importmap-rails'
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"
gem 'turbo-rails'
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"
gem 'stimulus-rails'
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"
gem 'jbuilder'
# Use Redis adapter to run Action Cable in production
# gem "redis", ">= 4.0.1"

Expand All @@ -25,10 +27,10 @@ gem "jbuilder"
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ windows jruby ]
gem 'tzinfo-data', platforms: %i[windows jruby]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false
gem 'bootsnap', require: false

# OmniAuth for Google login
gem 'omniauth'
Expand All @@ -43,31 +45,34 @@ gem 'csv'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
gem 'debug', platforms: %i[mri windows], require: 'debug/prelude'

# Static analysis for security vulnerabilities [https://brakemanscanner.org/]
gem "brakeman", require: false
gem 'brakeman', require: false

# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
gem "rubocop-rails-omakase", require: false
gem 'rubocop-rails-omakase', require: false

gem "sqlite3", "~> 1.4"
gem 'sqlite3', '~> 1.4'
end

group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
gem 'web-console'
end

group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem 'capybara'
gem 'cucumber-rails', require: false
gem 'database_cleaner'
gem 'rails-controller-testing'
gem 'rspec-rails'
gem 'selenium-webdriver'
gem 'simplecov', require: false
gem 'ZenTest'
end
group :production do
gem 'pg' # for Heroku deployment
end

2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ GEM
parser (3.3.5.0)
ast (~> 2.4.1)
racc
pg (1.5.8)
psych (5.1.2)
stringio
public_suffix (6.0.1)
Expand Down Expand Up @@ -444,6 +445,7 @@ DEPENDENCIES
omniauth
omniauth-google-oauth2
omniauth-rails_csrf_protection
pg
puma (>= 5.0)
rails (~> 7.2.1)
rails-controller-testing
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bundle exec rails server -p $PORT
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ The key stakeholder for this application is the Associate Department Head, who i

## Links
- **App** : https://faculty-teaching-assignment-31f5f9c405bc.herokuapp.com
- **Working agreement** : https://github.com/tamu-edu-students/Faculty-Teaching-Assignment/blob/documentation/documentation/Fall2024/Team%20Working%20Agreement.md
- **Team Working agreement** : https://github.com/tamu-edu-students/Faculty-Teaching-Assignment/blob/documentation/documentation/Fall2024/Team%20Working%20Agreement.md
- **Sprint Plans**:
- Sprint 1: https://github.com/tamu-edu-students/Faculty-Teaching-Assignment/blob/documentation/documentation/Fall2024/Sprint_1_Plan.pdf
- Sprint 1:
- Goal: Setup and understand the project, get client data and enable user login and authentication
- https://github.com/tamu-edu-students/Faculty-Teaching-Assignment/blob/documentation/documentation/Fall2024/Sprint_1_Plan.pdf
- **Code Climate Report**: https://codeclimate.com/github/tamu-edu-students/Faculty-Teaching-Assignment
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative "config/application"
require_relative 'config/application'

Rails.application.load_tasks
34 changes: 20 additions & 14 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
# frozen_string_literal: true

# ApplicationController serves as the base controller for all other controllers in the application.
# It enforces user authentication for all actions unless overridden, and supports browser version
# restrictions for modern features like webp images, web push, badges, etc.
class ApplicationController < ActionController::Base
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
# Require users to be logged in
before_action :require_login

private
def current_user
# if @current _user is undefined or falsy, evaluate the RHS
# Look up user by id if user id is in the session hash
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end

def logged_in?
current_user
end
def current_user
# if @current _user is undefined or falsy, evaluate the RHS
# Look up user by id if user id is in the session hash
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end

def logged_in?
current_user
end

def require_login
# redirect to the welcome page unless user is logged in
return if logged_in?

def require_login
# redirect to the welcome page unless user is logged in
unless logged_in?
redirect_to welcome_path, alert: 'You must be logged in to access this section.'
end
end
redirect_to welcome_path, alert: 'You must be logged in to access this section.'
end
end
31 changes: 20 additions & 11 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
# frozen_string_literal: true

# SessionsController handles user authentication with OmniAuth for Google OAuth2.
class SessionsController < ApplicationController
# Don't require login for login page
skip_before_action :require_login, only: [:omniauth]

# GET /logout
def logout
reset_session
redirect_to welcome_path, notice: 'You are logged out'
end

# GET /auth/google_oauth2/callback
def omniauth
auth = request.env['omniauth.auth']
@user = User.find_or_create_by(uid: auth['uid'], provider: auth['provider']) do |u|
u.email = auth['info']['email']
names = auth['info']['name'].split
u.first_name = names[0]
u.last_name = names[1..].join(' ')
end

@user = find_or_create_user_from_auth(auth_info)

if @user.valid?
session[:user_id] = @user.id
redirect_to user_path(@user), notice: 'You are logged in'
else
redirect_to welcome_path, alert: 'Login failed'
end
end

private

def auth_info
request.env['omniauth.auth']
end

def find_or_create_user_from_auth(auth)
User.find_or_create_by(uid: auth['uid'], provider: auth['provider']) do |user|
user.email = auth['info']['email']
names = auth['info']['name'].split
user.first_name = names[0]
user.last_name = names[1..].join(' ')
end
end
end
4 changes: 4 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# frozen_string_literal: true

# UsersController handles displaying user-related data.
# The show action retrieves and displays the current user based on the ID provided in the parameters.
class UsersController < ApplicationController
def show
@current_user = User.find(params[:id])
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# app/controllers/welcome_controller.rb
# frozen_string_literal: true

# WelcomeController handles displaying the public welcome page.
# It skips the login requirement for the index action and redirects logged-in users
# to their user page with a personalized welcome message.
class WelcomeController < ApplicationController
# Don't require login for the public welcome page
skip_before_action :require_login, only: [:index]
Expand All @@ -11,4 +15,4 @@ def index
redirect_to user_path(@current_user)
end
end
end
end
3 changes: 3 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# frozen_string_literal: true

# ApplicationHelper is used to store helper methods that can be used across views.
module ApplicationHelper
end
3 changes: 3 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# frozen_string_literal: true

# ApplicationRecord serves as the base class for all models in the application.
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# frozen_string_literal: true

# The User model represents users in the application.
class User < ApplicationRecord
validates :email, presence: true
end
10 changes: 6 additions & 4 deletions bin/brakeman
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
# frozen_string_literal: true

ARGV.unshift("--ensure-latest")
require 'rubygems'
require 'bundler/setup'

load Gem.bin_path("brakeman", "brakeman")
ARGV.unshift('--ensure-latest')

load Gem.bin_path('brakeman', 'brakeman')
Loading

0 comments on commit bbe10d7

Please sign in to comment.