Skip to content

Commit

Permalink
Merge pull request #10 from rauversion/label
Browse files Browse the repository at this point in the history
Label
  • Loading branch information
michelson committed May 13, 2024
2 parents 8e09000 + a80d9c3 commit 5b9ceb9
Show file tree
Hide file tree
Showing 93 changed files with 1,836 additions and 372 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gem "puma", "~> 5.0"
# Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
gem "jsbundling-rails"

gem "hotwire_combobox"
gem "hotwire_combobox", github: "josefarias/hotwire_combobox", branch: "main"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails", github: "hotwired/turbo-rails", branch: "main"
Expand Down
24 changes: 15 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@ GIT

GIT
remote: https://github.com/hotwired/turbo-rails.git
revision: e8dd34a11b588978534ce9b8f8e0822f2c6e3f2a
revision: e376852bfb273f69f4ebb54cf516b99fcbaa7acb
branch: main
specs:
turbo-rails (2.0.4)
turbo-rails (2.0.5)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)

GIT
remote: https://github.com/josefarias/hotwire_combobox.git
revision: 201954ceecf369f4ec70fbd50afaa4e3d0cebedc
branch: main
specs:
hotwire_combobox (0.2.5)
rails (>= 7.0.7.2)
stimulus-rails (>= 1.2)
turbo-rails (>= 1.2)

GIT
remote: https://github.com/rspec/rspec-core.git
revision: 81589709e88db1ec2537faee3a7f4a43c7d9aac1
Expand Down Expand Up @@ -268,10 +278,6 @@ GEM
groupdate (6.3.0)
activesupport (>= 6.1)
hashie (5.0.0)
hotwire_combobox (0.2.1)
rails (>= 7.0.7.2)
stimulus-rails (>= 1.2)
turbo-rails (>= 1.2)
http (5.1.1)
addressable (~> 2.8)
http-cookie (~> 1.0)
Expand Down Expand Up @@ -340,7 +346,7 @@ GEM
json (>= 1.4.6)
meta-tags (2.18.0)
actionpack (>= 3.2.0, < 7.1)
method_source (1.0.0)
method_source (1.1.0)
mini_magick (4.12.0)
mini_mime (1.1.5)
minitest (5.22.3)
Expand Down Expand Up @@ -558,7 +564,7 @@ GEM
rubocop-performance (~> 1.18.0)
standardrb (1.0.1)
standard
stimulus-rails (1.2.1)
stimulus-rails (1.3.3)
railties (>= 6.0.0)
store_attribute (1.1.1)
activerecord (>= 6.0)
Expand Down Expand Up @@ -620,7 +626,7 @@ DEPENDENCIES
friendly_id (~> 5.4)
geocoder (~> 1.8)
groupdate (~> 6.3)
hotwire_combobox
hotwire_combobox!
http (~> 5.1)
image_processing (~> 1.2)
jbuilder
Expand Down
14 changes: 9 additions & 5 deletions app/assets/stylesheets/application.tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
/* Brand shinanigans
-> These will be computed for the users theme at runtime.
*/
--rau-brand: #002c63;
--rau-brand: #ea09e3;
--rau-brand-emphasis: #002c63;
--rau-brand-text: white;
}
Expand Down Expand Up @@ -89,7 +89,7 @@
-> These will be computed for the users theme at runtime.
*/

--rau-brand: #002c63;
--rau-brand: #ea09e3;
--rau-brand-emphasis: #002c63;
--rau-brand-text: white;
}
Expand Down Expand Up @@ -203,6 +203,10 @@
@apply bg-white;
}

.scaleX {
@apply hover:scale-125 transform-gpu hover:animate-pulse transition duration-500;
}

textarea {
@apply block w-full rounded-md border-0 py-1.5 dark:bg-gray-900 dark:text-gray-100 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-brand-600 sm:text-sm sm:leading-6;
}
Expand Down Expand Up @@ -342,16 +346,16 @@
/* COMBOBOX */

.hw-combobox__main__wrapper {
@apply sm:w-[35rem] rounded-full w-80;
@apply sm:w-full rounded-full w-80 relative;
}
.hw-combobox__handle {
@apply right-3;
}
.hw-combobox__listbox {
@apply rounded-2xl bg-subtle;
@apply rounded-2xl bg-subtle overflow-auto h-48 absolute w-full z-[500];
}

.hw-combobox__option {
.hw-combobox__listbox .hw-combobox__option {
@apply p-2 border-b border-muted hover:bg-emphasis;
}
}
110 changes: 110 additions & 0 deletions app/controllers/account_connections_controller.rb
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
20 changes: 18 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
class ApplicationController < ActionController::Base
before_action do
ActiveStorage::Current.url_options = {protocol: request.protocol, host: request.host, port: request.port}
ActiveStorage::Current.host = request.url

# ActiveStorage::Current.url_options = { protocol: "http://", host: "localhost", port: "3000" }
Current.label_user = User.find(session[:parent_user]) if session[:parent_user].present?
end

before_action :set_locale

helper_method :flash_stream

def flash_stream
turbo_stream.replace("flash", partial: "shared/flash", locals: { flash: flash })
end

helper_method :impersonating?
def impersonating?(user)
label_user.present? && current_user&.id == user&.id
end

def set_locale
if params[:locale].present?
cookies[:locale] = params[:locale]
Expand All @@ -19,6 +29,12 @@ def set_locale
end
end

helper_method :label_user
def label_user
return if session[:parent_user].blank?
@label_user ||= User.find session[:parent_user]
end

def become
if current_user.is_admin?
user = User.find_by(username: params[:id])
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/label_artists_controller.rb
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
34 changes: 34 additions & 0 deletions app/controllers/label_auth_controller.rb
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
6 changes: 6 additions & 0 deletions app/controllers/labels_controller.rb
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
11 changes: 11 additions & 0 deletions app/controllers/likes_controller.rb
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
8 changes: 8 additions & 0 deletions app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ class PhotosController < ApplicationController
def create
end

def show
@photos = User.find(params[:user_id]).photos
@photo = User.find(params[:user_id]).photos.find(params[:id])
@prev_photo = @photos.where("id < ?", @photo.id).last
@next_photo = @photos.where("id > ?", @photo.id).first

end

def update
current_user.update(resource_params)

Expand Down
Loading

0 comments on commit 5b9ceb9

Please sign in to comment.