Add organizations to user profile (#5583) [deploy]
* Add organizations to user profile * Add user organization info updated at column and cache key * Remove default value for users organization_info_updated_at column * Update organization_memberships factory * Remove schema organization_info_updated_at default value Co-authored-by: rhymes <rhymesete@gmail.com>
This commit is contained in:
parent
c91080c371
commit
a25446b1d4
8 changed files with 49 additions and 3 deletions
|
|
@ -5,4 +5,11 @@ class OrganizationMembership < ApplicationRecord
|
||||||
validates :user_id, :organization_id, :type_of_user, presence: true
|
validates :user_id, :organization_id, :type_of_user, presence: true
|
||||||
validates :user_id, uniqueness: { scope: :organization_id }
|
validates :user_id, uniqueness: { scope: :organization_id }
|
||||||
validates :type_of_user, inclusion: { in: %w[admin member guest] }
|
validates :type_of_user, inclusion: { in: %w[admin member guest] }
|
||||||
|
|
||||||
|
after_create :update_user_organization_info_updated_at
|
||||||
|
after_destroy :update_user_organization_info_updated_at
|
||||||
|
|
||||||
|
def update_user_organization_info_updated_at
|
||||||
|
user.touch(:organization_info_updated_at)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
16
app/views/users/_organizations_area.html.erb
Executable file
16
app/views/users/_organizations_area.html.erb
Executable file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<% if @user.organizations.present? %>
|
||||||
|
<div id="sidebar-organizations" class="widget">
|
||||||
|
<div class="widget-suggested-follows-container">
|
||||||
|
<header><h4>organizations</h4></header>
|
||||||
|
<div class="widget-body">
|
||||||
|
<% @user.organizations.find_each do |organization| %>
|
||||||
|
<div class="widget-user-pic">
|
||||||
|
<a href="/<%= organization.slug %>">
|
||||||
|
<img src="<%= ProfileImage.new(organization).get(90) %>" alt="<%= organization.name %> profile image">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<div id="sidebar-wrapper-right" class="sidebar-wrapper sidebar-wrapper-right">
|
<div id="sidebar-wrapper-right" class="sidebar-wrapper sidebar-wrapper-right">
|
||||||
<div class="sidebar-bg" id="sidebar-bg-right"></div>
|
<div class="sidebar-bg" id="sidebar-bg-right"></div>
|
||||||
<div class="side-bar sidebar-additional showing" id="sidebar-additional">
|
<div class="side-bar sidebar-additional showing" id="sidebar-additional">
|
||||||
|
<%= render "users/organizations_area" %>
|
||||||
<% @user.github_repos.where(featured: true).order(stargazers_count: :desc, name: :asc).each do |repo| %>
|
<% @user.github_repos.where(featured: true).order(stargazers_count: :desc, name: :asc).each do |repo| %>
|
||||||
<a class="widget" href="<%= repo.url %>" target="_blank">
|
<a class="widget" href="<%= repo.url %>" target="_blank">
|
||||||
<header>
|
<header>
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@
|
||||||
loading...
|
loading...
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% cache "user-profile-sidebar-additional-#{@user.id}-#{@user.github_repos_updated_at}-#{@user.badge_achievements_count}", expires_in: 2.days do %>
|
<% cache "user-profile-sidebar-additional-#{@user.id}-#{@user.github_repos_updated_at}-#{@user.badge_achievements_count}-#{@user.organization_info_updated_at}", expires_in: 2.days do %>
|
||||||
<%= render "users/sidebar_additional" %>
|
<%= render "users/sidebar_additional" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddOrganizationInfoUpdatedAtToUsers < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :users, :organization_info_updated_at, :datetime
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1115,6 +1115,7 @@ ActiveRecord::Schema.define(version: 2020_01_20_053525) do
|
||||||
t.string "onboarding_variant_version", default: "0"
|
t.string "onboarding_variant_version", default: "0"
|
||||||
t.boolean "org_admin", default: false
|
t.boolean "org_admin", default: false
|
||||||
t.integer "organization_id"
|
t.integer "organization_id"
|
||||||
|
t.datetime "organization_info_updated_at"
|
||||||
t.boolean "permit_adjacent_sponsors", default: true
|
t.boolean "permit_adjacent_sponsors", default: true
|
||||||
t.datetime "personal_data_updated_at"
|
t.datetime "personal_data_updated_at"
|
||||||
t.string "profile_image"
|
t.string "profile_image"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :organization_membership do
|
factory :organization_membership do
|
||||||
user
|
association :user, factory: :user, strategy: :create
|
||||||
organization
|
association :organization, factory: :organization, strategy: :create
|
||||||
type_of_user { "member" }
|
type_of_user { "member" }
|
||||||
|
|
||||||
|
after(:build) do |organization_membership|
|
||||||
|
organization_membership.class.skip_callback(:create, :after, :update_user_organization_info_updated_at, raise: false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ RSpec.describe "User index", type: :system do
|
||||||
let!(:article) { create(:article, user: user) }
|
let!(:article) { create(:article, user: user) }
|
||||||
let!(:other_article) { create(:article) }
|
let!(:other_article) { create(:article) }
|
||||||
let!(:comment) { create(:comment, user: user, commentable: other_article) }
|
let!(:comment) { create(:comment, user: user, commentable: other_article) }
|
||||||
|
let(:organization) { create(:organization) }
|
||||||
|
|
||||||
context "when user is unauthorized" do
|
context "when user is unauthorized" do
|
||||||
context "when 1 article" do
|
context "when 1 article" do
|
||||||
|
|
@ -59,6 +60,17 @@ RSpec.describe "User index", type: :system do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when user has an organization membership" do
|
||||||
|
before do
|
||||||
|
user.organization_memberships.create(organization: organization, type_of_user: "member")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "shows organizations" do
|
||||||
|
visit "/user3000"
|
||||||
|
expect(page).to have_css("#sidebar-wrapper-right h4", text: "organizations")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "when visiting own profile" do
|
context "when visiting own profile" do
|
||||||
before do
|
before do
|
||||||
sign_in user
|
sign_in user
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue