Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joining groups #14

Merged
merged 77 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
bcd88dc
Adds Invitations schema, adds timestamps to Groups and Users.
kmeyerhofer Oct 12, 2018
901eda0
Changes profile link on page.
kmeyerhofer Oct 12, 2018
910e36f
Adds invitations to user profiles. Group owners can invite users to a…
kmeyerhofer Oct 12, 2018
6255a32
Adds invitation controller, models and form on user page.
kmeyerhofer Oct 12, 2018
7430c24
Adds functionality to add an existing user via a selection menu to gr…
kmeyerhofer Oct 13, 2018
2287d8c
Changes link text to profile.
kmeyerhofer Oct 13, 2018
66a3c57
Due date visible on group show page. Group destroy functionality remo…
kmeyerhofer Oct 22, 2018
6ff532b
Adds 'Select Group' as default group selection.
kmeyerhofer Oct 22, 2018
95864d9
Validates for gift date, raises a flash message when incorrectly ente…
kmeyerhofer Oct 22, 2018
3872404
Adds group invitation list to a profile which can be added to a group.
kmeyerhofer Oct 23, 2018
492b120
Removes unneeded comments.
kmeyerhofer Oct 23, 2018
c3a1304
Adds links to invitation sender's profile and to the group page.
kmeyerhofer Oct 23, 2018
d008599
Adds spacing for readability.
kmeyerhofer Oct 23, 2018
fe04697
Moves invitations# accept, decline and invite to paths which make mor…
kmeyerhofer Oct 24, 2018
193e14a
Renames edit and destroy actions. Creates invite action accessed from…
kmeyerhofer Oct 24, 2018
a01791a
Adds first/last name to invite title.
kmeyerhofer Oct 24, 2018
2644eee
Modifies link_to paths for invitation accept and decline.
kmeyerhofer Oct 24, 2018
7407a8f
Adds invitation form for a group owner to send an invite.
kmeyerhofer Oct 24, 2018
2063a02
Renames label to 'Message'.
kmeyerhofer Oct 24, 2018
585923e
Adds invitation form for a group owner to send an invite.
kmeyerhofer Oct 24, 2018
5c387dd
Adds @group_owner to the view to display whether or not a user can se…
kmeyerhofer Oct 24, 2018
cc4151d
Adds seeds to database.
kmeyerhofer Oct 24, 2018
4c2350d
Adds login check for groups#show.
kmeyerhofer Oct 24, 2018
2f0278b
Adds database_cleaner gem.
kmeyerhofer Oct 24, 2018
6738e1c
Adds Model tests.
kmeyerhofer Oct 25, 2018
afafd60
Removes comment.
kmeyerhofer Oct 25, 2018
e03e270
Adds database cleaner and adjusts config files.
kmeyerhofer Oct 25, 2018
2be5ab6
These tests now pass.
kmeyerhofer Oct 25, 2018
96b9af1
WIP
kmeyerhofer Oct 25, 2018
6dc0446
Adds tests, utilizing let.
kmeyerhofer Oct 25, 2018
daaeb2b
Adds support method to Features module.
kmeyerhofer Oct 25, 2018
3571312
Uses #find_by instead of #where.
kmeyerhofer Oct 25, 2018
7665c5f
Adds logging in tests, checking for email case.
kmeyerhofer Oct 25, 2018
066e002
Adds email downcasing functionality.
kmeyerhofer Oct 25, 2018
5e9c067
Seeds emails to be downcase.
kmeyerhofer Oct 25, 2018
feb84c6
Adds group visibility to one user test.
kmeyerhofer Oct 25, 2018
a61540d
Adds helper methods and makes use of them.
kmeyerhofer Oct 25, 2018
d4e056e
Removes 'only' array from before actions, modifies flash warning, fix…
kmeyerhofer Oct 26, 2018
843bff0
Adds feature tests for group creation, editing, and deletion.
kmeyerhofer Oct 26, 2018
62f9e64
Replaces flash warning message.
kmeyerhofer Oct 26, 2018
7c4c99a
Adds feature tests for item creation, editing and deletion.
kmeyerhofer Oct 26, 2018
779a71b
Renamed and split tests in other files.
kmeyerhofer Oct 26, 2018
37b2e87
Adds blank credential feature test.
kmeyerhofer Oct 26, 2018
1c4e662
Replaces string quotes, moved comment to private method.
kmeyerhofer Oct 26, 2018
b907a3d
Gemfile update after testing Ruby 2.4.0
kmeyerhofer Oct 26, 2018
1355606
Adds StrongPassword Gem
kmeyerhofer Oct 26, 2018
1a41daa
Adds more secure password to tests.
kmeyerhofer Oct 26, 2018
d452a20
Adds more secure password to seeds.
kmeyerhofer Oct 26, 2018
8051f72
Refactors update action for password change functionality.
kmeyerhofer Oct 26, 2018
3d8234f
Separates edit forms.
kmeyerhofer Oct 26, 2018
35a052e
Adds strong password validators.
kmeyerhofer Oct 26, 2018
afeccdb
Adds more secure password.
kmeyerhofer Oct 26, 2018
c91fe92
Adds password strength model tests.
kmeyerhofer Oct 26, 2018
07c3594
Refactors updating action logic.
kmeyerhofer Oct 27, 2018
7a0a159
Adds feature tests for editing a user's profile.
kmeyerhofer Oct 27, 2018
baccefc
Adds feature tests for inviting and accepting group invitations.
kmeyerhofer Oct 27, 2018
2312be8
Inserts a form email_field_tag for the email address of the receiver.
kmeyerhofer Oct 27, 2018
e3f407e
Adds edge case tests.
kmeyerhofer Oct 27, 2018
694059c
Renamed file and added sign_out helper method.
kmeyerhofer Oct 27, 2018
7538f09
Renamed file.
kmeyerhofer Oct 27, 2018
78a4667
Merge branch 'wish-list' into joining-groups
kmeyerhofer Oct 27, 2018
b34d0df
Merge branch 'master' into joining-groups
kmeyerhofer Oct 28, 2018
c867190
Merge from master.
kmeyerhofer Nov 3, 2018
255bda4
Pulling branch joining-groups
kmeyerhofer Nov 3, 2018
1066116
Removes ability to accept or decline invitations for another user.
kmeyerhofer Nov 6, 2018
4b46559
Modifies model associations.
kmeyerhofer Nov 6, 2018
0b294d9
Removes byebug.
kmeyerhofer Nov 6, 2018
ec77978
Passing tests.
kmeyerhofer Nov 6, 2018
41b568f
Adds shoulda-matchers gem for testing.
kmeyerhofer Nov 6, 2018
c50de4a
Adds testing for unauthorized access.
kmeyerhofer Nov 6, 2018
96342dd
Moves query to user model.
kmeyerhofer Nov 7, 2018
e02fa50
Refactors destroy action. Removes index action.
kmeyerhofer Nov 7, 2018
ce60080
Adds date selector to group creation and editing.
kmeyerhofer Nov 7, 2018
65b887b
Changes user lookup to utilize AR relations.
kmeyerhofer Nov 7, 2018
f0202c0
Removes validation duplication.
kmeyerhofer Nov 7, 2018
e8a9de5
Refactors conditional check.
kmeyerhofer Nov 7, 2018
55087d4
Removes groups#index route.
kmeyerhofer Nov 12, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ gem 'jbuilder', '~> 2.5'
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
gem 'strong_password', '~> 0.0.6'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
Expand All @@ -44,6 +45,12 @@ group :development, :test do
gem 'launchy'
end

