This repository has been archived by the owner on Nov 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from shimomura1004/id/170
change profile settings for each rooms Id/170
- Loading branch information
Showing
15 changed files
with
275 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class UserProfile | ||
include Mongoid::Document | ||
include Mongoid::Timestamps | ||
field :room_id | ||
field :name | ||
field :profile_image_url | ||
embedded_in :User, :inverse_of => :user_profiles | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
as_profile_setting | ||
=================== | ||
|
||
Overview | ||
---------------- | ||
|
||
as_profile_setting is a plugin of AsakusaSatellite that enables users | ||
to change their name and icon. | ||
|
||
Install | ||
---------------- | ||
|
||
Put this plugin into plugins directory of your AsakusaSatellite |
32 changes: 32 additions & 0 deletions
32
plugins/as_profile_setting/app/controllers/profile_setting_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- encoding: utf-8 -*- | ||
class ProfileSettingController < ApplicationController | ||
def update | ||
unless logged? | ||
redirect_to :controller => 'chat', :action => 'index' | ||
return | ||
end | ||
update_profile(params["account"], params["room"]["id"]) | ||
redirect_to :controller => 'account' | ||
end | ||
|
||
private | ||
def update_profile(profile_info, room_id) | ||
user = User.first(:conditions => {:_id => current_user.id}) | ||
user.user_profiles ||= [] | ||
|
||
room = Room.where(:_id => room_id)[0] | ||
return if room.nil? | ||
|
||
if user.user_profiles.where(:room_id => room._id).empty? | ||
user.user_profiles << UserProfile.new(:room_id => room._id, | ||
:name => profile_info["name"], | ||
:profile_image_url => profile_info["image_url"]) | ||
else | ||
profile = user.user_profiles.where(:room_id => room._id).first | ||
profile.update_attributes(:profile_image_url => profile_info["image_url"]) | ||
profile.update_attributes(:name => profile_info["name"]) | ||
end | ||
|
||
user.save | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
plugins/as_profile_setting/app/views/account/_input.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
=form_for :account, :url => {:controller => :profile_setting, :action => :update} do |form| | ||
=hidden_field :room, :id, {:value => room.id} | ||
%div | ||
%h4 #{room.title} | ||
%div | ||
- room.owner_and_members.each do |user| | ||
= image_tag(user.profile_for(room.id)[:profile_image_url], :title => user.screen_name, :class => "profile") | ||
|
||
%div | ||
%div{:style => "float: left; width: 10%;"} | ||
=image_tag(current_user.profile_for(room.id)[:profile_image_url], :title => current_user.screen_name, :style => "width: 100%;") | ||
%div{:style => "margin-left: 10%; width: 90%;"} | ||
|
||
%div | ||
%div{:style => "float: left; width: 50px;"} | ||
%span Icon | ||
%div{:style => "margin-left: 80px;"} | ||
=text_field :account, :image_url, :class => :text, :value => current_user.profile_for(room.id)[:profile_image_url], :style => "width: 100%; margin-left: 0px;" | ||
|
||
%div | ||
%div{:style => "float: left; width: 50px;"} | ||
%span Name | ||
%div{:style => "margin-left: 80px;"} | ||
= text_field :account, :name, :class => :text, :value => current_user.profile_for(room.id)[:name], :style => "width: 100%; margin-left: 0px;" | ||
|
||
=submit_tag "Update", :class => "submit red button large" |
15 changes: 15 additions & 0 deletions
15
plugins/as_profile_setting/app/views/account/_profile_setting.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
%fieldset | ||
%legend Your Profile | ||
%div | ||
%h3 Default Profile | ||
%img{:src => current_user.profile_image_url} | ||
%span #{current_user.name} | ||
|
||
%div{:style => "margin-bottom: 50px;"} | ||
%h3 Private Rooms | ||
- (@rooms[:owner_rooms] + @rooms[:member_rooms]).each do |room| | ||
= render :partial => "input", :locals => {:room => room} | ||
%div{:style => "margin-bottom: 50px;"} | ||
%h3 Public Rooms | ||
- @rooms[:public_rooms].each do |room| | ||
= render :partial => "input", :locals => {:room => room} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
AsakusaSatellite::Application.routes.draw do | ||
post 'profile_setting/update' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'profile_setting_listener' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class ProfileSettingListener < AsakusaSatellite::Hook::Listener | ||
render_on :account_setting_item, :partial => "profile_setting" | ||
end | ||
|
133 changes: 133 additions & 0 deletions
133
plugins/as_profile_setting/spec/controllers/profile_setting_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# -*- coding: utf-8 -*- | ||
require File.dirname(__FILE__) + '/../../../../spec/spec_helper' | ||
|
||
describe ProfileSettingController do | ||
before do | ||
@user = User.new(:profile_image_url => "http://example.com/profile.png").tap{|u| u.save! } | ||
@room1 = Room.new(:title => 'test1').tap{|r| r.save! } | ||
@room2 = Room.new(:title => 'test2').tap{|r| r.save! } | ||
end | ||
|
||
describe "ログインしていない場合はエラーになる" do | ||
before { put :update } | ||
subject { response } | ||
it { | ||
should redirect_to :controller => 'chat', :action => 'index' | ||
} | ||
end | ||
|
||
describe "1つめのプロファイル追加" do | ||
before do | ||
session[:current_user_id] = @user.id | ||
put(:update, | ||
:room => {"id" => @room1._id}, | ||
:account => { "name" => "user1", "image_url" => "http://example.com/pic1.jpg" }) | ||
end | ||
|
||
describe "プロファイルを追加する" do | ||
before { @modified_user = User.where(:_id => @user._id).first } | ||
|
||
describe "成功する" do | ||
subject { response } | ||
it { | ||
should redirect_to :controller => 'account' | ||
} | ||
end | ||
|
||
describe "新規作成される" do | ||
subject { @modified_user.user_profiles } | ||
it { should have_exactly(1).items } | ||
end | ||
|
||
describe "値が正しく設定される" do | ||
subject { @modified_user.user_profiles[0] } | ||
its(:name) { should == "user1" } | ||
its(:profile_image_url) { should == "http://example.com/pic1.jpg" } | ||
its(:room_id) { should == @room1._id } | ||
end | ||
|
||
describe "デフォルトのプロファイルは変更されない" do | ||
subject { @modified_user } | ||
its(:name) { should == @user.name } | ||
its(:profile_image_url) { should == @user.profile_image_url } | ||
end | ||
|
||
|
||
describe "2つめのプロファイルを追加する" do | ||
before { | ||
session[:current_user_id] = @user.id | ||
put(:update, | ||
:room => {"id" => @room2._id}, | ||
:account => { "name" => "user2", "image_url" => "http://example.com/pic2.jpg" }) | ||
} | ||
|
||
describe "プロファイルを追加する" do | ||
before { @modified_user = User.where(:_id => @user._id).first } | ||
|
||
describe "成功する" do | ||
subject { response } | ||
it { | ||
should redirect_to :controller => 'account' | ||
} | ||
end | ||
|
||
describe "新規作成される" do | ||
subject { @modified_user.user_profiles } | ||
it { should have_exactly(2).items } | ||
end | ||
|
||
describe "値が正しく設定される" do | ||
subject { @modified_user.user_profiles[1] } | ||
its(:name) { should == "user2" } | ||
its(:profile_image_url) { should == "http://example.com/pic2.jpg" } | ||
its(:room_id) { should == @room2._id } | ||
end | ||
|
||
describe "1つめのプロファイルは変更されない" do | ||
subject { @modified_user.user_profiles[0] } | ||
its(:name) { should == "user1" } | ||
its(:profile_image_url) { should == "http://example.com/pic1.jpg" } | ||
end | ||
|
||
describe "1つめのプロファイルを変更する" do | ||
before { | ||
session[:current_user_id] = @user.id | ||
put(:update, | ||
:room => {"id" => @room1._id}, | ||
:account => { "name" => "user3", "image_url" => "http://example.com/pic3.jpg" }) | ||
} | ||
|
||
describe "プロファイルを追加する" do | ||
before { @modified_user = User.where(:_id => @user._id).first } | ||
|
||
describe "成功する" do | ||
subject { response } | ||
it { | ||
should redirect_to :controller => 'account' | ||
} | ||
end | ||
|
||
describe "新規作成されない" do | ||
subject { @modified_user.user_profiles } | ||
it { should have_exactly(2).items } | ||
end | ||
|
||
describe "値が正しく更新される" do | ||
subject { @modified_user.user_profiles[0] } | ||
its(:name) { should == "user3" } | ||
its(:profile_image_url) { should == "http://example.com/pic3.jpg" } | ||
its(:room_id) { should == @room1._id } | ||
end | ||
|
||
describe "2つめのプロファイルは変更されない" do | ||
subject { @modified_user.user_profiles[1] } | ||
its(:name) { should == "user2" } | ||
its(:profile_image_url) { should == "http://example.com/pic2.jpg" } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters