Skip to content

Commit

Permalink
account connections
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed May 13, 2024
1 parent 98107c9 commit a80d9c3
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 33 deletions.
15 changes: 13 additions & 2 deletions app/controllers/account_connections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def create
if params[:commit] == "Select user"
a = User.find(params[:search])
@selected_artist = FormModels::ArtistForm.new(username: a.username)
if @selected_artist.valid?
@selected_artist
end
return
end

Expand Down Expand Up @@ -93,7 +96,15 @@ def update
end

def approve
@connection_account = ConnectedAccount.find_signed(params[:id])
render json: @connected_account
@connected_account = ConnectedAccount.find_signed(params[:id])
@label = @connected_account.parent
@artist = @connected_account.user
if request.get?
sign_in(:user, @artist)
elsif request.post?
flash[:notice] = "you are now part of #{@label.username}"
redirect_to user_path(@artist.username)
end

end
end
24 changes: 24 additions & 0 deletions app/mailers/connected_account_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class ConnectedAccountMailer < ApplicationMailer
# default from: 'noreply@labelx.com'

# Method to send an invitation confirmation email to existing artists
def invitation_email(connected_account)
@artist = connected_account.user
@label = connected_account.parent
@connected_account = connected_account
mail(to: @artist.email, subject: "Welcome to Join Us at Label #{@label.username} on Rauversion.com!")
end

# Method to notify the label of a new artist account creation
def new_account_notification_to_label(connected_account)
@artist = connected_account.user
@label = connected_account.parent
mail(to: @label.email, subject: "New Artist Account Activation at Label #{@label.username}!")
end

def new_account_notification_to_artist(connected_account)
@artist = connected_account.user
@label = connected_account.parent
mail(to: @label.email, subject: "New Artist Account Activation at Label #{@label.username}!")
end
end
4 changes: 2 additions & 2 deletions app/models/connected_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def validate_unique_user_for_parent
errors.add(:user_id, "is already connected to this parent") if exists && new_record? || persisted? && changed?
end

def self.attach_account(inviter: , invited_user:)
inviter.connected_accounts.create(user_id: invited_user.id)
def self.attach_account(inviter: , invited_user:, state: "peding")
inviter.connected_accounts.create(user_id: invited_user.id, state: state)
end

def self.attach_new_account(inviter: , user_params:, state: "pending")
Expand Down
31 changes: 16 additions & 15 deletions app/models/form_models/artist_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def process_user_interaction
return false unless valid? # Ensure all validations pass before processing

User.transaction do
if request_access
if !is_new
send_invitation
else
create_user
Expand All @@ -56,7 +56,7 @@ def create_user
user.confirm

if user
connected_account = ConnectedAccount.attach_account(inviter: inviter , invited_user: user)
connected_account = ConnectedAccount.attach_account(inviter: inviter , invited_user: user, state: "active")

ConnectedAccountMailer.new_account_notification_to_label(connected_account).deliver_now

Expand All @@ -68,20 +68,21 @@ def create_user

# Send an invitation to the existing user
def send_invitation
invited_user = User.invite!(
{
username: username,
email: email,
role: "artist"
},
inviter
)

ConnectedAccount.attach_account(
inviter: inviter,
invited_user: invited_user
) if invited_user
invited_user = User.find_by(username: username)

if !inviter.child_accounts.exists?(invited_user.id)

connected_account = ConnectedAccount.attach_account(
inviter: inviter,
invited_user: invited_user,
state: "pending"
) if invited_user

invited_user
ConnectedAccountMailer.invitation_email(connected_account).deliver_now
invited_user
else
nil
end
end
end
7 changes: 5 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@ def self.track_preloaded_by_user_n(user:)

end

def reposts_preloaded
User.track_preloaded_by_user(id).joins(:reposts).where("reposts.user_id =?", id)
def reposts_preloaded(current_user: nil)
tracks = current_user.blank? ?
User.track_preloaded_by_user_n(user: self) :
User.track_preloaded_by_user(current_user_id: current_user, user: self)
tracks.joins(:reposts).where("reposts.user_id =?", id)
end

def is_publisher?
Expand Down
8 changes: 2 additions & 6 deletions app/views/account_connections/_existing.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
<%= t("Existing User") %>
</h2>

<%= f.object.errors.full_messages %>

<p class="text-md">Please search for an existing artist.</p>

<% # f.text_field :username, label: "username", hint: "Artist URL http://#{ ENV["DOMAIN"] }/jjj" %>
Expand All @@ -37,9 +35,9 @@
<span>.rauversion.com</span>
</div>

<p class="text-default text-md py-4 text-lg">Add via</p>
<p class="text-default text-md py-4 text-lg hidden">Add via</p>

<div class="space-y-2">
<div class="space-y-2 hidden">

<div class="flex space-x-2 items-center">
<%= f.radio_button :request_access, :request, label: "Request access from the artist" %>
Expand Down Expand Up @@ -69,6 +67,4 @@
<% end %>

<%= link_to "back", new_account_connection_path, data: {turbo_frame: "modal"} %>

</div>
9 changes: 3 additions & 6 deletions app/views/account_connections/_new_user.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
<%= t("New user") %>
</h2>

<%= f.object.errors.full_messages %>


<p>Please specify an account to add.</p>

