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

User groups #12

Merged
merged 16 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@

# Ignore master key for decrypting credentials and more.
/config/master.key

# Ignore rbenv version
.ruby-version
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0
2.3.1
122 changes: 61 additions & 61 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (5.2.0)
actionpack (= 5.2.0)
actioncable (5.2.1)
actionpack (= 5.2.1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.0)
actionpack (= 5.2.0)
actionview (= 5.2.0)
activejob (= 5.2.0)
actionmailer (5.2.1)
actionpack (= 5.2.1)
actionview (= 5.2.1)
activejob (= 5.2.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.0)
actionview (= 5.2.0)
activesupport (= 5.2.0)
actionpack (5.2.1)
actionview (= 5.2.1)
activesupport (= 5.2.1)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.0)
activesupport (= 5.2.0)
actionview (5.2.1)
activesupport (= 5.2.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.0)
activesupport (= 5.2.0)
activejob (5.2.1)
activesupport (= 5.2.1)
globalid (>= 0.3.6)
activemodel (5.2.0)
activesupport (= 5.2.0)
activerecord (5.2.0)
activemodel (= 5.2.0)
activesupport (= 5.2.0)
activemodel (5.2.1)
activesupport (= 5.2.1)
activerecord (5.2.1)
activemodel (= 5.2.1)
activesupport (= 5.2.1)
arel (>= 9.0)
activestorage (5.2.0)
actionpack (= 5.2.0)
activerecord (= 5.2.0)
activestorage (5.2.1)
actionpack (= 5.2.1)
activerecord (= 5.2.1)
marcel (~> 0.3.1)
activesupport (5.2.0)
activesupport (5.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
Expand All @@ -47,11 +47,11 @@ GEM
arel (9.0.0)
bcrypt (3.1.12)
bindex (0.5.0)
bootsnap (1.3.1)
bootsnap (1.3.2)
msgpack (~> 1.0)
builder (3.2.3)
byebug (10.0.2)
capybara (3.5.1)
capybara (3.8.2)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand All @@ -75,7 +75,7 @@ GEM
ffi (1.9.25)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (1.0.1)
i18n (1.1.0)
concurrent-ruby (~> 1.0)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
Expand All @@ -91,71 +91,71 @@ GEM
nokogiri (>= 1.5.9)
mail (2.7.0)
mini_mime (>= 0.1.1)
marcel (0.3.2)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.0)
mimemagic (0.3.2)
mini_mime (1.0.0)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
minitest (5.11.3)
msgpack (1.2.4)
multi_json (1.13.1)
nio4r (2.3.1)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
pg (1.0.0)
public_suffix (3.0.2)
pg (1.1.3)
public_suffix (3.0.3)
puma (3.12.0)
rack (2.0.5)
rack-test (1.0.0)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.0)
actioncable (= 5.2.0)
actionmailer (= 5.2.0)
actionpack (= 5.2.0)
actionview (= 5.2.0)
activejob (= 5.2.0)
activemodel (= 5.2.0)
activerecord (= 5.2.0)
activestorage (= 5.2.0)
activesupport (= 5.2.0)
rails (5.2.1)
actioncable (= 5.2.1)
actionmailer (= 5.2.1)
actionpack (= 5.2.1)
actionview (= 5.2.1)
activejob (= 5.2.1)
activemodel (= 5.2.1)
activerecord (= 5.2.1)
activestorage (= 5.2.1)
activesupport (= 5.2.1)
bundler (>= 1.3.0)
railties (= 5.2.0)
railties (= 5.2.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.0)
actionpack (= 5.2.0)
activesupport (= 5.2.0)
railties (5.2.1)
actionpack (= 5.2.1)
activesupport (= 5.2.1)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
thor (>= 0.19.0, < 2.0)
rake (12.3.1)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-rails (3.7.2)
rspec-support (~> 3.8.0)
rspec-rails (3.8.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
ruby_dep (1.5.0)
sass (3.5.7)
sass (3.6.0)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand All @@ -178,9 +178,9 @@ GEM
tilt (2.0.8)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.1.15)
uglifier (4.1.19)
execjs (>= 0.3.0, < 3)
web-console (3.6.2)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
bindex (>= 0.4.0)
Expand Down Expand Up @@ -217,4 +217,4 @@ RUBY VERSION
ruby 2.3.1p112

