Skip to content
Extraits de code Groupes Projets
Valider 200b0045 rédigé par Daniel Vincent Grippi's avatar Daniel Vincent Grippi
Parcourir les fichiers

Merge branch 'master' of github.com:diaspora/diaspora

Conflicts:
	public/stylesheets/application.css
	public/stylesheets/sass/application.sass
parents 8c80174e 1312728b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 189 ajouts et 105 suppressions
......@@ -17,8 +17,8 @@ class ApplicationController < ActionController::Base
def set_friends_and_status
if current_user
@group = :all
@groups = current_user.groups
@aspect = :all
@aspects = current_user.aspects
@friends = current_user.friends
end
end
......
class GroupsController < ApplicationController
class AspectsController < ApplicationController
before_filter :authenticate_user!
respond_to :html
......@@ -6,63 +6,63 @@ class GroupsController < ApplicationController
def index
@posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC'
@group = :all
@aspect = :all
end
def create
@group = current_user.group params[:group]
respond_with @group
@aspect = current_user.aspect params[:aspect]
respond_with @aspect
end
def new
@group = Group.new
@aspect = Aspect.new
end
def destroy
@group = Group.find_by_id params[:id]
@group.destroy
respond_with :location => groups_url
@aspect = Aspect.find_by_id params[:id]
@aspect.destroy
respond_with :location => aspects_url
end
def show
@group = Group.find_by_id params[:id]
@friends = @group.people
@posts = current_user.visible_posts( :by_members_of => @group ).paginate :per_page => 15, :order => 'created_at DESC'
@aspect = Aspect.find_by_id params[:id]
@friends = @aspect.people
@posts = current_user.visible_posts( :by_members_of => @aspect ).paginate :per_page => 15, :order => 'created_at DESC'
respond_with @group
respond_with @aspect
end
def edit
@groups = current_user.groups
@aspects = current_user.aspects
@remote_requests = Request.for_user current_user
end
def update
@group = Group.find_by_id(params[:id])
@group.update_attributes(params[:group])
respond_with @group
@aspect = Aspect.find_by_id(params[:id])
@aspect.update_attributes(params[:aspect])
respond_with @aspect
end
def move_friends
params[:moves].each{ |move|
move = move[1]
unless current_user.move_friend(move)
flash[:error] = "Group editing failed for friend #{Person.find_by_id( move[:friend_id] ).real_name}."
redirect_to Group.first, :action => "edit"
flash[:error] = "Aspect editing failed for friend #{Person.find_by_id( move[:friend_id] ).real_name}."
redirect_to Aspect.first, :action => "edit"
return
end
}
flash[:notice] = "Groups edited successfully."
redirect_to Group.first, :action => "edit"
flash[:notice] = "Aspects edited successfully."
redirect_to Aspect.first, :action => "edit"
end
def move_friend
unless current_user.move_friend( :friend_id => params[:friend_id], :from => params[:from], :to => params[:to][:to])
flash[:error] = "didn't work #{params.inspect}"
end
if group = Group.first(:id => params[:to][:to])
redirect_to group
if aspect = Aspect.first(:id => params[:to][:to])
redirect_to aspect
else
redirect_to Person.first(:id => params[:friend_id])
end
......
......@@ -30,8 +30,8 @@ def warzombie
backer_email = "#{backer['username']}@#{backer['username']}.joindiaspora.com"
rel_hash = relationship_flow(backer_email)
logger.info "Zombefriending #{backer['given_name']} #{backer['family_name']}"
logger.info "Calling send_friend_request with #{rel_hash[:friend]} and #{current_user.groups.first}"
current_user.send_friend_request_to(rel_hash[:friend], current_user.groups.first)
logger.info "Calling send_friend_request with #{rel_hash[:friend]} and #{current_user.aspects.first}"
current_user.send_friend_request_to(rel_hash[:friend], current_user.aspects.first)
end
end
end
......@@ -39,7 +39,7 @@ def warzombie
def zombiefriendaccept
render :nothing => true
Request.all.each{|r|
current_user.accept_and_respond(r.id, current_user.groups.first.id)
current_user.accept_and_respond(r.id, current_user.aspects.first.id)
}
end
......
......@@ -5,7 +5,7 @@ class PeopleController < ApplicationController
respond_to :json, :only => [:index, :show]
def index
@groups_dropdown_array = current_user.groups.collect{|x| [x.to_s, x.id]}
@aspects_dropdown_array = current_user.aspects.collect{|x| [x.to_s, x.id]}
@people = Person.search params[:q]
respond_with @people
end
......@@ -13,8 +13,8 @@ class PeopleController < ApplicationController
def show
@person = current_user.visible_person_by_id(params[:id])
@profile = @person.profile
@groups_with_person = current_user.groups_with_person(@person)
@groups_dropdown_array = current_user.groups.collect{|x| [x.to_s, x.id]}
@aspects_with_person = current_user.aspects_with_person(@person)
@aspects_dropdown_array = current_user.aspects.collect{|x| [x.to_s, x.id]}
@posts = current_user.visible_posts_from_others(:from => @person).paginate :page => params[:page], :order => 'created_at DESC'
@latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last
@post_count = @posts.count
......
......@@ -14,12 +14,12 @@ class RequestsController < ApplicationController
def destroy
if params[:accept]
if params[:group_id]
@friend = current_user.accept_and_respond( params[:id], params[:group_id])
if params[:aspect_id]
@friend = current_user.accept_and_respond( params[:id], params[:aspect_id])
flash[:notice] = "you are now friends"
respond_with :location => current_user.group_by_id(params[:group_id])
respond_with :location => current_user.aspect_by_id(params[:aspect_id])
else
flash[:error] = "please select a group!"
flash[:error] = "please select a aspect!"
respond_with :location => requests_url
end
else
......@@ -33,32 +33,32 @@ class RequestsController < ApplicationController
end
def create
group = current_user.group_by_id(params[:request][:group_id])
aspect = current_user.aspect_by_id(params[:request][:aspect_id])
begin
rel_hash = relationship_flow(params[:request][:destination_url])
rescue Exception => e
respond_with :location => group, :error => "No diaspora seed found with this email!"
respond_with :location => aspect, :error => "No diaspora seed found with this email!"
return
end
Rails.logger.debug("Sending request: #{rel_hash}")
begin
@request = current_user.send_friend_request_to(rel_hash[:friend], group)
@request = current_user.send_friend_request_to(rel_hash[:friend], aspect)
rescue Exception => e
raise e unless e.message.include? "already friends"
message = "You are already friends with #{params[:request][:destination_url]}!"
respond_with :location => group, :notice => message
respond_with :location => aspect, :notice => message
return
end
if @request
message = "A friend request was sent to #{@request.destination_url}."
respond_with :location => group, :notice => message
respond_with :location => aspect, :notice => message
else
message = "Something went horribly wrong."
respond_with :location => group, :error => message
respond_with :location => aspect, :error => message
end
end
......
......@@ -5,7 +5,7 @@ class StatusMessagesController < ApplicationController
respond_to :json, :only => :show
def create
params[:status_message][:to] = params[:group_ids]
params[:status_message][:to] = params[:aspect_ids]
@status_message = current_user.post(:status_message, params[:status_message])
respond_with @status_message
end
......
module ApplicationHelper
def current_group?(group)
@group != :all && @group.id == group.id
def current_aspect?(aspect)
@aspect != :all && @aspect.id == aspect.id
end
def object_path(object)
......
module AspectsHelper
def link_for_aspect( aspect )
link_to aspect.name, aspect
end
end
module GroupsHelper
def link_for_group( group )
link_to group.name, group
end
end
class Group
class Aspect
include MongoMapper::Document
key :name, String
......@@ -27,7 +27,7 @@ class Group
def as_json(opts = {})
{
:group => {
:aspect => {
:name => self.name,
:people => self.people.each{|person| person.as_json},
:posts => self.posts.each {|post| post.as_json },
......
......@@ -11,7 +11,7 @@ class Request
xml_accessor :exported_key, :cdata => true
key :person_id, ObjectId
key :group_id, ObjectId
key :aspect_id, ObjectId
key :destination_url, String
key :callback_url, String
key :exported_key, String
......@@ -30,7 +30,7 @@ class Request
:callback_url => person.receive_url,
:person => person,
:exported_key => person.exported_key,
:group_id => options[:into])
:aspect_id => options[:into])
end
def reverse_for accepting_user
......
......@@ -25,7 +25,7 @@ class User
many :pending_requests, :in => :pending_request_ids, :class_name => 'Request'
many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post'
many :groups, :class_name => 'Group'
many :aspects, :class_name => 'Aspect'
before_validation_on_create :setup_person
before_validation :do_bad_things
......@@ -49,26 +49,26 @@ class User
"#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}"
end
######### Groups ######################
def group( opts = {} )
######### Aspects ######################
def aspect( opts = {} )
opts[:user] = self
Group.create(opts)
Aspect.create(opts)
end
def move_friend( opts = {})
return true if opts[:to] == opts[:from]
friend = Person.first(:_id => opts[:friend_id])
if self.friend_ids.include?(friend.id)
from_group = self.group_by_id(opts[:from])
to_group = self.group_by_id(opts[:to])
if from_group && to_group
posts_to_move = from_group.posts.find_all_by_person_id(friend.id)
to_group.people << friend
to_group.posts << posts_to_move
from_group.person_ids.delete(friend.id.to_id)
posts_to_move.each{ |x| from_group.post_ids.delete(x.id)}
from_group.save
to_group.save
from_aspect = self.aspect_by_id(opts[:from])
to_aspect = self.aspect_by_id(opts[:to])
if from_aspect && to_aspect
posts_to_move = from_aspect.posts.find_all_by_person_id(friend.id)
to_aspect.people << friend
to_aspect.posts << posts_to_move
from_aspect.person_ids.delete(friend.id.to_id)
posts_to_move.each{ |x| from_aspect.post_ids.delete(x.id)}
from_aspect.save
to_aspect.save
return true
end
end
......@@ -80,19 +80,19 @@ class User
if class_name == :photo
raise ArgumentError.new("No album_id given") unless options[:album_id]
group_ids = groups_with_post( options[:album_id] )
group_ids.map!{ |group| group.id }
aspect_ids = aspects_with_post( options[:album_id] )
aspect_ids.map!{ |aspect| aspect.id }
else
group_ids = options.delete(:to)
aspect_ids = options.delete(:to)
end
group_ids = [group_ids.to_s] if group_ids.is_a? BSON::ObjectId
raise ArgumentError.new("You must post to someone.") if group_ids.nil? || group_ids.empty?
aspect_ids = [aspect_ids.to_s] if aspect_ids.is_a? BSON::ObjectId
raise ArgumentError.new("You must post to someone.") if aspect_ids.nil? || aspect_ids.empty?
post = build_post(class_name, options)
post.socket_to_uid(id, :group_ids => group_ids) if post.respond_to?(:socket_to_uid)
push_to_groups(post, group_ids)
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid)
push_to_aspects(post, aspect_ids)
post
end
......@@ -107,21 +107,21 @@ class User
post
end
def push_to_groups( post, group_ids )
if group_ids == :all || group_ids == "all"
groups = self.groups
elsif group_ids.is_a?(Array) && group_ids.first.class == Group
groups = group_ids
def push_to_aspects( post, aspect_ids )
if aspect_ids == :all || aspect_ids == "all"
aspects = self.aspects
elsif aspect_ids.is_a?(Array) && aspect_ids.first.class == Aspect
aspects = aspect_ids
else
groups = self.groups.find_all_by_id( group_ids )
aspects = self.aspects.find_all_by_id( aspect_ids )
end
#send to the groups
#send to the aspects
target_people = []
groups.each{ |group|
group.posts << post
group.save
target_people = target_people | group.people
aspects.each{ |aspect|
aspect.posts << post
aspect.save
target_people = target_people | aspect.people
}
push_to_people(post, target_people)
end
......@@ -171,7 +171,7 @@ class User
if owns? comment.post
comment.post_creator_signature = comment.sign_with_key(encryption_key)
comment.save
push_to_people comment, people_in_groups(groups_with_post(comment.post.id))
push_to_people comment, people_in_aspects(aspects_with_post(comment.post.id))
elsif owns? comment
comment.save
salmon comment, :to => comment.post.person
......@@ -180,12 +180,12 @@ class User
######### Posts and Such ###############
def retract( post )
group_ids = groups_with_post( post.id )
group_ids.map!{|group| group.id.to_s}
aspect_ids = aspects_with_post( post.id )
aspect_ids.map!{|aspect| aspect.id.to_s}
post.unsocket_from_uid(self.id, :group_ids => group_ids) if post.respond_to? :unsocket_from_uid
post.unsocket_from_uid(self.id, :aspect_ids => aspect_ids) if post.respond_to? :unsocket_from_uid
retraction = Retraction.for(post)
push_to_people retraction, people_in_groups(groups_with_post(post.id))
push_to_people retraction, people_in_aspects(aspects_with_post(post.id))
retraction
end
......@@ -194,7 +194,7 @@ class User
params[:profile].delete(:image_url) if params[:profile][:image_url].empty?
if self.person.update_attributes(params)
push_to_groups profile, :all
push_to_aspects profile, :all
true
else
false
......@@ -225,9 +225,9 @@ class User
else
object.perform self.id
groups = self.groups_with_person(object.person)
groups.each{ |group| group.post_ids.delete(object.post_id.to_id)
group.save
aspects = self.aspects_with_person(object.person)
aspects.each{ |aspect| aspect.post_ids.delete(object.post_id.to_id)
aspect.save
}
end
elsif object.is_a? Request
......@@ -236,7 +236,7 @@ class User
object.person = person
object.person.save
old_request = Request.first(:id => object.id)
object.group_id = old_request.group_id if old_request
object.aspect_id = old_request.aspect_id if old_request
object.save
receive_friend_request(object)
elsif object.is_a? Profile
......@@ -265,11 +265,11 @@ class User
self.raw_visible_posts << object
self.save
groups = self.groups_with_person(object.person)
groups.each{ |group|
group.posts << object
group.save
object.socket_to_uid(id, :group_ids => [group.id]) if (object.respond_to?(:socket_to_uid) && !self.owns?(object))
aspects = self.aspects_with_person(object.person)
aspects.each{ |aspect|
aspect.posts << object
aspect.save
object.socket_to_uid(id, :aspect_ids => [aspect.id]) if (object.respond_to?(:socket_to_uid) && !self.owns?(object))
}
end
......@@ -310,7 +310,7 @@ class User
:user => {
:posts => self.raw_visible_posts.each{|post| post.as_json},
:friends => self.friends.each {|friend| friend.as_json},
:groups => self.groups.each {|group| group.as_json},
:aspects => self.aspects.each {|aspect| aspect.as_json},
:pending_requests => self.pending_requests.each{|request| request.as_json},
}
}
......
......@@ -8,7 +8,7 @@
= link_to "Albums", albums_path
- content_for :left_pane do
= render "shared/group_friends"
= render "shared/aspect_friends"
%h1.big_text
Albums
......
......@@ -9,7 +9,7 @@
= link_to @album.name, @album
- content_for :left_pane do
= render "shared/group_friends"
= render "shared/aspect_friends"
.album_id{:id => @album.id, :style => "display:hidden;"}
......
%h1 Add a new group
= form_for Group.new do |f|
%h1 Add a new aspect
= form_for Aspect.new do |f|
= f.error_messages
%p
= f.label :name
......
- content_for :head do
= javascript_include_tag 'jquery-ui-1.8.4.custom.min.js'
= javascript_include_tag 'group-edit.js'
= javascript_include_tag 'aspect-edit.js'
- content_for :left_pane do
%h1
......@@ -21,29 +21,29 @@
%ul
%h1{:id => 'group_title'}
Relations
%h1{:id => 'aspect_title'}
Aspects
%ul#group_list
%ul#aspect_list
- for group in @groups
- for aspect in @aspects
%li.group
%h3{:contenteditable => true}= group.name
%li.aspect
%h3{:contenteditable => true}= aspect.name
%ul{:id => group.id}
-if group.people.size < 1
%ul{:id => aspect.id}
-if aspect.people.size < 1
%li.grey Drag to add people
-else
-for person in group.people
-for person in aspect.people
%li.person{:id => person.id, :from_group_id => group.id}
%li.person{:id => person.id, :from_aspect_id => aspect.id}
= person_image_tag(person)
.name
= person.real_name
%p
%br
= link_to 'Update Groups', '#', :class => 'button', :id => "move_friends_link"
= link_to 'Update Aspects', '#', :class => 'button', :id => "move_friends_link"
#content_bottom
......@@ -2,7 +2,7 @@
Home
- content_for :left_pane do
= render "shared/group_friends"
= render "shared/aspect_friends"
%ul#stream
- for post in @posts
......
%h1.big_text
=link_to 'groups', groups_path
=link_to 'aspects', aspects_path
>>
new group
new aspect
= form_for @group do |f|
= form_for @aspect do |f|
= f.error_messages
%p
= f.label :name
......@@ -11,4 +11,4 @@
%p
= f.submit
%p= link_to "Back to List", groups_path
%p= link_to "Back to List", aspects_path
......@@ -2,7 +2,7 @@
Home
- content_for :left_pane do
= render "shared/group_friends"
= render "shared/aspect_friends"
%ul#stream
- for post in @posts
......
......@@ -10,7 +10,7 @@
ws.onmessage = function(evt) {
var obj = jQuery.parseJSON(evt.data);
//console.log(obj);
debug("got a " + obj['class'] + " for groups " + obj['group_ids']);
debug("got a " + obj['class'] + " for aspects " + obj['aspect_ids']);
if (obj['class']=="retractions"){
processRetraction(obj['post_id']);
......@@ -21,7 +21,7 @@
}else if (obj['class']=='photos' && onPageForClass('albums')){
processPhotoInAlbum(obj['photo_hash'])
}else{
processPost(obj['class'], obj['html'], obj['group_ids'])
processPost(obj['class'], obj['html'], obj['aspect_ids'])
}
......@@ -55,8 +55,8 @@
}
}
function processPost(className, html, groupIds){
if(onPageForGroups(groupIds)){
function processPost(className, html, aspectIds){
if(onPageForAspects(aspectIds)){
$("#stream").prepend(
$(html).fadeIn("fast", function(){
$("#stream label:first").inFieldLabels();
......@@ -83,19 +83,19 @@
return (location.href.indexOf(className) != -1 );
}
function onPageForGroups(groupIds){
function onPageForAspects(aspectIds){
if(location.pathname == '/' && onPageOne()){
return true
}
var found = false;
$.each(groupIds, function(index, value) {
if(onPageForGroup(value)){ found = true };
$.each(aspectIds, function(index, value) {
if(onPageForAspect(value)){ found = true };
});
return found;
}
function onPageForGroup(groupId){
return (location.href.indexOf(groupId) != -1 )
function onPageForAspect(aspectId){
return (location.href.indexOf(aspectId) != -1 )
}
function onPageOne() {
......
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