<% # f.text_field :username, label: "username", hint: "Artist URL http://#{ ENV["DOMAIN"] }/jjj" %>
Expand All @@ -31,9 +28,9 @@
<%= f.text_field :email, hint: gettext("Email") %>
</div>
<div class="sm:col-span-3">
<%= f.file_field :avatar %>
</div>
<!--<div class="sm:col-span-3">
<% #= f.file_field :avatar %>
</div>-->
<div class="mt-6 grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6">
<div class="sm:col-span-6 flex justify-end space-x-2 items-center">
Expand Down
27 changes: 27 additions & 0 deletions app/views/account_connections/approve.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@




<div class="bg-default">
<div class="mx-auto max-w-7xl py-24 sm:px-6 sm:py-32 lg:px-8">
<div class="relative isolate overflow-hidden bg-muted px-6 py-24 text-center shadow-2xl sm:rounded-3xl sm:px-16">
<h2 class="mx-auto max-w-2xl text-3xl font-bold tracking-tight text-default sm:text-4xl">
Be part of <%= @label.username %> label.
</h2>
<p class="mx-auto mt-6 max-w-xl text-lg leading-8 text-gray-300">
<%= @label.username %>, has extended an invitation to be part of their catalog.
If you are agree please click on accept button, if not, just ignore the message
</p>
<div class="mt-10 flex items-center justify-center gap-x-6">
<%= button_to approve_account_connection_url(params[:id]), class: "button-sm-outline space-x-2" do %>
Get started
<% end %>

<a href="#" class="text-sm font-semibold leading-6 text-default">
Learn more <span aria-hidden="true"></span>
</a>

</div>
</div>
</div>
</div>
19 changes: 19 additions & 0 deletions app/views/connected_account_mailer/invitation_email.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

Dear <%= @artist.full_name %>,
<br>

We are delighted to extend an exclusive invitation for you to join Label <%= @label.username %>, on Rauversion platform.
<br>
Please confirm your interest by clicking on the following link:
<br>
<%= approve_account_connection_url(@connected_account.signed_id ) %>

<br>
As a member of Label <%= @label.username %>, you will have access to unique collaborative opportunities,
promotional support, and the chance to connect with a network of talented artists and industry professionals.
<br>
If you have any questions or wish to discuss this exciting opportunity further, please do not hesitate to contact us.
<br>
Warm regards,
<br>
Rauversion team
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Dear <%= @label.username %>, <br/>

We are excited to announce that a new artist account has been created on the your label, <%= @label.username%> on Rauversion.
<br>
This addition underscores our commitment to nurturing a diverse and vibrant artistic community.

<br/>
Artist Details:
<br/>

<br/>
Name: <%= @artist.full_name %>
<br/>
<!--Genre: [Artist’s Genre]-->
Account Created On: <%= l @artist.created_at, format: :short %>
<br/>
Please ensure that the artist’s onboarding process is seamless and engaging.
For more information or to review their profile, please visit the link below:
<br/>
<%= user_url @artist.username %>
<br/>
Thank you for your cooperation and enthusiasm as we welcome our newest artist to the Label <%= @label.full_name%> family.

<br/>
Best regards,
<br/>
Rauversion Team
35 changes: 35 additions & 0 deletions app/views/label_artists/_artist.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div>
<div class="group relative">
<%= link_to user_path(artist.username), data: {turbo_frame: "_top"} do %>
<div class="
h-56- lg:h-72-- xl:h-80--
w-full
rounded-full
overflow-hidden
bg-gray-200 group-hover:opacity-75">
<%= image_tag(artist.avatar_url, class: "h-full w-full object-cover object-center") %>
</div>

<h3 class="my-2 text-md text-default">
<span class="absolute- inset-0"></span> <%= artist.full_name.present? ? artist.full_name : artist.username %>
</h3>
<% end %>
<% if @admin %>
<div class="relative justify-end space-x-2 mb-2 hidden group-hover:flex">

<div class="flex absolute space-x-2 top-[-66px] left-[4.5em] p-2 bg-emphasis rounded-lg">
<%= link_to impersonate_account_connections_path(username: artist.username), data: {turbo_frame: "_top"} do %>
<span class="absolute- inset-0"></span> Impersonate
<% end %>
<%= link_to account_connection_path(artist.id), data: {turbo_method: :destroy, turbo_confirm: "sure?"} do %>
<span class="absolute- inset-0"></span> Disconnect
<% end %>
</div>
</div>
<% end %>
</div>

</div>
Empty file.
5 changes: 5 additions & 0 deletions spec/mailers/connected_account_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "rails_helper"

RSpec.describe ConnectedAccountMailer, type: :mailer do
pending "add some examples to (or delete) #{__FILE__}"
end
14 changes: 14 additions & 0 deletions spec/mailers/previews/connected_account_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Preview all emails at http://localhost:3000/rails/mailers/connected_account_mailer
class ConnectedAccountMailerPreview < ActionMailer::Preview


def new_account_notification_to_label
connected_account = ConnectedAccount.last
ConnectedAccountMailer.with(connected_account).new_account_notification_to_label(connected_account)
end

def invitation_email
connected_account = ConnectedAccount.last
ConnectedAccountMailer.with(connected_account).invitation_email(connected_account)
end
end

0 comments on commit a80d9c3

Please sign in to comment.