Skip to content
Extraits de code Groupes Projets
Valider 8ec85d3b rédigé par maxwell's avatar maxwell
Parcourir les fichiers

basic notifications

parent b2239895
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -7,16 +7,17 @@ class ApplicationController < ActionController::Base
protect_from_forgery :except => :receive
# 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 :set_invites
before_filter :set_locale
def set_contacts_and_status
def set_contacts_notifications_and_status
if current_user
@aspect = nil
@aspects = current_user.aspects.fields(:name)
@aspects_dropdown_array = @aspects.collect{|x| [x.to_s, x.id]}
@notifications = Notification.for(current_user)
end
end
......
# 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
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
def for(user, opts={})
query = opts.merge(:user_id => user)
self.all(opts)
def self.for(user, opts={})
self.all(opts.merge(:user_id => user.id))
end
end
......@@ -2,7 +2,6 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Service
include MongoMapper::Document
include ActionView::Helpers::TextHelper
......
%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"
confirm_remove_aspect: "Are you sure you want to delete this aspect?"
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:
edit:
export_data: "Export Data"
......
......@@ -7,6 +7,8 @@ Diaspora::Application.routes.draw do
resources :comments, :only => [:create]
resources :requests, :only => [:destroy, :create]
resources :services
resources :notifications, :only => [:destroy, :index]
resources :posts, :only => [:show], :path => '/p/'
resources :people do
resources :status_messages
......
# 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)
@person = Factory(:person)
@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
it 'contains a type' do
......@@ -26,7 +27,18 @@ describe Notification do
end
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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter