Skip to content

Commit

Permalink
Merge pull request #26 from tamu-edu-students/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
Abhishek-More authored Feb 8, 2023
2 parents f291649 + 88a7bbd commit dc6109f
Show file tree
Hide file tree
Showing 24 changed files with 802 additions and 429 deletions.
499 changes: 253 additions & 246 deletions app/controllers/experiences_controller.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/controllers/programs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def edit
def update
@program = Program.find params[:id]
@program.update_attributes(name: params[:program][:name], location: params[:program][:location],
region: params[:program][:region])
region: params[:program][:region])
flash[:notice] = "#{@program.name} was successfully updated."
redirect_to programs_path
end
Expand Down
90 changes: 45 additions & 45 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
# frozen_string_literal: true

class SessionsController < ApplicationController
def create
user_info = request.env['omniauth.auth']

# Allow non tamu emails for testing
if params[:hd] != 'tamu.edu' && 1.zero?
flash[:alert] = 'Must login with @tamu.edu email address!'
redirect_to root_path and return
end

dbUser = User.find_by email: user_info['info']['email']
if dbUser.nil?
dbUser = User.create(uid: user_info['uid'], name: user_info['info']['name'],
email: user_info['info']['email'])
elsif dbUser.banned
flash[:alert] = 'Your account has been banned! Please contact the administrators.'
redirect_to root_path and return
end

# if email address matches the one in the /config/application.rb file then make that user an admin
if user_info['info']['email'] == Rails.configuration.admin_email
dbUser.admin = true
dbUser.save
end

session[:user] = dbUser.id
session[:user_admin] = dbUser.admin
session[:user_img] = user_info['info']['image']
session[:user_program_id] = dbUser.program_id
session[:user_email] = dbUser.email

redirect_to(root_path) and return
end

def destroy
session.delete :user
session.delete :user_admin
session.delete :user_img
session.delete :user_program_id
session.delete :user_email
redirect_to root_path
end
end
# frozen_string_literal: true

class SessionsController < ApplicationController
def create
user_info = request.env['omniauth.auth']

# Allow non tamu emails for testing
if params[:hd] != 'tamu.edu' && 1.zero?
flash[:alert] = 'Must login with @tamu.edu email address!'
redirect_to root_path and return
end

dbUser = User.find_by email: user_info['info']['email']
if dbUser.nil?
dbUser = User.create(uid: user_info['uid'], name: user_info['info']['name'],
email: user_info['info']['email'])
elsif dbUser.banned
flash[:alert] = 'Your account has been banned! Please contact the administrators.'
redirect_to root_path and return
end

# if email address matches the one in the /config/application.rb file then make that user an admin
if user_info['info']['email'] == Rails.configuration.admin_email
dbUser.admin = true
dbUser.save
end

session[:user] = dbUser.id
session[:user_admin] = dbUser.admin
session[:user_img] = user_info['info']['image']
session[:user_program_id] = dbUser.program_id
session[:user_email] = dbUser.email

redirect_to(root_path) and return
end

def destroy
session.delete :user
session.delete :user_admin
session.delete :user_img
session.delete :user_program_id
session.delete :user_email
redirect_to root_path
end
end
13 changes: 7 additions & 6 deletions app/controllers/tips_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ def new
end

def create
participant = Participant.find_by(email: current_user.email, program_id: params[:id])
if participant.nil?
flash[:alert] = 'You are not authorized to manage tips for this program'
redirect_to portal_path(params[:id]) and return
end
# participant = Participant.find_by(email: current_user.email, program_id: params[:id])
# if participant.nil?
# flash[:notice] = 'You are not authorized to manage tips for this program'
# redirect_to portal_path(params[:id]) and return
# end

if params[:tip][:tip].blank? # tip text is required
flash[:alert] = 'Cannot create tip'
flash[:notice] = 'Cannot create tip'
redirect_to portal_path(params[:id]) and return
end

Tip.create(tip: params[:tip][:tip], user_id: current_user.id, program_id: params[:id])
flash[:notice] = "Tip was successfully created."
redirect_to portal_path(params[:id])
end

Expand Down
230 changes: 114 additions & 116 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand All @@ -12,140 +10,140 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20_230_112_141_145) do
create_table 'active_storage_attachments', force: :cascade do |t|
t.string 'name', null: false
t.string 'record_type', null: false
t.integer 'record_id', null: false
t.integer 'blob_id', null: false
t.datetime 'created_at', null: false
t.index ['blob_id'], name: 'index_active_storage_attachments_on_blob_id'
t.index %w[record_type record_id name blob_id], name: 'index_active_storage_attachments_uniqueness',
unique: true
ActiveRecord::Schema.define(version: 2023_01_12_141145) do

create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.integer "record_id", null: false
t.integer "blob_id", null: false
t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end

create_table 'active_storage_blobs', force: :cascade do |t|
t.string 'key', null: false
t.string 'filename', null: false
t.string 'content_type'
t.text 'metadata'
t.bigint 'byte_size', null: false
t.string 'checksum', null: false
t.datetime 'created_at', null: false
t.index ['key'], name: 'index_active_storage_blobs_on_key', unique: true
create_table "active_storage_blobs", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
t.text "metadata"
t.bigint "byte_size", null: false
t.string "checksum", null: false
t.datetime "created_at", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end

create_table 'experience_comments', force: :cascade do |t|
t.text 'comment'
t.integer 'rating'
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
t.integer 'experience_id'
t.integer 'user_id'
t.index ['experience_id'], name: 'index_experience_comments_on_experience_id'
t.index ['user_id'], name: 'index_experience_comments_on_user_id'
create_table "experience_comments", force: :cascade do |t|
t.text "comment"
t.integer "rating"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "experience_id"
t.integer "user_id"
t.index ["experience_id"], name: "index_experience_comments_on_experience_id"
t.index ["user_id"], name: "index_experience_comments_on_user_id"
end

