-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
381 additions
and
0 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,12 @@ | ||
class AccountConnectionsController < ApplicationController | ||
|
||
|
||
|
||
def new | ||
|
||
if request.headers["Turbo-Frame"] == "modal" | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class LabelArtistsController < ApplicationController | ||
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,34 @@ | ||
class LabelAuthController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
# Assuming `User` model and `Accounts` is a service object that contains user related queries | ||
# and `is_child_of?` is a method defined within your User model or an associated service. | ||
|
||
def add | ||
username = params[:username] | ||
user = User.get_user_by_username(username) | ||
|
||
if current_user.is_child_of?(user.id) | ||
sign_in(:user, user) # Devise's sign_in helper | ||
session[:parent_user] = current_user.id | ||
redirect_to "/#{user.username}" | ||
else | ||
flash[:error] = "Not allowed" | ||
redirect_to "/#{current_user.username}" | ||
end | ||
end | ||
|
||
def back | ||
username = params[:username] | ||
user = User.get_user_by_username(username) | ||
|
||
if user.is_child_of?(current_user.id) | ||
sign_in(:user, user) # Devise's sign_in helper | ||
session[:parent_user] = nil | ||
redirect_to "/#{user.username}" | ||
else | ||
flash[:error] = "Not allowed" | ||
redirect_to "/#{current_user.username}" | ||
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module AccountConnectionsHelper | ||
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,2 @@ | ||
module LabelArtistsHelper | ||
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,2 @@ | ||
module LabelAuthHelper | ||
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,13 @@ | ||
class ConnectedAccount < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :parent | ||
|
||
def self.attach_account(inviter: , invited_user:) | ||
inviter.connected_accounts.create(user: invited_user) | ||
end | ||
|
||
def self.attach_new_account(inviter: , user_params:) | ||
user = User.create(user_params) | ||
self.attach_account(inviter: inviter , invited_user: user) | ||
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,47 @@ | ||
<%= render "shared/modal" do %> | ||
|
||
<div class="space-y-4"> | ||
<% unless @selected_artist %> | ||
<h2 class="mx-0 mt-0 mb-4 font-sans text-2xl font-bold leading-none"> | ||
<%= t("existing_artist") %> | ||
</h2> | ||
<p class="text-md">Please search for an existing artist.</p> | ||
<%= form_with url: search_artists_path, method: :get, local: true do |form| %> | ||
<div class="mt-1 flex rounded-md shadow-sm md:col-span-6"> | ||
<span class="inline-flex items-center px-3 rounded-l-md border border-r-0 dark:border-gray-700 bg-blue-gray-50 text-blue-gray-500 sm:text-sm"> | ||
<%= t("search_artist") %>/ | ||
</span> | ||
<%= form.text_field :search, data: { action: "change->artist#search" }, autocomplete: "off", class: "autofill:!bg-yellow-200 dark:bg-gray-900 appearance-none block w-full px-3 py-2 border border-gray-300 dark:border-gray-700 flex-1 block w-full min-w-0 border-blue-gray-300 rounded-none rounded-r-md shadow-sm placeholder-gray-400 dark:placeholder-gray-600 focus:outline-none focus:ring-brand-500 focus:border-brand-500 sm:text-sm" %> | ||
</div> | ||
<% end %> | ||
<% @collection.each do |artist| %> | ||
<div class="dark:bg-gray-900 bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> | ||
<dt class="text-sm font-medium text-gray-500"> | ||
<%= artist.username %> | ||
</dt> | ||
<dd class="mt-1 text-sm text-gray-900 sm:col-span-2 sm:mt-0"> | ||
<%= button_to 'Select', select_artist_path(artist_id: artist.id), method: :post, class: "font-medium text-indigo-600 hover:text-indigo-500 dark:text-indigo-300 dark:hover:text-indigo-200" %> | ||
</dd> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
<% if @selected_artist %> | ||
<div class="space-y-4"> | ||
<p class="text-xl font-bold"> | ||
<%= t("%{name} is selected", name: @selected_artist.username) %> | ||
</p> | ||
<p class="text-md"> | ||
<%= t("Please confirm in order to send the connect invitation request to the artist.") %> | ||
</p> | ||
<div class="flex items-center space-x-4"> | ||
<%= button_to 'Send connect request', confirm_artist_path, method: :post, class: "w-full rounded-md border border-transparent bg-indigo-600 py-3 px-4 text-base font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:ring-offset-gray-50" %> | ||
<%= button_to 'Cancel', cancel_artist_path, method: :post, class: "btn btn-secondary" %> | ||
</div> | ||
<% if @errors %> | ||
<p class="text-red-600"><%= @errors %></p> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</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,33 @@ | ||
<%= render "shared/modal" do %> | ||
<div> | ||
<p>Please specify an account to add.</p> | ||
Artist URL http://<%= Rails.application.credentials.rauversion[:domain] %>/jjj | ||
|
||
, | ||
Add via | ||
Password | ||
Request access from the artist | ||
Hide artist | ||
You can hide and unhide artists later, too. | ||
<div> | ||
<%= form_with model: @changeset, url: save_hosts_managers_path, method: :post, local: true, id: "hosts-managers-form", data: { target: "myself", action: "validate->save" } do |f| %> | ||
<h2 class="mx-0 mt-0 mb-4 font-sans text-2xl font-bold leading-none"> | ||
<%= t("New user") %> | ||
</h2> | ||
|
||
<div class="mt-6 grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6"> | ||
<%= f.text_field :username, class: "sm:col-span-6" %> | ||
<%= f.text_field :first_name, class: "sm:col-span-6" %> | ||
<%= f.text_field :last_name, class: "sm:col-span-6" %> | ||
|
||
<div class="sm:col-span-6 flex justify-end space-x-2"> | ||
<%= f.submit t("Save"), data: { disable_with: t("Saving...") }, class: "inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-brand-600 hover:bg-brand-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-brand-500" %> | ||
</div> | ||
</div> | ||
<% end %> | ||
</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,29 @@ | ||
<!-- app/views/account_connect/new.html.erb --> | ||
|
||
<% if params[:kind] %> | ||
<% if params[:kind] == "new" %> | ||
<%= render "new_user" %> | ||
<% elsif params[:kind] == "existing" %> | ||
<%= render "existing" %> | ||
<% end %> | ||
<% else %> | ||
|
||
<div data-controller="account-connect" class="mx-auto md:w-2/4"> | ||
<div class="relative mx-auto mt-16 grid w-full max-w-container grid-cols-1 px-4 sm:mt-20 sm:px-6 lg:px-8 xl:mt-32"> | ||
<div class="relative z-10 p-4 space-y-8"> | ||
<div class="space-x-4 flex justify-center"> | ||
<!-- Trigger Stimulus actions --> | ||
<%= link_to "New Artist", new_account_connection_path(kind: "new"), data: {turbo_frame: "modal"} %> | ||
<%= link_to "Existing Artist", new_account_connection_path(kind: "existing"), data: {turbo_frame: "modal"} %> | ||
</div> | ||
<!-- Dynamic content updated via Stimulus and ActionCable --> | ||
<%= turbo_frame_tag "dynamic-content" do %> | ||
<!-- Updated content goes here --> | ||
<% end %> | ||
</div> | ||
</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,57 @@ | ||
<div class=""> | ||
<div class="mx-auto max-w-2xl py-16 px-4 sm:py-24 sm:px-6 lg:max-w-7xl lg:px-8"> | ||
|
||
<%= link_to "new artist", new_account_connection_path %> | ||
<%= link_to "existing artist", new_account_connection_path %> | ||
|
||
<div class="md:flex md:items-center md:justify-between"> | ||
<h2 class="text-2xl font-bold tracking-tight text-gray-900 dark:text-gray-200"> | ||
Artists | ||
</h2> | ||
|
||
<!--<a | ||
href="#" | ||
class="hidden text-sm font-medium text-indigo-600 hover:text-indigo-500 md:block" | ||
> | ||
Shop the collection <span aria-hidden="true"> →</span> | ||
</a>--> | ||
<% if current_user.id == @profile&.id %> | ||
<%= link_to "/accounts/connnect", class: "inline-flex justify-between dark:border-2 dark:border-white rounded-lg py-3 px-5 bg-black text-white block font-medium" do %> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
class="h-6 w-6" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke="currentColor" | ||
stroke-width="2" | ||
> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4v16m8-8H4"></path> | ||
</svg> | ||
<span>Add artist</span> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
|
||
<div class="mt-6 grid grid-cols-2 gap-x-4 gap-y-10 sm:gap-x-6 md:grid-cols-4 md:gap-y-0 lg:gap-x-8"> | ||
<% current_user.child_accounts.each do |artist| %> | ||
<div class="group relative"> | ||
<div class="h-56 lg:h-72-- xl:h-80-- w-full overflow-hidden rounded-md bg-gray-200 group-hover:opacity-75"> | ||
<%= image_tag(artist.avatar.url, class: "h-full w-full object-cover object-center") %> | ||
</div> | ||
|
||
<h3 class="mt-4 text-sm text-gray-700 dark:text-gray-300"> | ||
<%= link_to user_path(artist.username) do %> | ||
<span class="absolute inset-0"></span> <%= artist.username %> | ||
<% end %> | ||
</h3> | ||
</div> | ||
<% end %> | ||
</div> | ||
|
||
<div class="mt-8 text-sm md:hidden"> | ||
<a href="#" class="font-medium text-indigo-600 hover:text-indigo-500"> | ||
Shop the collection <span aria-hidden="true"> →</span> | ||
</a> | ||
</div> | ||
</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,11 @@ | ||
class CreateConnectedAccounts < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :connected_accounts do |t| | ||
t.references :user, null: false, foreign_key: true | ||
t.string :state | ||
t.references :parent, null: false, foreign_key: {to_table: :users} | ||
|
||
t.timestamps | ||
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :connected_account do | ||
user { nil } | ||
state { "MyString" } | ||
parent { nil } | ||
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,15 @@ | ||
require 'rails_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the AccountConnectionsHelper. For example: | ||
# | ||
# describe AccountConnectionsHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# expect(helper.concat_strings("this","that")).to eq("this that") | ||
# end | ||
# end | ||
# end | ||
RSpec.describe AccountConnectionsHelper, type: :helper do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
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 @@ | ||
require 'rails_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the LabelArtistsHelper. For example: | ||
# | ||
# describe LabelArtistsHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# expect(helper.concat_strings("this","that")).to eq("this that") | ||
# end | ||
# end | ||
# end | ||
RSpec.describe LabelArtistsHelper, type: :helper do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
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 @@ | ||
require 'rails_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the LabelAuthHelper. For example: | ||
# | ||
# describe LabelAuthHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# expect(helper.concat_strings("this","that")).to eq("this that") | ||
# end | ||
# end | ||
# end | ||
RSpec.describe LabelAuthHelper, type: :helper do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
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,64 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ConnectedAccount, type: :model do | ||
describe "ConnectedAccount" do | ||
let(:invalid_attributes) { { state: nil } } | ||
|
||
context "list" do | ||
it "returns all connected accounts" do | ||
connected_account = FactoryBot.create(:connected_account) | ||
expect(ConnectedAccount.all).to eq([connected_account]) | ||
end | ||
end | ||
|
||
context "get!" do | ||
it "returns the connected account with given id" do | ||
connected_account = FactoryBot.create(:connected_account) | ||
expect(ConnectedAccount.find(connected_account.id)).to eq(connected_account) | ||
end | ||
end | ||
|
||
context "create" do | ||
it "with valid data creates a connected account" do | ||
valid_attributes = { state: "some state" } | ||
connected_account = ConnectedAccount.create(valid_attributes) | ||
expect(connected_account.state).to eq("some state") | ||
end | ||
|
||
it "with invalid data returns error" do | ||
connected_account = ConnectedAccount.new(invalid_attributes) | ||
expect(connected_account.valid?).to be_falsey | ||
expect(connected_account.errors).to be_present | ||
end | ||
end | ||
|
||
context "update" do | ||
it "with valid data updates the connected account" do | ||
connected_account = FactoryBot.create(:connected_account) | ||
update_attributes = { state: "some updated state" } | ||
connected_account.update(update_attributes) | ||
expect(connected_account.state).to eq("some updated state") | ||
end | ||
|
||
it "with invalid data does not update connected account" do | ||
connected_account = FactoryBot.create(:connected_account) | ||
connected_account.update(invalid_attributes) | ||
expect(connected_account.reload.attributes).not_to include(invalid_attributes.stringify_keys) | ||
end | ||
end | ||
|
||
context "delete" do | ||
it "deletes the connected account" do | ||
connected_account = FactoryBot.create(:connected_account) | ||
expect { connected_account.destroy }.to change(ConnectedAccount, :count).by(-1) | ||
end | ||
end | ||
|
||
context "change" do | ||
it "returns a connected account changeset" do | ||
connected_account = FactoryBot.create(:connected_account) | ||
expect(connected_account).to be_valid | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "AccountConnections", type: :request do | ||
describe "GET /index" do | ||
pending "add some examples (or delete) #{__FILE__}" | ||
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,7 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe "LabelArtists", type: :request do | ||
describe "GET /index" do | ||
pending "add some examples (or delete) #{__FILE__}" | ||
end | ||
end |
Oops, something went wrong.