-
-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add organization gems and organization edit/update
- Loading branch information
1 parent
5102ba0
commit 8521bc3
Showing
11 changed files
with
207 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Organizations::GemsController < ApplicationController | ||
before_action :redirect_to_signin, unless: :signed_in? | ||
before_action :redirect_to_new_mfa, if: :mfa_required_not_yet_enabled? | ||
before_action :redirect_to_settings_strong_mfa_required, if: :mfa_required_weak_level_enabled? | ||
|
||
before_action :find_organization, only: %i[index] | ||
|
||
layout "subject" | ||
|
||
# GET /organizations/:handle/gems | ||
|
||
def index | ||
@gems = @organization.rubygems.with_versions.by_downloads.preload(:most_recent_version, :gem_download).load_async | ||
end | ||
|
||
private | ||
|
||
def find_organization | ||
@organization = Organization.find_by_handle!(params[:organization_handle]) | ||
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
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,26 @@ | ||
<% content_for :subject do %> | ||
<%= render "organizations/subject", organization: @organization, current: :settings %> | ||
<% end %> | ||
|
||
<h1 class="text-h2 mb-10"><%= t("layouts.application.header.settings") %></h1> | ||
|
||
<%= render CardComponent.new do |c| %> | ||
<%= c.head do %> | ||
<%= c.title t("layouts.application.header.settings"), icon: "settings" %> | ||
<% end %> | ||
<%= form_with model: @organization, url: organization_path(@organization), method: :patch do |form| %> | ||
<div> | ||
<%= form.label :name, "Display Name", class: "block text-b2 font-semibold mb-2" %> | ||
<%= form.text_field( | ||
:name, | ||
class: "w-full text-b2 rounded-lg dark:bg-neutral-950 focus:ring-inset focus:ring-1 focus:ring-orange-500", | ||
required: true, | ||
autocomplete: "organization", | ||
) %> | ||
</div> | ||
|
||
<div class="flex mt-10"> | ||
<%= render ButtonComponent.new("Update", type: :submit, style: :outline) %> | ||
</div> | ||
<% 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<% content_for :subject do %> | ||
<%= render "organizations/subject", organization: @organization, current: :gems %> | ||
<% end %> | ||
|
||
<h1 class="text-h2 mb-10"><%= t("organizations.show.gems") %></h1> | ||
|
||
<%= render CardComponent.new do |c| %> | ||
<%= c.head do %> | ||
<%= c.title t("organizations.show.gems"), icon: "gems", count: @gems_count %> | ||
<% end %> | ||
<% if @gems.empty? %> | ||
<%= prose do %> | ||
<i><%= t('organizations.show.no_gems') %></i> | ||
<% end %> | ||
<% else %> | ||
<%= c.divided_list do %> | ||
<% @gems.each do |rubygem| %> | ||
<%= c.list_item_to( | ||
rubygem_path(rubygem.slug), | ||
title: short_info(rubygem.most_recent_version), | ||
) do %> | ||
<div class="flex flex-col w-full justify-between"> | ||
<div class="flex flex-row w-full items-center justify-between"> | ||
<h4 class="text-b1 flex"><%= rubygem.name %></h4> | ||
<%= version_number(rubygem.most_recent_version) %> | ||
</div> | ||
<div class="flex flex-row w-full items-center justify-between"> | ||
<%= download_count_component(rubygem, class: "flex") %> | ||
<div class="flex text-neutral-600"><%= version_date_component(rubygem.most_recent_version) %></div> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
<% 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
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,25 @@ | ||
require "test_helper" | ||
|
||
class Organizations::GemsTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@user = create(:user, remember_token_expires_at: Gemcutter::REMEMBER_FOR.from_now) | ||
post session_path(session: { who: @user.handle, password: PasswordHelpers::SECURE_TEST_PASSWORD }) | ||
end | ||
|
||
test "should get index" do | ||
@organization = create(:organization, owners: [@user]) | ||
@organization.rubygems << create(:rubygem, name: "arrakis", number: "1.0.0") | ||
|
||
get "/organizations/#{@organization.to_param}/gems" | ||
|
||
assert page.has_content? "arrakis" | ||
end | ||
|
||
test "should get index with no gems" do | ||
@organization = create(:organization, owners: [@user]) | ||
|
||
get "/organizations/#{@organization.to_param}/gems" | ||
|
||
assert page.has_content? "No gems 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require "test_helper" | ||
|
||
class OrganizationsTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@user = create(:user, remember_token_expires_at: Gemcutter::REMEMBER_FOR.from_now) | ||
post session_path(session: { who: @user.handle, password: PasswordHelpers::SECURE_TEST_PASSWORD }) | ||
end | ||
|
||
test "should show an organization" do | ||
@organization = create(:organization, owners: [@user]) | ||
@organization.rubygems << create(:rubygem, name: "arrakis", number: "1.0.0") | ||
|
||
get "/organizations/#{@organization.to_param}" | ||
|
||
assert_response :success | ||
assert page.has_content? "arrakis" | ||
end | ||
|
||
test "should render not found when an organization doesn't exist" do | ||
get "/organizations/notfound" | ||
|
||
assert_response :not_found | ||
end | ||
|
||
|
||
test "should list no organization for a user with none" do | ||
get "/organizations" | ||
|
||
assert_response :success | ||
end | ||
|
||
test "should list organizations for a user" do | ||
@organization = create(:organization, owners: [@user]) | ||
|
||
get "/organizations" | ||
|
||
assert_response :success | ||
assert page.has_content? @organization.name | ||
end | ||
|
||
test "should render organization edit form" do | ||
@organization = create(:organization, owners: [@user]) | ||
|
||
get "/organizations/#{@organization.to_param}/edit" | ||
|
||
assert_response :success | ||
assert_select "form[action=?]", organization_path(@organization) | ||
assert_select "input[name=?]", "organization[name]" | ||
end | ||
|
||
test "should update an organization display name" do | ||
@organization = create(:organization, owners: [@user]) | ||
|
||
patch "/organizations/#{@organization.to_param}", params: { | ||
organization: { name: "New Name" } | ||
} | ||
|
||
assert_redirected_to organization_path(@organization) | ||
follow_redirect! | ||
|
||
assert page.has_content? "New Name" | ||
end | ||
end |