create_table 'experiences', force: :cascade do |t|
t.text 'experience'
t.integer 'rating'
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
t.integer 'program_id'
t.integer 'user_id'
t.string 'tags'
t.string 'title'
t.index ['program_id'], name: 'index_experiences_on_program_id'
t.index ['user_id'], name: 'index_experiences_on_user_id'
create_table "experiences", force: :cascade do |t|
t.text "experience"
t.integer "rating"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "program_id"
t.integer "user_id"
t.string "tags"
t.string "title"
t.index ["program_id"], name: "index_experiences_on_program_id"
t.index ["user_id"], name: "index_experiences_on_user_id"
end

create_table 'helpful_votes', force: :cascade do |t|
t.integer 'vote'
t.integer 'tip_id'
t.integer 'user_id'
t.index ['tip_id'], name: 'index_helpful_votes_on_tip_id'
t.index ['user_id'], name: 'index_helpful_votes_on_user_id'
create_table "helpful_votes", force: :cascade do |t|
t.integer "vote"
t.integer "tip_id"
t.integer "user_id"
t.index ["tip_id"], name: "index_helpful_votes_on_tip_id"
t.index ["user_id"], name: "index_helpful_votes_on_user_id"
end

create_table 'participants', force: :cascade do |t|
t.boolean 'is_faculty'
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
t.integer 'program_id'
t.string 'email'
t.index ['program_id'], name: 'index_participants_on_program_id'
create_table "participants", force: :cascade do |t|
t.boolean "is_faculty"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "program_id"
t.string "email"
t.index ["program_id"], name: "index_participants_on_program_id"
end

create_table 'programs', force: :cascade do |t|
t.string 'name'
t.string 'region'
t.string 'location'
t.boolean 'disabled', default: false
create_table "programs", force: :cascade do |t|
t.string "name"
t.string "region"
t.string "location"
t.boolean "disabled", default: false
end

create_table 'reviews', force: :cascade do |t|
t.string 'business_id'
t.string 'user_email'
t.text 'comment'
t.integer 'rating'
t.integer 'price'
t.integer 'safety'
t.integer 'service'
t.boolean 'cash_only'
t.boolean 'english'
t.boolean 'tips'
t.boolean 'wifi'
t.boolean 'wheelchair'
t.string 'name'
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
create_table "reviews", force: :cascade do |t|
t.string "business_id"
t.string "user_email"
t.text "comment"
t.integer "rating"
t.integer "price"
t.integer "safety"
t.integer "service"
t.boolean "cash_only"
t.boolean "english"
t.boolean "tips"
t.boolean "wifi"
t.boolean "wheelchair"
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table 'tips', force: :cascade do |t|
t.text 'tip'
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
t.integer 'program_id'
t.integer 'user_id'
t.index ['program_id'], name: 'index_tips_on_program_id'
t.index ['user_id'], name: 'index_tips_on_user_id'
create_table "tips", force: :cascade do |t|
t.text "tip"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "program_id"
t.integer "user_id"
t.index ["program_id"], name: "index_tips_on_program_id"
t.index ["user_id"], name: "index_tips_on_user_id"
end

create_table 'users', force: :cascade do |t|
t.string 'uid'
t.string 'name'
t.string 'email'
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
t.integer 'program_id'
t.boolean 'admin', default: false
t.boolean 'banned', default: false
t.index ['program_id'], name: 'index_users_on_program_id'
create_table "users", force: :cascade do |t|
t.string "uid"
t.string "name"
t.string "email"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "program_id"
t.boolean "admin", default: false
t.boolean "banned", default: false
t.index ["program_id"], name: "index_users_on_program_id"
end

create_table 'yelp_locations', force: :cascade do |t|
t.string 'name'
t.string 'address'
t.string 'alias'
t.string 'yelp_id'
t.string 'url'
t.string 'image_url'
t.string 'rating'
t.string 'yelp_tags'
t.integer 'experience_id'
t.index ['experience_id'], name: 'index_yelp_locations_on_experience_id'
create_table "yelp_locations", force: :cascade do |t|
t.string "name"
t.string "address"
t.string "alias"
t.string "yelp_id"
t.string "url"
t.string "image_url"
t.string "rating"
t.string "yelp_tags"
t.integer "experience_id"
t.index ["experience_id"], name: "index_yelp_locations_on_experience_id"
end

add_foreign_key 'active_storage_attachments', 'active_storage_blobs', column: 'blob_id'
add_foreign_key 'experience_comments', 'experiences'
add_foreign_key 'experience_comments', 'users'
add_foreign_key 'experiences', 'programs'
add_foreign_key 'experiences', 'users'
add_foreign_key 'helpful_votes', 'tips'
add_foreign_key 'helpful_votes', 'users'
add_foreign_key 'participants', 'programs'
add_foreign_key 'tips', 'programs'
add_foreign_key 'tips', 'users'
add_foreign_key 'users', 'programs'
add_foreign_key 'yelp_locations', 'experiences'
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "experience_comments", "experiences"
add_foreign_key "experience_comments", "users"
add_foreign_key "experiences", "programs"
add_foreign_key "experiences", "users"
add_foreign_key "helpful_votes", "tips"
add_foreign_key "helpful_votes", "users"
add_foreign_key "participants", "programs"
add_foreign_key "tips", "programs"
add_foreign_key "tips", "users"
add_foreign_key "users", "programs"
add_foreign_key "yelp_locations", "experiences"
end
Loading

0 comments on commit dc6109f

Please sign in to comment.