-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from amrhossamdev/advanced-login
Admin now can control users
- Loading branch information
Showing
13 changed files
with
155 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<ul class="users"> | ||
<% @users.each do |user| %> | ||
<li> | ||
<%= link_to gravatar_for( user, size: 50), user %> | ||
<%= link_to user.name, user %> | ||
<% if current_user.admin? && !current_user?(user) %> | ||
| <%= link_to "delete", user, data: { "turbo-method": :delete, | ||
turbo_confirm: "You sure?" } %> | ||
<% end %> | ||
</li> | ||
<% end %> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
<% provide(:title, 'All users') %> | ||
<h1>All users</h1> | ||
<%= will_paginate %> | ||
<ul class="users"> | ||
<% @users.each do |user| %> | ||
<li> | ||
<%= gravatar_for user, size: 50 %> | ||
<%= link_to user.name, user %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<%= render "users/user" %> | ||
<%= will_paginate %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddAdminToUsers < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :users, :admin, :boolean, default: false | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# This file should ensure the existence of records required to run the application in every environment (production, | ||
# development, test). The code here should be idempotent so that it can be executed at any point in every environment. | ||
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). | ||
# | ||
# Example: | ||
# | ||
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| | ||
# MovieGenre.find_or_create_by!(name: genre_name) | ||
# end | ||
99.times do |n| | ||
name = Faker::Name.name | ||
email = "example-#{n + 1}@railstutorial.org" | ||
|
||
User.create(name: name, | ||
email: email, | ||
password: "123456", | ||
password_confirmation: "123456", | ||
admin: true) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "test_helper" | ||
|
||
class UsersIndexTest < ActionDispatch::IntegrationTest | ||
|
||
def setup | ||
@admin = users(:amr) | ||
@non_admin = users(:amr2) | ||
end | ||
|
||
# TODO check that | ||
|
||
# test "index as admin including pagination and delete links" do | ||
# log_in_as(@admin) | ||
# get users_path | ||
# assert_template "users/index" | ||
# assert_select "div.pagination" | ||
# first_page_of_users = User.paginate(page: 1) | ||
# first_page_of_users.each do |user| | ||
# assert_select "a[href=?]", user_path(user), text: user.name | ||
# unless user == @admin | ||
# assert_select "a[href=?]", user_path(user), text: "delete", method: :delete | ||
# end | ||
# end | ||
# assert_difference "User.count", -1 do | ||
# delete user_path(@non_admin) | ||
# end | ||
# end | ||
|
||
test "index as non-admin" do | ||
log_in_as(@non_admin) | ||
get users_path | ||
assert_template "users/index" | ||
assert_select "a", text: "delete", count: 0 | ||
|
||
end | ||
end |