-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: page for removing team members from team
- Loading branch information
Showing
17 changed files
with
249 additions
and
11 deletions.
There are no files selected for viewing
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,40 @@ | ||
class Accounts::MembersController < ApplicationController | ||
before_action :ensure_team_account | ||
before_action :setup_account | ||
|
||
def index | ||
end | ||
|
||
def edit | ||
@account_user = @account.account_users.find_puid!(params[:id]) | ||
end | ||
|
||
def destroy | ||
@account_user = @account.account_users.find_puid!(params[:id]) | ||
if @account_user.destroy | ||
flash[:notice] = I18n.t("account_users.destroy.success") | ||
redirect_to members_path | ||
else | ||
flash[:alert] = I18n.t("account_users.destroy.failure") | ||
redirect_to members_path, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def ensure_team_account | ||
redirect_to edit_account_path if current_account.personal? | ||
end | ||
|
||
def setup_account | ||
@account = current_account | ||
@members = current_account.account_users | ||
end | ||
|
||
def options_for_roles | ||
AccountUser::ROLES.map do |role| | ||
[I18n.t("account_users.roles.#{role}"), role] | ||
end | ||
end | ||
helper_method :options_for_roles | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
class AccountUser < ApplicationRecord | ||
ROLES = %w[owner member] | ||
class AccountUser < ApplicationRecord # This will generate a public_uid for the model when it is created. | ||
# Use this public_uidas a unique public identifier for the model. | ||
# To find a model by its public_uid, use the following method: | ||
# Account.find_puid('xxxxxxxx') | ||
# Learn more: https://github.com/equivalent/public_uid | ||
include PublicUid::ModelConcern | ||
|
||
# This is a list of roles that a user can have in an account. | ||
# You can add more roles if you want, but you SHOULD NOT REMOVE | ||
# the owner role, as it is required for the account to function. | ||
ROLES = %w[owner admin readonly] | ||
|
||
belongs_to :user | ||
belongs_to :account | ||
|
||
# The name of the account user. | ||
delegate :name, to: :user | ||
|
||
validates :role, presence: true, inclusion: {in: self::ROLES} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= simple_form_for(account_user, url: "#") do |f| %> | ||
<div class="mt-4 flex justify-between items-center"> | ||
<%= f.button :submit, t(".submit") %> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<% title t(".title") %> | ||
<%= render(PageLayouts::Settings::Component.new( | ||
title: t(".title"), | ||
description: t(".description") | ||
)) do %> | ||
<div class="box"> | ||
<header class="border-b pb-4 mb-4"> | ||
<h3 class="font-bold text-primary uppercase"><%= t(".delete.box_title") %></h3> | ||
</header> | ||
<div class="prose dark:prose-invert"> | ||
<p><%= t(".delete.description", name: @account_user.name) %></p> | ||
<%= button_to t(".delete.button"), member_path(@account_user), class: "button danger", method: :delete, data: { confirm: t(".confirmation_message", name: @account_user.name), turbo_confirm: t(".confirmation_message", name: @account_user.name) } %> | ||
</div> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<% title t(".title") %> | ||
<%= render(PageLayouts::Settings::Component.new( | ||
title: t(".title"), | ||
description: t(".description") | ||
)) do %> | ||
<div class="box"> | ||
<header class="border-b pb-4 mb-4"> | ||
<h3 class="font-bold text-primary uppercase"><%= t(".box_title", team_name: @account.name) %></h3> | ||
</header> | ||
|
||
<div class="prose"> | ||
<table class="kiqr-table"> | ||
<thead> | ||
<tr> | ||
<th><%= t(".table.name") %></th> | ||
<th><%= t(".table.email") %></th> | ||
<th><%= t(".table.role") %></th> | ||
<th class="text-right"><%= t(".table.actions") %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @members.each do |member| %> | ||
<tr> | ||
<td><%= member.user.name %></td> | ||
<td><%= member.user.email %></td> | ||
<td><%= member.role %></td> | ||
<td class="text-right"> | ||
<%= link_to t(".table.edit"), edit_member_path(id: member), class: "button xs" %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
<div class="mt-6 flex justify-between items-center"> | ||
<%= link_to "Invite a new member", "#", class: "button" %> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
68f1lAzRuHJdsoUn+xOP1qA4uyyweYvYpC1fQbf8VwkrefELEgzEn8odaMSSRmnaFwd3vnJb5OQmxCcZCFEWnDaIp8wO+8K5SS/veymXozbnwf2i8PuWgHhZF/+M5wHa445hCjfyE8Br0OA1Z8uc+GHE7GJesJUAtIeHkxhRKbikRVepQAVdfDQNDI903ufKtK/Ws5CEZwe1SDb8Vss/whidT1DG7Br2i7F99VN9q4fsWIWih/qs6w3yt8fJNJQXFxsC/l+SWK/3uVAGVrbxah1I2vIA14SsC7aU3ruEw0WgYLKH1fIkDiePptlQUgTLaug23mZwSmybTwTcMjZoExBfYyf1Y52iqhg1ASLx1j0M/5R2Y9ho3X6q9RWLK/g48ZejznyT7/iqrfDWMryYwTrkEMccYLNn3jAn6CZJcSGMQPQARp216DlnCSyD9p0Xdqx37xC2pl4GP5BSHxXMb9B0kBICXqnKBND1VtQVwnuGxEj0aYK8d8GNl4ZqQ2dC4IBeTQgcyQ0a4r4A1t+8NPTmn1tYN8PY1sEIN92P45pNnknpi9SZSPqdtT/QLLxnIJJrL7XTlybV/grIYaDC9F15uCNMEGbDcxoXwvuZ3mo29tIeklVgT6HbLI1qAsG2MuHTClknitxPJDFMcxtlauTO75I/luk2g7si5lauXC8uYox8q5jgPj9z27RYSpXQ5+VJe0L13lUhoWfoW/mS0wVjVRe4sdWkLjJDZ0UH86UDd7Q1VbV0hr+ClEKWJQdxCid4GOHOs9D7bwICpPsgRQTMahDqWlaN6vtmBL1DfsTkj+kkmJPEpWG8/Eio94YgqHujOynU90e+fv6X8FDQ87vtjgrLPTELB4qUvB0WwaP7u/8sJX+Qa3UqcF3Jp35atobXTT/lKYCrS1EshFR9eGouvV4ZUr2YiP0ULAReZFAQbfVKm0o=--BLJ94eO0gaHIPwVS--+WUWE/M4QuFW6XeFxwrQAg== |
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,6 @@ | ||
class AddPublicUidToAccountUsers < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :account_users, :public_uid, :string | ||
add_index :account_users, :public_uid, unique: true | ||
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "test_helper" | ||
|
||
class Accounts::MembersControllerTest < ActionDispatch::IntegrationTest | ||
test "can't show members as personal account" do | ||
user = create(:user) | ||
sign_in user | ||
get members_path | ||
|
||
assert_redirected_to edit_account_path(account_id: nil) | ||
end | ||
|
||
test "can show members as team account" do | ||
user = create(:user) | ||
account = create(:account, name: "Team account") | ||
account.account_users << AccountUser.create(user:, role: "owner") | ||
|
||
sign_in user | ||
get members_path(account_id: account) | ||
|
||
assert_response :success | ||
end | ||
|
||
test "can remove a member from team" do | ||
user = create(:user) | ||
some_user = create(:user) | ||
|
||
account = create(:account, name: "Team account") | ||
account.account_users << AccountUser.create(user: user, role: "owner") | ||
account.account_users << AccountUser.create(user: some_user, role: "admin") | ||
|
||
assert_includes account.reload.users, some_user | ||
|
||
sign_in user | ||
delete member_path(account_id: account, id: some_user.account_users.first) | ||
|
||
assert_redirected_to members_path(account_id: account) | ||
assert_not_includes account.reload.users, some_user | ||
end | ||
|
||
test "can not remove the team owner" do | ||
skip "This test is not implemented yet" | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
require "test_helper" | ||
|
||
class AccountUserTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
test "should have the owner role" do | ||
assert_includes AccountUser::ROLES, "owner" | ||
end | ||
end |