-
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.
Merge pull request #10 from rauversion/label
Label
- Loading branch information
Showing
93 changed files
with
1,836 additions
and
372 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,110 @@ | ||
class AccountConnectionsController < ApplicationController | ||
|
||
|
||
def user_search | ||
@title = "Tracks" | ||
|
||
q = params[:q] | ||
if q.present? | ||
@artists = current_user.find_artists_excluding_children(q) | ||
end | ||
#.with_attached_avatar | ||
#.order("id desc") | ||
@artists = @artists ? @artists.page(params[:page]).per(5) : [] | ||
end | ||
|
||
def new | ||
@collection = [] | ||
@user = FormModels::ArtistForm.new( | ||
request_access: "request", | ||
hide: false, | ||
is_new: params[:kind] == "new" | ||
) | ||
@users = User.where(role: "artists").page(params[:page]).per(10) | ||
end | ||
|
||
def create | ||
if params[:form_models_artist_form] | ||
resource_params = params.require(:form_models_artist_form).permit( | ||
:password, :username, :hide, :request_access, :email, :search, :first_name, :last_name, :logo | ||
) | ||
@user = FormModels::ArtistForm.new(resource_params) | ||
@user.is_new = params[:kind] == "new" | ||
@user.inviter = current_user | ||
|
||
unless @user.username.present? | ||
@user.username = User.find_by(id: @user.search)&.username if @user.search.present? | ||
@user.inviter = current_user | ||
end | ||
if @user.valid? | ||
created_user = @user.process_user_interaction | ||
if !created_user | ||
flash.now[:error] = "not invited user" | ||
else | ||
@created = true | ||
end | ||
end | ||
return | ||
end | ||
|
||
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 | ||
|
||
if params[:commit] == "Send connect request" | ||
user = User.find(params[:user][:id]) | ||
connected_account = ConnectedAccount.attach_account(inviter: current_user , invited_user: user) if user | ||
|
||
if connected_account | ||
ConnectedAccountMailer.invitation_email(connected_account).deliver_now | ||
|
||
@created = true | ||
end | ||
return | ||
end | ||
end | ||
|
||
def impersonate | ||
if params[:username] | ||
user = User.find_by(username: params[:username]) | ||
if current_user.child_accounts.find(user.id) | ||
session[:parent_user] = current_user.id | ||
Current.label_user = current_user | ||
flash[:notice] = "signed as #{user.username}" | ||
sign_in(:user, user) | ||
redirect_to user_path(user.username) | ||
end | ||
else | ||
if session[:parent_user].present? | ||
user = User.find(session[:parent_user]) | ||
session[:parent_user] = nil | ||
Current.label_user = nil | ||
flash[:notice] = "signed as #{user.username}" | ||
sign_in(:user, user) | ||
redirect_to user_path(user.username) | ||
end | ||
end | ||
end | ||
|
||
def update | ||
|
||
end | ||
|
||
def approve | ||
@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 |
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,7 @@ | ||
class LabelArtistsController < ApplicationController | ||
|
||
|
||
def index | ||
@label = User.where(role: ["artist", "admin"], label: true).find_by(username: params[:user_id]) | ||
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,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,6 @@ | ||
class LabelsController < ApplicationController | ||
|
||
before_action :find_user, except: [:index] | ||
before_action :check_user_role, except: [:index] | ||
|
||
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,14 +1,25 @@ | ||
class LikesController < ApplicationController | ||
|
||
before_action :check_user | ||
|
||
def create | ||
@resource = find_resource | ||
@button_class = current_user.toggle_like!(@resource) ? "button-active" : "button" | ||
end | ||
|
||
private | ||
|
||
def find_resource | ||
if params[:track_id] | ||
@resource = Track.friendly.find(params[:track_id]) | ||
elsif params[:playlist_id] | ||
@resource = Playlist.friendly.find(params[:playlist_id]) | ||
end | ||
end | ||
|
||
def check_user | ||
redirect_to new_user_session_path and return if current_user.blank? | ||
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
Oops, something went wrong.