group :test do
gem 'database_cleaner'
gem 'shoulda-matchers', '4.0.0.rc1'
gem 'rails-controller-testing'
end

group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
Expand Down
32 changes: 23 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ GEM
msgpack (~> 1.0)
builder (3.2.3)
byebug (10.0.2)
capybara (3.8.2)
capybara (3.10.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
xpath (~> 3.1)
regexp_parser (~> 1.2)
xpath (~> 3.2)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
Expand All @@ -67,6 +68,7 @@ GEM
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
crass (1.0.4)
database_cleaner (1.7.0)
diff-lcs (1.3)
erubi (1.7.1)
execjs (2.7.0)
Expand All @@ -75,7 +77,7 @@ GEM
ffi (1.9.25)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (1.1.0)
i18n (1.1.1)
concurrent-ruby (~> 1.0)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
Expand All @@ -89,7 +91,7 @@ GEM
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
Expand All @@ -101,7 +103,7 @@ GEM
msgpack (1.2.4)
multi_json (1.13.1)
nio4r (2.3.1)
nokogiri (1.8.4)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
pg (1.1.3)
public_suffix (3.0.3)
Expand All @@ -122,6 +124,10 @@ GEM
bundler (>= 1.3.0)
railties (= 5.2.1)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
actionview (~> 5.x, >= 5.0.1)
activesupport (~> 5.x)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
Expand All @@ -137,15 +143,16 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
regexp_parser (1.2.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.1)
rspec-expectations (3.8.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.0)
rspec-rails (3.8.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
Expand All @@ -166,13 +173,16 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
shoulda-matchers (4.0.0.rc1)
activesupport (>= 4.2.0)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
strong_password (0.0.6)
thor (0.20.0)
thread_safe (0.3.6)
tilt (2.0.8)
Expand All @@ -188,7 +198,7 @@ GEM
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
xpath (3.1.0)
xpath (3.2.0)
nokogiri (~> 1.8)

PLATFORMS
Expand All @@ -200,15 +210,19 @@ DEPENDENCIES
byebug
capybara
coffee-rails (~> 4.2)
database_cleaner
faker
jbuilder (~> 2.5)
launchy
listen (>= 3.0.5, < 3.2)
pg (>= 0.18, < 2.0)
puma (~> 3.11)
rails (~> 5.2.0)
rails-controller-testing
rspec-rails (~> 3.7)
sass-rails (~> 5.0)
shoulda-matchers (= 4.0.0.rc1)
strong_password (~> 0.0.6)
tzinfo-data
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
Expand All @@ -217,4 +231,4 @@ RUBY VERSION
ruby 2.3.1p112

BUNDLED WITH
1.16.3
1.16.4
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def root_path_if_not_logged_in

def unauthorized_user(user)
if !authorized_user(user)
flash[:warning] = 'This action is unauthorized.'
flash[:warning] = 'Action is unauthorized.'
redirect_to root_path
end
end
Expand Down
31 changes: 23 additions & 8 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ class GroupsController < ApplicationController
before_action :set_group, only: [:show, :edit, :update, :destroy]
before_action -> { unauthorized_user(@group.owner) }, only: [:update, :edit, :destroy]

def index
@groups = Group.all
end

def new
@group = Group.new
end

def create
@group = Group.new(group_params)
@group.user_ids = current_user.id # Add user as a user
@group.user_ids << current_user.id # Add user as a user
@group.owner_id = current_user.id # Add user as owner
if authorized_user(@group.owner) && @group.save
current_user.groups << @group
create_list
flash[:notice] = 'Group created successfully.'
redirect_to group_path(@group)
Expand All @@ -26,6 +23,9 @@ def create

def show
@user_wish_list = @group.user_wish_list(current_user)
if authorized_user(@group.owner)
@invitation = Invitation.new
end
end

def edit
Expand All @@ -36,13 +36,28 @@ def update
flash[:notice] = "Group '#{@group.name}' updated!"
redirect_to group_path(@group)
else
flash[:warning] = 'An error occurred, please try again.'
flash[:warning] = 'Please enter valid information.'
redirect_to edit_group_path(@group)
end
end

def destroy
# Destroy not working. Delete lists associated with group first.
lists = List.where(group_id: @group.id)
if !lists.empty?
lists.each do |list|
items = Item.where(list_id: list.id)
items.each { |item| item.destroy }
list.destroy
end
end

invitations = Invitation.where(group_id: @group.id)
if !invitations.empty?
invitations.each do |invitation|
invitation.destroy
end
end

@group.destroy
flash[:notice] = "Group Deleted!"
redirect_to dashboard_path
Expand All @@ -62,7 +77,7 @@ def set_group
end

def group_params
params.require(:group).permit(:name, :description, :owner_id)
params.require(:group).permit(:name, :description, :owner_id, :gift_due_date)
end

def belonging_user(user_list)
Expand Down
96 changes: 96 additions & 0 deletions app/controllers/invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
class InvitationsController < ApplicationController
def create
@invitation = Invitation.new(invitation_params)
@invitation.sender_id = current_user.id
@invitation.receiver_id = params[:user_id]
@invitation.save
flash[:notice] = 'Invitation sent.'
redirect_to user_path(@invitation.receiver_id)
end

def accept
invitation = Invitation.find(params[:id])
user = invitation.receiver
if authorized_user(user)
@group = Group.find(invitation.group_id)
invitation.accepted = true
invitation.save
if !user.groups.include?(@group)
user.groups << @group
create_list
flash[:notice] = 'Invitation accepted.'
redirect_to dashboard_path
else
flash[:warning] = 'You already belongs to this group.'
redirect_to dashboard_path
end
else
flash[:warning] = 'Action is unauthorized.'
redirect_to root_path
end
end

def decline
invitation = Invitation.find(params[:id])
user = invitation.receiver
if authorized_user(user)
invitation.accepted = false
invitation.save
flash[:notice] = 'Invitation declined.'
redirect_to dashboard_path
else
flash[:warning] = 'Action is unauthorized.'
redirect_to root_path
end
end

def invite
# sent from the groups page, by the group owner
receiver = User.find_by(email: downcase_email_param)
group = Group.find(params[:group_id])
if receiver
no_pending_user_invitations = user_invitations('group_id = ? AND receiver_id = ? AND accepted IS NULL', group.id, receiver.id)
no_declined_user_invitations = user_invitations('group_id = ? AND receiver_id = ? AND accepted = false', group.id, receiver.id)
not_inviting_self = (group.owner_id != receiver.id)
end

if no_pending_user_invitations && no_declined_user_invitations && not_inviting_self
invitation = Invitation.new
invitation.group_id = group.id
invitation.receiver_id = receiver.id
invitation.sender_id = group.owner_id
invitation.comment = params[:invitation][:comment]
if invitation.save
flash[:notice] = 'Invitation sent.'
else
flash[:warning] = 'There was an error sending the invitation, please try again.'
end
else
flash[:notice] = "Invitation sent to user's email."
# Default failure behavior to not give away user's email
# Create a new user with this email address, eventually sending them an invitation email.
end
redirect_to group_path(group.id)
end

private

def user_invitations(accepted_string, group, user)
Invitation.joins(:group).where([accepted_string, group, user,]).empty?
end

def invitation_params
params.require(:invitation).permit(:comment, :group_id)
end

def create_list
list = List.new
list.user_id = current_user.id
list.group_id = @group.id
list.save
end

def downcase_email_param
params[:email].downcase
end
end
2 changes: 1 addition & 1 deletion app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create
if authorized_user(@user) && @item.save
redirect_to group_list_path(@group, @list)
else
flash[:warning] = 'Invalid entry.'
flash[:warning] = 'Please enter valid information.'
render 'new'
end
end
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def new
end

def create
user = User.find_by(email: params[:email])
user = User.find_by(email: downcase_email)
if user && user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to dashboard_path
Expand All @@ -20,4 +20,10 @@ def destroy
flash[:notice] = "Log out successful."
redirect_to root_path
end

private

def downcase_email
params[:email].downcase
end
end
Loading