basic notifications
This commit is contained in:
parent
b22398951e
commit
8ec85d3b12
10 changed files with 113 additions and 8 deletions
|
|
@ -7,16 +7,17 @@ class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery :except => :receive
|
protect_from_forgery :except => :receive
|
||||||
|
|
||||||
# before_filter :mobile_except_ipad
|
# before_filter :mobile_except_ipad
|
||||||
before_filter :set_contacts_and_status, :except => [:create, :update]
|
before_filter :set_contacts_notifications_and_status, :except => [:create, :update]
|
||||||
before_filter :count_requests
|
before_filter :count_requests
|
||||||
before_filter :set_invites
|
before_filter :set_invites
|
||||||
before_filter :set_locale
|
before_filter :set_locale
|
||||||
|
|
||||||
def set_contacts_and_status
|
def set_contacts_notifications_and_status
|
||||||
if current_user
|
if current_user
|
||||||
@aspect = nil
|
@aspect = nil
|
||||||
@aspects = current_user.aspects.fields(:name)
|
@aspects = current_user.aspects.fields(:name)
|
||||||
@aspects_dropdown_array = @aspects.collect{|x| [x.to_s, x.id]}
|
@aspects_dropdown_array = @aspects.collect{|x| [x.to_s, x.id]}
|
||||||
|
@notifications = Notification.for(current_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
21
app/controllers/notifications_controller.rb
Normal file
21
app/controllers/notifications_controller.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
class NotificationsController < ApplicationController
|
||||||
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
note = Notification.find_by_user_id_and_id(current_user.id, params[:id])
|
||||||
|
if note
|
||||||
|
note.delete
|
||||||
|
render :nothing => true
|
||||||
|
else
|
||||||
|
render :nothing => true, :code => 404
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
22
app/helpers/notifications_helper.rb
Normal file
22
app/helpers/notifications_helper.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
module NotificationsHelper
|
||||||
|
def glue_text(kind)
|
||||||
|
translation = "notifications.#{kind.underscore}_glue"
|
||||||
|
t(translation)
|
||||||
|
end
|
||||||
|
|
||||||
|
def object_link(note)
|
||||||
|
kind = note.kind.underscore
|
||||||
|
translation = t("notifications.#{kind.underscore}_link")
|
||||||
|
case kind
|
||||||
|
when 'request'
|
||||||
|
link_to translation, aspects_manage_path
|
||||||
|
when 'status_message'
|
||||||
|
link_to translation, status_message_path(note.object_id)
|
||||||
|
when 'commnent'
|
||||||
|
link_to translation, object_path(note.object_id)
|
||||||
|
when 'photo'
|
||||||
|
link_to translation, photo_path(note.object_id)
|
||||||
|
else
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -16,8 +16,7 @@ class Notification
|
||||||
|
|
||||||
attr_accessible :object_id, :kind, :user_id, :person_id
|
attr_accessible :object_id, :kind, :user_id, :person_id
|
||||||
|
|
||||||
def for(user, opts={})
|
def self.for(user, opts={})
|
||||||
query = opts.merge(:user_id => user)
|
self.all(opts.merge(:user_id => user.id))
|
||||||
self.all(opts)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
class Service
|
class Service
|
||||||
include MongoMapper::Document
|
include MongoMapper::Document
|
||||||
include ActionView::Helpers::TextHelper
|
include ActionView::Helpers::TextHelper
|
||||||
|
|
|
||||||
6
app/views/notifications/index.html.haml
Normal file
6
app/views/notifications/index.html.haml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
%ul
|
||||||
|
- @notifications.each do |note|
|
||||||
|
%li
|
||||||
|
= link_to "#{note.person.name.titleize}", person_path(note.person)
|
||||||
|
= glue_text(note.kind)
|
||||||
|
= object_link(note)
|
||||||
|
|
@ -178,6 +178,14 @@ en:
|
||||||
remove_aspect: "Delete this aspect"
|
remove_aspect: "Delete this aspect"
|
||||||
confirm_remove_aspect: "Are you sure you want to delete this aspect?"
|
confirm_remove_aspect: "Are you sure you want to delete this aspect?"
|
||||||
add_existing: "Add an existing contact"
|
add_existing: "Add an existing contact"
|
||||||
|
notifications:
|
||||||
|
status_message_glue: "posted a new"
|
||||||
|
status_message_link: "message"
|
||||||
|
request_glue: "sent you a contact request"
|
||||||
|
request_link: "request"
|
||||||
|
comment_glue: "commented on your"
|
||||||
|
comment_link: "post"
|
||||||
|
also_commnet_glue: "commented on your contact's"
|
||||||
users:
|
users:
|
||||||
edit:
|
edit:
|
||||||
export_data: "Export Data"
|
export_data: "Export Data"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ Diaspora::Application.routes.draw do
|
||||||
resources :comments, :only => [:create]
|
resources :comments, :only => [:create]
|
||||||
resources :requests, :only => [:destroy, :create]
|
resources :requests, :only => [:destroy, :create]
|
||||||
resources :services
|
resources :services
|
||||||
|
|
||||||
|
resources :notifications, :only => [:destroy, :index]
|
||||||
resources :posts, :only => [:show], :path => '/p/'
|
resources :posts, :only => [:show], :path => '/p/'
|
||||||
resources :people do
|
resources :people do
|
||||||
resources :status_messages
|
resources :status_messages
|
||||||
|
|
|
||||||
35
spec/controllers/notifications_controller_spec.rb
Normal file
35
spec/controllers/notifications_controller_spec.rb
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe NotificationsController do
|
||||||
|
|
||||||
|
let!(:user) { make_user }
|
||||||
|
let!(:aspect) { user.aspects.create(:name => "AWESOME!!") }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in :user, user
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#destroy' do
|
||||||
|
it 'removes a notification' do
|
||||||
|
note = Notification.create(:user_id => user.id)
|
||||||
|
delete :destroy, :id => note.id
|
||||||
|
Notification.count.should == 0
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'only lets you delete your own notifications' do
|
||||||
|
user2 = make_user
|
||||||
|
|
||||||
|
Notification.create(:user_id => user.id)
|
||||||
|
note = Notification.create(:user_id => user2.id)
|
||||||
|
|
||||||
|
delete :destroy, :id => note.id
|
||||||
|
|
||||||
|
Notification.count.should == 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -10,7 +10,8 @@ describe Notification do
|
||||||
@sm = Factory(:status_message)
|
@sm = Factory(:status_message)
|
||||||
@person = Factory(:person)
|
@person = Factory(:person)
|
||||||
@user = make_user
|
@user = make_user
|
||||||
@note = Notification.new(:object_id => @sm.id, :kind => @sm.class.name, :person => @person, :user => @user)
|
@opts = {:object_id => @sm.id, :kind => @sm.class.name, :person_id => @person.id, :user_id => @user.id}
|
||||||
|
@note = Notification.new(@opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'contains a type' do
|
it 'contains a type' do
|
||||||
|
|
@ -26,7 +27,18 @@ describe Notification do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.for' do
|
describe '.for' do
|
||||||
|
it 'returns all of a users notifications' do
|
||||||
|
user2 = make_user
|
||||||
|
Notification.create(@opts)
|
||||||
|
Notification.create(@opts)
|
||||||
|
Notification.create(@opts)
|
||||||
|
Notification.create(@opts)
|
||||||
|
|
||||||
|
@opts.delete(:user_id)
|
||||||
|
Notification.create(@opts.merge(:user_id => user2.id))
|
||||||
|
|
||||||
|
Notification.for(@user).count.should == 4
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue