Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Link invites for playlist

  • Loading branch information...
commit 6dd2f7700c1305d20b61827493bc4146ffe9f84b 1 parent 43134b2
@shell shell authored
View
1  Gemfile
@@ -11,7 +11,6 @@ gem "paperclip", "~> 2.4"
gem "bcrypt-ruby", :require => "bcrypt"
gem "friendly_id", "~> 4.0.0.beta14"
-
# HAML and SASS for Templating
gem 'sass'
gem 'haml'
View
6 app/controllers/application_controller.rb
@@ -1,6 +1,12 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+ before_filter :mailer_set_url_options
+
+ def mailer_set_url_options
+ ActionMailer::Base.default_url_options[:host] = request.host_with_port
+ end
+
private
def has_access_to(user, playlist)
playlist && user && (playlist.user == user || playlist.members.include?(user) || playlist.invited_members.include?(user))
View
40 app/controllers/invites_controller.rb
@@ -1,5 +1,5 @@
-class InvitesController < ApplicationController
- def create
+class InvitesController < ApplicationController
+ def create
@errors = []
playlist_id, username = params[:playlist_id], params[:username]
if playlist_id.nil? || username.nil?
@@ -11,10 +11,10 @@ def create
@playlist = Playlist.find(playlist_id)
@user = User.find_by_username(username)
unless @playlist.members.collect(&:id).include?(@user.id) || PlaylistInvite.exists?(:playlist_id => playlist_id, :user_id => @user.id)
- @invite = PlaylistInvite.create(:playlist_id => playlist_id,
- :user_id => @user.id,
+ @invite = PlaylistInvite.create(:playlist_id => playlist_id,
+ :user_id => @user.id,
:invite_token => BCrypt::Engine.generate_salt)
- else
+ else
@errors << "Already invited"
end
end
@@ -22,9 +22,9 @@ def create
format.js
end
end
-
+
end
-
+
def accept
if params[:token]
@invite = PlaylistInvite.find_by_invite_token(params[:token])
@@ -40,5 +40,29 @@ def accept
end
end
end
-
+
+ def generate_for_everyone
+ @type = 'link_everyone'
+ playlist_id = params[:playlist_id]
+ @invite = PlaylistInvite.where(playlist_id: playlist_id, invite_type: @type).first
+ unless @invite
+ @invite = PlaylistInvite.create(playlist_id: playlist_id, invite_type: @type, invite_token: BCrypt::Engine.generate_salt)
+ @created = true
+ end
+
+ render :generate
+ end
+
+ def generate_for_plisters
+ @type = 'link_plisters'
+ playlist_id = params[:playlist_id]
+ @invite = PlaylistInvite.where(playlist_id: playlist_id, invite_type: @type).first
+ unless @invite
+ @invite = PlaylistInvite.create(playlist_id: playlist_id, invite_type: @type, invite_token: BCrypt::Engine.generate_salt)
+ @created = true
+ end
+
+ render :generate
+ end
+
end
View
2  app/controllers/playlists_controller.rb
@@ -8,6 +8,8 @@ class PlaylistsController < InheritedResources::Base
def show
show! do |format|
+ @link_invite_everyone = @playlist.link_invite
+ @link_invite_plisters = @playlist.link_invite('plisters')
format.html {
unless @playlist.published
if !user_signed_in? || !has_access_to(current_user, @playlist)
View
8 app/helpers/playlist_helper.rb
@@ -1,8 +1,12 @@
module PlaylistHelper
def myown_playlist
- @playlist && current_user && (@playlist.user == current_user || @playlist.members.include?(current_user))
+ @playlist && current_user &&
+ (@playlist.user == current_user ||
+ @playlist.members.include?(current_user) ||
+ (params[:access_token] && @playlist.accessible_via(params[:access_token])))
+
end
-
+
def user_invited?
current_user && PlaylistInvite.user_invited_to(current_user.id, @playlist.id).count > 0
end
View
8 app/models/playlist.rb
@@ -60,6 +60,10 @@ def has_member?(user)
def accessible_by(user)
self.user == user || self.has_member?(user)
end
+
+ def accessible_via(access_token)
+ link_invite && (link_invite.invite_token == access_token || link_invite('plisters').invite_token == access_token)
+ end
def invited_members
invited_ids = PlaylistInvite.where(:playlist_id => self.id).collect(&:user_id).uniq
@@ -70,6 +74,10 @@ def invite_for(user_id)
PlaylistInvite.user_invited_to(user_id, self.id).first
end
+ def link_invite(type = 'everyone')
+ PlaylistInvite.where(invite_type: "link_#{type}", playlist_id: self.id).first
+ end
+
class << self
def shared_with(user_id)
shared_ids = Collaborator.where(:user_id => user_id).collect(&:playlist_id).uniq
View
18 app/models/playlist_invite.rb
@@ -5,13 +5,22 @@ class PlaylistInvite < ActiveRecord::Base
scope :for_user, -> user_id { includes(:playlist).where(user_id: user_id) }
scope :user_invited_to, -> user_id, playlist_id { joins(:playlist).where(user_id: user_id, playlist_id: playlist_id) }
+ scope :user, where(invite_type: 'user')
def after_create
- UserMailer.collaboration_invite(self).deliver
+ UserMailer.collaboration_invite(self).deliver if user_id
end
def url
- link_to 'Accept invintation', Rails.application.routes.url_helpers.accept_invites_url(:token => invite_token, :host => 'dev.plist.tv')
+ if invite_type == 'user'
+ routes.accept_invites_url(:token => invite_token)
+ elsif invite_type
+ routes.user_playlist_url(self.playlist.user.username, self.playlist, access_token: invite_token)
+ end
+ end
+
+ def link
+ Rails.application.routes.url_helpers.accept_invites_url(:token => invite_token)
end
def accept(current_user)
@@ -28,4 +37,9 @@ def accept(current_user)
self.delete
self
end
+
+ def routes
+ Rails.application.routes.url_helpers
+ end
+
end
View
6 app/views/invites/generate.js.erb
@@ -0,0 +1,6 @@
+<% if @created %>
+ $('.<%= @type %>').remove()
+ $('.link_invites').append($('<%= link_to "Invite #{@type}", @invite.url %> '))
+<% else %>
+ $.ctNotify("Already have that type of invite", 'error')
+<% end %>
View
15 app/views/playlists/_invites_box.html.haml
@@ -0,0 +1,15 @@
+// Invite box
+%div
+ = text_field_tag :username, nil, :class => 'invite_field', :id => 'invite_username', :placeholder => "username of user you want to invite"
+ = link_to 'Invite', '#', :id => 'invite_btn'
+
+// URL invites
+.link_invites
+ - if @link_invite_everyone
+ = link_to "Invite everyone", @link_invite_everyone.url
+ - else
+ = link_to 'Invite everyone', generate_for_everyone_invites_path(playlist_id: @playlist.id), remote: true, class: 'fallr-button fallr-green link_everyone'
+ / - if @link_invite_plisters
+ / = link_to "Invite plisters", @link_invite_plisters.url
+ / - else
+ / = link_to 'Invite plisters', generate_for_plisters_invites_path(playlist_id: @playlist.id), remote: true, class: 'fallr-button fallr-green link_plisters'
View
13 app/views/playlists/_options.html.haml
@@ -7,6 +7,8 @@
%span Description
= f.text_area :description, :class => 'playlist_title', :size => '20x2'
%br
+
+ // published / unpublished
- unless @playlist.has_member? current_user
%div
%span Visibility
@@ -15,6 +17,7 @@
= f.label :published_no, "Unpublished"
= f.radio_button :published, true
= f.label :published_yes, "Published"
+ // Collaborators
- if @playlist.members.length > 0
%div
%span Owner:
@@ -22,9 +25,12 @@
%div
%span Collaborators:
= @playlist.members.collect(&:username).join(', ')
- %div
- = text_field_tag :username, nil, :class => 'invite_field', :id => 'invite_username', :placeholder => "username of user you want to invite"
- = link_to 'Invite', '#', :id => 'invite_btn'
+
+ %br/
+ = render 'invites_box'
+ %br/
+
+ // featured
- unless @playlist.has_member? current_user
%div
- if @playlist.ask_for_promotion == 0
@@ -32,5 +38,6 @@
- else
- if !@playlist.featured
Waiting for promotion
+ // delete playlist
%div
= link_to "Delete Playlist", playlist_path(@playlist.id), :class => 'fallr-button fallr-red', :remote => true, :method => :delete, :confirm => "Are you sure?"
View
2  app/views/user_mailer/collaboration_invite.html.haml
@@ -104,7 +104,7 @@
Hi
= @invite.user.username
\, this is collaboration invintation from Plist.tv: to
- = @invite.playlist.title
+ = link_to @invite.playlist.title, user_playlist_path(@invite.playlist.user.username, @invite.playlist)
click to
= @invite.url
%br>/
View
4 config/deploy.rb
@@ -20,7 +20,7 @@
set :use_sudo, false
task :staging do
- set :branch, 'invites'
+ set :branch, 'master'
set :rails_env, "staging" # for now
ssh_options[:username] = 'www'
set :deploy_to, "/srv/www/plisttv-dev"
@@ -78,5 +78,5 @@
run "cd #{release_path} && bundle install"
end
-after "deploy:update_code", :bundle_install
+# after "deploy:update_code", :bundle_install
after "deploy:update_code", "deploy:assets_symlink"
View
6 config/routes.rb
@@ -1,8 +1,10 @@
Plist::Application.routes.draw do
+ default_url_options :host => "plist.dev"
+
devise_for :users, :controllers => { :registrations => "registrations", :sessions => "sessions" }
resources :users do
- resources :playlists do
+ resources :playlists do
get :shared, on: :collection
end
resources :jukeboxes
@@ -24,6 +26,8 @@
resources :invites, :only => [:create] do
get :accept, :on => :collection
+ get :generate_for_everyone, :on => :collection
+ get :generate_for_plisters, :on => :collection
end
devise_scope :user do
View
9 db/migrate/20111211091615_add_invite_kind.rb
@@ -0,0 +1,9 @@
+class AddInviteKind < ActiveRecord::Migration
+ def self.up
+ add_column :playlist_invites, :invite_type, :string, default: 'user'
+ end
+
+ def self.down
+ remove_column :playlist_invites, :invite_type
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.