BUNDLED WITH
1.14.6
1.16.3
6 changes: 5 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
class ApplicationController < ActionController::Base
helper_method :current_user
helper_method :current_user, :authorized_user

def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end

def authorized_user(other_user)
current_user.id == other_user.id
end
end
8 changes: 8 additions & 0 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class DashboardController < ApplicationController
def show
if !current_user
redirect_to root_path
flash[:warning] = 'You must be logged in first.'
end
end
end
53 changes: 53 additions & 0 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class GroupsController < ApplicationController
before_action :set_group, only: [:show, :edit, :update, :destroy]

def index
@groups = Group.all
end
kmeyerhofer marked this conversation as resolved.
Show resolved Hide resolved

def new
@group = Group.new
end

def create
@group = Group.new(group_params)
@group.user_ids= current_user.id
if @group.save
redirect_to dashboard_path
else
render 'new'
end
end

def show
end

def edit
end

def update
if @group.update(group_params)
flash[:notice] = "Group '#{@group.name}' updated!"
redirect_to group_path(@group)
else
flash[:warning] = 'An error occurred, please try again.'
render 'edit'
end
end

def destroy
@group.destroy
flash[:notice] = 'Group Deleted!'
redirect_to dashboard_path
end

kmeyerhofer marked this conversation as resolved.
Show resolved Hide resolved
private

def set_group
@group = Group.find(params[:id])
end

def group_params
params.require(:group).permit(:name, :description)
end
end
5 changes: 2 additions & 3 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ def create
user = User.find_by(email: params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
# flash[:notice] = "Login successful."
redirect_to root_url
redirect_to root_path
else
flash[:warning] = 'Email or password is invalid'
render 'new'
Expand All @@ -17,6 +16,6 @@ def create
def destroy
session[:user_id] = nil
flash[:notice] = "Log out successful."
redirect_to root_url
redirect_to root_path
end
end
47 changes: 43 additions & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,63 @@
class UsersController < ApplicationController
before_action :set_user, only: [:edit, :update]
def new
@user = User.new
if current_user
redirect_to dashboard_path
else
render 'new'
end
end

def create
@user = User.new(user_params)
if @user.save
redirect_to root_url
flash[:notice] = "Account successfully created."
redirect_to login_path
kmeyerhofer marked this conversation as resolved.
Show resolved Hide resolved
else
render 'new'
end
end

def show
byebug
@user = User.find(params[:id]);
@user = params[:id] ? User.find(params[:id]) : current_user
if !current_user
redirect_to root_url
flash[:warning] = 'You must be logged in first.'
end
end

def edit
end

def update
segment_string = params[:commit].split(' ')[1]
if @user.update(validate_params(segment_string))
flash[:notice] = "#{segment_string} successfully updated."
redirect_to profile_path
else
flash[:warning] = "An error occurred, please try again."
render 'edit'
end
end

private

def set_user
@user = current_user
end

def validate_params(string)
case string
when 'Name'
return params.require(:user).permit(:first_name, :last_name)
when 'Email'
return params.require(:user).permit(:email)
when 'Password'
return params.require(:user).permit(:password, :password_confirmation)
end
end

def user_params
params.require(:user).permit(:email, :first_name, :last_name, :password, :password_confirmation)
end
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class WelcomeController < ApplicationController
def index
#@users = User.all
if current_user
redirect_to dashboard_path
end
end
end
4 changes: 4 additions & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Group < ApplicationRecord
has_many :user_groups
has_many :users, through: :user_groups
end
Loading