-
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.
Merge pull request #30 from jameswilliamiii/feature/organization-posts
Add organization relationship to posts
- Loading branch information
Showing
18 changed files
with
107 additions
and
33 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
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,21 @@ | ||
module Organizationable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
before_action :assign_organization | ||
end | ||
|
||
def current_organization | ||
Current.organization || Current.user.base_organization | ||
end | ||
|
||
def assign_organization | ||
return unless Current.user | ||
|
||
Current.organization = find_organization_by_cookie | ||
end | ||
|
||
def find_organization_by_cookie | ||
Organization.find_by(id: cookies.signed[:organization_id]) || Current.user.base_organization | ||
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
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,4 +1,4 @@ | ||
class Current < ActiveSupport::CurrentAttributes | ||
attribute :session | ||
attribute :session, :organization | ||
delegate :user, to: :session, allow_nil: 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
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,28 +1,17 @@ | ||
<div class="mx-auto md:w-2/3 w-full flex"> | ||
<div class="mx-auto w-full"> | ||
<% if notice.present? %> | ||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p> | ||
<% end %> | ||
|
||
<%= render @post %> | ||
|
||
<%= render RBUI::Link.new(href: edit_post_path(@post), variant: :outline, class: "me-3") { "Edit" } %> | ||
<%#= render RBUI::Link.new( | ||
href: post_path(@post), | ||
variant: :destructive, | ||
data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete this post?" }, | ||
class: "ms-3") { | ||
"Delete" | ||
} %> | ||
|
||
<%= render Components::ConfirmDialog.new( | ||
variant: :destructive, | ||
href: post_path(@post), | ||
title: "Are you sure?", | ||
description: "This action cannot be undone. This will permanently delete your post.", | ||
action_text: "Delete post", | ||
cancel_text: "Cancel", | ||
data: { turbo_method: :delete }, | ||
) { "Delete" } %> | ||
<%= render Components::ConfirmDialog.new( | ||
variant: :destructive, | ||
href: post_path(@post), | ||
title: "Are you sure?", | ||
description: "This action cannot be undone. This will permanently delete your post.", | ||
action_text: "Delete post", | ||
cancel_text: "Cancel", | ||
data: { turbo_method: :delete }, | ||
) { "Delete" } %> | ||
</div> | ||
</div> |
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 AddOrganizationToPost < ActiveRecord::Migration[8.0] | ||
def change | ||
add_reference :posts, :organization, null: false, foreign_key: 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
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 |
---|---|---|
|
@@ -7,5 +7,9 @@ | |
trait :admin do | ||
role { :admin } | ||
end | ||
|
||
trait :owner do | ||
role { :owner } | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
FactoryBot.define do | ||
factory :post do | ||
user | ||
organization | ||
title { "MyString" } | ||
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