2013-08-01 10:33:49 +08:00
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
class UsersController < ApplicationController
|
|
|
|
layout 'base_users'
|
2013-08-10 10:25:30 +08:00
|
|
|
#Added by young
|
2013-09-16 08:49:39 +08:00
|
|
|
menu_item :activity
|
2013-08-10 10:25:30 +08:00
|
|
|
menu_item :user_information, :only => :info
|
2013-10-13 15:26:41 +08:00
|
|
|
menu_item :user_course, :only => :user_courses
|
|
|
|
menu_item :user_homework, :only => :user_homeworks
|
2013-10-24 08:24:56 +08:00
|
|
|
menu_item :user_project, :only => [:user_projects, :watch_projects]
|
2013-08-10 10:25:30 +08:00
|
|
|
menu_item :requirement_focus, :only => :watch_bids
|
2013-08-10 10:31:57 +08:00
|
|
|
menu_item :user_newfeedback, :only => :user_newfeedback
|
2013-10-13 15:26:41 +08:00
|
|
|
|
2013-10-12 17:21:50 +08:00
|
|
|
|
2013-08-10 10:25:30 +08:00
|
|
|
#Ended by young
|
2013-08-01 10:33:49 +08:00
|
|
|
|
2013-08-11 10:36:55 +08:00
|
|
|
|
2013-10-24 08:24:56 +08:00
|
|
|
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info,
|
|
|
|
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects]
|
2013-09-23 15:12:06 +08:00
|
|
|
#edit has been deleted by huang, 2013-9-23
|
2013-10-12 17:21:50 +08:00
|
|
|
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :user_homeworks,
|
2013-10-24 08:24:56 +08:00
|
|
|
:destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info,
|
|
|
|
:watch_projects]
|
2013-08-12 14:50:54 +08:00
|
|
|
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save
|
2013-08-08 22:25:32 +08:00
|
|
|
|
|
|
|
#william
|
2013-09-16 08:49:39 +08:00
|
|
|
before_filter :require_login, :only => :tag_save
|
2013-08-01 10:33:49 +08:00
|
|
|
|
2013-08-08 22:26:46 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
helper :sort
|
|
|
|
include SortHelper
|
|
|
|
helper :custom_fields
|
|
|
|
include CustomFieldsHelper
|
|
|
|
include AvatarHelper
|
2013-08-05 22:47:01 +08:00
|
|
|
|
2013-08-08 22:19:15 +08:00
|
|
|
# added by liuping 关注
|
2013-08-05 22:47:01 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
helper :watchers
|
|
|
|
helper :activities
|
|
|
|
|
|
|
|
### added by william
|
|
|
|
include ActsAsTaggableOn::TagsHelper
|
|
|
|
|
|
|
|
# fq
|
|
|
|
helper :words
|
|
|
|
#added by young
|
|
|
|
def user_projects
|
2013-10-02 21:47:18 +08:00
|
|
|
cond = Project.visible_condition(User.current) + "AND projects.project_type <> 1"
|
|
|
|
@memberships = @user.memberships.all(:conditions => cond)
|
2013-08-01 10:33:49 +08:00
|
|
|
|
|
|
|
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20)
|
|
|
|
@events_by_day = events.group_by(&:event_date)
|
2013-10-28 20:09:15 +08:00
|
|
|
@state = 0
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
|
2013-08-08 09:38:54 +08:00
|
|
|
#add by huang
|
2013-08-01 10:33:49 +08:00
|
|
|
unless User.current.admin?
|
2013-08-08 09:38:54 +08:00
|
|
|
if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
|
2013-08-01 10:33:49 +08:00
|
|
|
render_404
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2013-08-08 09:38:54 +08:00
|
|
|
#end
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
2013-08-05 22:47:01 +08:00
|
|
|
|
2013-08-02 08:53:07 +08:00
|
|
|
##added by fq
|
|
|
|
def watch_bids
|
2013-10-12 16:23:25 +08:00
|
|
|
cond = 'bids.reward_type <> 1'
|
|
|
|
@bids = Bid.watched_by(@user).where('reward_type = ?', 1) # added by huang
|
2013-08-12 15:37:42 +08:00
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
@bid_count = @bids.count
|
|
|
|
@bid_pages = Paginator.new @bid_count, @limit, params['page']
|
|
|
|
@offset ||= @bid_pages.reverse_offset
|
|
|
|
unless @offset == 0
|
|
|
|
@bid = @bids.offset(@offset).limit(@limit).all.reverse
|
|
|
|
else
|
|
|
|
limit = @bid_count % @limit
|
|
|
|
@bid = @bids.offset(@offset).limit(limit).all.reverse
|
|
|
|
end
|
|
|
|
|
2013-08-02 08:53:07 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
render :layout => 'base_users'
|
|
|
|
}
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
2013-08-05 22:47:01 +08:00
|
|
|
|
|
|
|
# added by fq
|
2013-08-01 10:33:49 +08:00
|
|
|
def user_activities
|
2013-08-05 22:47:01 +08:00
|
|
|
@watcher = User.watched_by_id(@user)
|
|
|
|
events = []
|
|
|
|
for user in @watcher
|
|
|
|
events << Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 30)
|
|
|
|
end
|
2013-10-31 21:44:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
@events_by_day = events.group_by(&:event_date)
|
|
|
|
|
|
|
|
unless User.current.admin?
|
|
|
|
if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
|
|
|
|
render_404
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
2013-08-05 22:47:01 +08:00
|
|
|
# end
|
2013-09-12 17:19:51 +08:00
|
|
|
|
2013-10-12 17:21:50 +08:00
|
|
|
# added by huang
|
|
|
|
def user_homeworks
|
|
|
|
@membership = @user.memberships.all(:conditions => Project.visible_condition(User.current))
|
|
|
|
@memberships = []
|
|
|
|
@membership.each do |membership|
|
|
|
|
if membership.project.project_type == 1
|
|
|
|
@memberships << membership
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@bid = []
|
|
|
|
@memberships.each do |membership|
|
|
|
|
@bid += membership.project.homeworks
|
|
|
|
end
|
|
|
|
@bid = @bid.group_by {|bid| bid.courses.first.id}
|
|
|
|
#add by huang
|
|
|
|
unless User.current.admin?
|
|
|
|
if !@user.active?
|
|
|
|
render_404
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-17 16:14:35 +08:00
|
|
|
# added by fq, modify by nyan
|
2013-10-12 16:23:25 +08:00
|
|
|
def user_courses
|
2013-10-17 16:14:35 +08:00
|
|
|
@membership = @user.memberships.all(:conditions => Project.visible_condition(User.current))
|
|
|
|
@membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
2013-10-12 16:23:25 +08:00
|
|
|
case params[:type]
|
2013-10-16 10:58:21 +08:00
|
|
|
when "2"
|
|
|
|
#@membership = @user.memberships.all(:conditions => Project.visible_condition(User.current))
|
2013-09-23 08:44:48 +08:00
|
|
|
@memberships = []
|
|
|
|
@membership.each do |membership|
|
2013-10-12 16:23:25 +08:00
|
|
|
if membership.project.project_type == 1
|
|
|
|
@membership << membership
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@state = 2
|
|
|
|
|
2013-09-12 17:19:51 +08:00
|
|
|
when "1"
|
2013-10-16 10:58:21 +08:00
|
|
|
#@membership = @user.memberships.all(:conditions => Project.visible_condition(User.current))
|
2013-09-12 17:19:51 +08:00
|
|
|
@memberships = []
|
|
|
|
@membership.each do |membership|
|
|
|
|
if membership.project.project_type == 1
|
|
|
|
@memberships << membership
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@bid = []
|
|
|
|
@memberships.each do |membership|
|
2013-09-23 08:44:48 +08:00
|
|
|
@bid += membership.project.homeworks
|
2013-09-12 17:19:51 +08:00
|
|
|
end
|
2013-09-18 22:56:01 +08:00
|
|
|
@bid = @bid.group_by {|bid| bid.courses.first.id}
|
2013-09-12 17:19:51 +08:00
|
|
|
@state = 1
|
2013-09-23 08:44:48 +08:00
|
|
|
|
2013-09-12 17:19:51 +08:00
|
|
|
else
|
2013-10-16 10:58:21 +08:00
|
|
|
#@membership = @user.memberships.all(:conditions => Project.visible_condition(User.current))
|
2013-09-12 17:19:51 +08:00
|
|
|
@memberships = []
|
|
|
|
@membership.each do |membership|
|
|
|
|
if membership.project.project_type == 1
|
|
|
|
@memberships << membership
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@state = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
# events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20)
|
|
|
|
# @events_by_day = events.group_by(&:event_date)
|
|
|
|
|
|
|
|
# @state = 0
|
|
|
|
|
|
|
|
#add by huang
|
|
|
|
unless User.current.admin?
|
|
|
|
if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
|
|
|
|
render_404
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
#end
|
|
|
|
|
|
|
|
# respond_to do |format|
|
|
|
|
# format.html
|
|
|
|
# format.api
|
|
|
|
# end
|
|
|
|
end
|
|
|
|
# end
|
2013-08-05 22:47:01 +08:00
|
|
|
|
2013-08-12 15:37:42 +08:00
|
|
|
# modified by fq
|
2013-08-01 10:33:49 +08:00
|
|
|
def user_newfeedback
|
2013-08-12 15:37:42 +08:00
|
|
|
@jours = @user.journals_for_messages.reverse
|
2013-08-25 20:19:44 +08:00
|
|
|
@jours.each do |jour|
|
|
|
|
jour.update_attribute(:status, false)
|
|
|
|
end
|
2013-08-12 15:37:42 +08:00
|
|
|
@limit = 10
|
|
|
|
@feedback_count = @jours.count
|
|
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
|
|
@offset ||= @feedback_pages.offset
|
|
|
|
@jour = @jours[@offset, @limit]
|
2013-08-01 10:33:49 +08:00
|
|
|
@state = false
|
|
|
|
end
|
2013-08-12 15:37:42 +08:00
|
|
|
# end
|
2013-08-05 22:47:01 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
def user_comments
|
2013-08-05 22:47:01 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
2013-08-05 22:47:01 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
#end
|
|
|
|
def index
|
2013-10-31 15:18:42 +08:00
|
|
|
|
2013-09-29 19:46:59 +08:00
|
|
|
@project_type = params[:project_type]
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
sort_init 'login', 'asc'
|
|
|
|
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
|
|
|
|
|
|
|
case params[:format]
|
|
|
|
when 'xml', 'json'
|
2013-08-15 10:29:15 +08:00
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 15})
|
2013-08-01 10:33:49 +08:00
|
|
|
else
|
2013-10-12 16:23:25 +08:00
|
|
|
@limit = 15#per_page_option
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
@status = params[:status] || 1
|
|
|
|
has = {
|
|
|
|
"show_changesets" => true
|
|
|
|
}
|
|
|
|
# @count = Redmine::Activity::Fetcher.new(User.current, :author => @user).scope_select {|t| !has["show_#{t}"].nil?}.events(nil, nil).count
|
2013-09-12 10:41:15 +08:00
|
|
|
|
|
|
|
scope = UserStatus.visible
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
scope = scope.in_group(params[:group_id]) if params[:group_id].present?
|
2013-09-12 10:41:15 +08:00
|
|
|
# scope.each do |user|
|
|
|
|
# UserStatus.create(:changesets_count => user.changesets.count, :watchers_count => user.watcher_users.count, :user_id => user.id)
|
|
|
|
# end
|
2013-08-01 10:33:49 +08:00
|
|
|
@user_count = scope.count
|
|
|
|
@user_pages = Paginator.new @user_count, @limit, params['page']
|
2013-09-12 10:41:15 +08:00
|
|
|
#@offset ||= @user_pages.offset
|
|
|
|
#@users = scope.order(sort_clause).limit(@limit).offset(@offset).all
|
2013-10-17 16:14:35 +08:00
|
|
|
@user_base_tag = params[:id] ? 'base_users':'base'
|
2013-09-12 10:41:15 +08:00
|
|
|
if params[:user_sort_type].present?
|
|
|
|
case params[:user_sort_type]
|
|
|
|
when '0'
|
|
|
|
@offset ||= @user_pages.reverse_offset
|
|
|
|
unless @offset == 0
|
|
|
|
@users_statuses = scope.offset(@offset).limit(@limit).all.reverse
|
|
|
|
else
|
|
|
|
limit = @user_count % @limit
|
|
|
|
if limit == 0
|
|
|
|
limit = @limit
|
|
|
|
end
|
|
|
|
@users_statuses = scope.offset(@offset).limit(limit).all.reverse
|
|
|
|
end
|
|
|
|
@s_type = 0
|
|
|
|
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
|
|
|
|
# @projects = @projects[@offset, @limit]
|
|
|
|
when '1'
|
|
|
|
@offset ||= @user_pages.reverse_offset
|
|
|
|
unless @offset == 0
|
2013-10-21 09:42:09 +08:00
|
|
|
@users_statuses = scope.reorder('grade').offset(@offset).limit(@limit).all.reverse
|
2013-09-12 10:41:15 +08:00
|
|
|
else
|
|
|
|
limit = @user_count % @limit
|
|
|
|
if limit == 0
|
|
|
|
limit = @limit
|
|
|
|
end
|
2013-10-21 09:42:09 +08:00
|
|
|
@users_statuses = scope.reorder('grade').offset(@offset).limit(limit).all.reverse
|
2013-09-12 10:41:15 +08:00
|
|
|
end
|
|
|
|
@s_type = 1
|
|
|
|
#sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count}
|
|
|
|
#@users = @users[@offset, @limit]
|
|
|
|
when '2'
|
|
|
|
@offset ||= @user_pages.reverse_offset
|
|
|
|
unless @offset == 0
|
|
|
|
@users_statuses = scope.reorder('watchers_count').offset(@offset).limit(@limit).all.reverse
|
|
|
|
else
|
|
|
|
limit = @user_count % @limit
|
|
|
|
if limit == 0
|
|
|
|
limit = @limit
|
|
|
|
end
|
|
|
|
@users_statuses = scope.reorder('watchers_count').offset(@offset).limit(limit).all.reverse
|
|
|
|
end
|
|
|
|
@s_type = 2
|
|
|
|
#@users = @users[@offset, @limit]
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
@offset ||= @user_pages.reverse_offset
|
|
|
|
unless @offset == 0
|
2013-10-28 08:51:15 +08:00
|
|
|
@users_statuses = scope.reorder('grade').offset(@offset).limit(@limit).all.reverse
|
2013-09-12 10:41:15 +08:00
|
|
|
else
|
|
|
|
limit = @user_count % @limit
|
|
|
|
if limit == 0
|
|
|
|
limit = @limit
|
|
|
|
end
|
2013-10-28 08:51:15 +08:00
|
|
|
@users_statuses = scope.reorder('grade').offset(@offset).limit(limit).all.reverse
|
2013-09-12 10:41:15 +08:00
|
|
|
end
|
|
|
|
@s_type = 1
|
|
|
|
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
|
|
|
|
# @projects = @projects[@offset, @limit]
|
|
|
|
end
|
|
|
|
|
|
|
|
@users = []
|
|
|
|
@users_statuses.each do |obj|
|
|
|
|
@users << User.find_by_id("#{obj.user_id}")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
@groups = Group.all.sort
|
|
|
|
render :layout => @user_base_tag
|
|
|
|
}
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
2013-09-12 10:41:15 +08:00
|
|
|
|
|
|
|
def search
|
|
|
|
sort_init 'login', 'asc'
|
|
|
|
sort_update %w(login firstname lastname mail admin created_on last_login_on)
|
|
|
|
|
|
|
|
case params[:format]
|
|
|
|
when 'xml', 'json'
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 15})
|
|
|
|
else
|
|
|
|
@limit = 15#per_page_option
|
|
|
|
end
|
|
|
|
|
|
|
|
@status = params[:status] || 1
|
|
|
|
has = {
|
|
|
|
"show_changesets" => true
|
|
|
|
}
|
|
|
|
scope = User.logged.status(@status)
|
|
|
|
scope = scope.like(params[:name]) if params[:name].present?
|
|
|
|
@user_count = scope.count
|
|
|
|
@user_pages = Paginator.new @user_count, @limit, params['page']
|
2013-10-17 16:14:35 +08:00
|
|
|
@user_base_tag = params[:id] ? 'base_users':'base'
|
2013-09-12 10:41:15 +08:00
|
|
|
@offset ||= @user_pages.reverse_offset
|
|
|
|
unless @offset == 0
|
|
|
|
@users = scope.offset(@offset).limit(@limit).all.reverse
|
|
|
|
else
|
|
|
|
limit = @user_count % @limit
|
|
|
|
if limit == 0
|
|
|
|
limit = @limit
|
|
|
|
end
|
|
|
|
@users = scope.offset(@offset).limit(limit).all.reverse
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
@groups = Group.all.sort
|
|
|
|
render :layout => @user_base_tag
|
|
|
|
}
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
def show
|
2013-09-12 10:41:15 +08:00
|
|
|
case params[:type]
|
|
|
|
when "1"
|
|
|
|
if @user == User.current
|
|
|
|
activity = Activity.where('user_id = ?', User.current.id).order('id desc')
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
@activity_count = activity.count
|
|
|
|
@activity_pages = Paginator.new @activity_count, @limit, params['page']
|
|
|
|
@offset ||= @activity_pages.offset
|
|
|
|
@activity = activity.offset(@offset).limit(@limit)
|
|
|
|
@state = 1
|
|
|
|
end
|
|
|
|
when "2"
|
|
|
|
message = []
|
|
|
|
if @user == User.current
|
|
|
|
message = JournalsForMessage.reference_message(@user.id)
|
|
|
|
message += Journal.reference_message(@user.id)
|
|
|
|
end
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
@activity_count = message.size
|
|
|
|
@info_pages = Paginator.new @activity_count, @limit, params['page']
|
|
|
|
@offset ||= @info_pages.offset
|
|
|
|
|
|
|
|
messages = message.sort {|x,y| y.created_on <=> x.created_on }
|
|
|
|
|
|
|
|
@message = messages[@offset, @limit]
|
|
|
|
@state = 2
|
|
|
|
else
|
|
|
|
if @user == User.current
|
2013-08-12 21:39:58 +08:00
|
|
|
watcher = User.watched_by(@user)
|
|
|
|
watcher.push(User.current)
|
|
|
|
activity = Activity.where('user_id in (?)', watcher).order('id desc')
|
2013-09-12 10:41:15 +08:00
|
|
|
else
|
2013-08-12 21:39:58 +08:00
|
|
|
activity = Activity.where('user_id = ?', @user.id).order('id desc')
|
2013-09-12 10:41:15 +08:00
|
|
|
end
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
@activity_count = activity.count
|
|
|
|
@activity_pages = Paginator.new @activity_count, @limit, params['page']
|
|
|
|
@offset ||= @activity_pages.offset
|
|
|
|
@activity = activity.offset(@offset).limit(@limit)
|
|
|
|
@state = 0
|
2013-08-12 21:39:58 +08:00
|
|
|
end
|
2013-09-12 10:41:15 +08:00
|
|
|
|
2013-10-31 21:44:10 +08:00
|
|
|
if params[:user].present?
|
2013-11-01 10:48:02 +08:00
|
|
|
|
2013-11-09 09:26:02 +08:00
|
|
|
user_temp = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:user]}%' or lastname like '%#{params[:user]}%'")
|
2013-11-01 10:48:02 +08:00
|
|
|
|
2013-10-31 21:44:10 +08:00
|
|
|
if user_temp.size > 1
|
2013-11-01 10:48:02 +08:00
|
|
|
activity = Activity.where('user_id in (?)', user_temp).where('user_id in (?)', watcher).order('id desc')
|
2013-10-31 21:44:10 +08:00
|
|
|
elsif user_temp.size == 1
|
2013-11-01 10:48:02 +08:00
|
|
|
activity = Activity.where('user_id = ?', user_temp).where('user_id in (?)', watcher).order('id desc')
|
2013-10-31 21:44:10 +08:00
|
|
|
else
|
|
|
|
activity = Activity.where("1 = 0")
|
|
|
|
end
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
@activity_count = activity.count
|
|
|
|
@activity_pages = Paginator.new @activity_count, @limit, params['page']
|
|
|
|
@offset ||= @activity_pages.offset
|
|
|
|
@activity = activity.offset(@offset).limit(@limit)
|
|
|
|
@state = 0
|
|
|
|
end
|
|
|
|
|
2013-08-08 10:04:44 +08:00
|
|
|
|
2013-08-06 22:23:22 +08:00
|
|
|
#Modified by nie
|
2013-08-01 10:33:49 +08:00
|
|
|
unless User.current.admin?
|
2013-08-06 22:23:22 +08:00
|
|
|
if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
|
|
|
|
# redirect_to home_path
|
2013-08-01 10:33:49 +08:00
|
|
|
render_404
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-05 22:47:01 +08:00
|
|
|
##end fq
|
|
|
|
|
2013-08-06 22:26:52 +08:00
|
|
|
#### added by fq
|
|
|
|
def info
|
2013-08-11 10:36:55 +08:00
|
|
|
|
|
|
|
message = []
|
2013-09-12 10:41:15 +08:00
|
|
|
if @user == User.current
|
2013-08-11 10:36:55 +08:00
|
|
|
message = JournalsForMessage.reference_message(@user.id)
|
2013-09-12 10:41:15 +08:00
|
|
|
message += Journal.reference_message(@user.id)
|
|
|
|
end
|
2013-08-11 10:36:55 +08:00
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
@info_count = message.size
|
|
|
|
@info_pages = Paginator.new @info_count, @limit, params['page']
|
|
|
|
@offset ||= @info_pages.offset
|
|
|
|
|
|
|
|
messages = message.sort {|x,y| y.created_on <=> x.created_on }
|
|
|
|
|
|
|
|
@message = messages[@offset, @limit]
|
2013-08-06 22:26:52 +08:00
|
|
|
|
|
|
|
unless User.current.admin?
|
|
|
|
if !@user.active?
|
|
|
|
render_404
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
|
|
|
#### end
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
def new
|
|
|
|
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
|
|
|
|
@auth_sources = AuthSource.all
|
2013-08-13 10:43:52 +08:00
|
|
|
render :layout => "base"
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
|
|
|
|
@user.safe_attributes = params[:user]
|
|
|
|
@user.admin = params[:user][:admin] || false
|
|
|
|
@user.login = params[:user][:login]
|
|
|
|
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
|
|
|
|
|
|
|
|
if @user.save
|
|
|
|
@user.pref.attributes = params[:pref]
|
|
|
|
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
|
|
|
@user.pref.save
|
|
|
|
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
|
|
|
|
|
|
|
|
Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information]
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user)))
|
|
|
|
if params[:continue]
|
|
|
|
redirect_to new_user_path
|
|
|
|
else
|
|
|
|
redirect_to edit_user_path(@user)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@auth_sources = AuthSource.all
|
|
|
|
# Clear password input
|
|
|
|
@user.password = @user.password_confirmation = nil
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :action => 'new' }
|
|
|
|
format.api { render_validation_errors(@user) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@auth_sources = AuthSource.all
|
|
|
|
@membership ||= Member.new
|
|
|
|
end
|
2013-10-24 08:24:56 +08:00
|
|
|
|
|
|
|
def watch_projects
|
2013-11-07 17:04:37 +08:00
|
|
|
@watch_type = Watcher.where("watchable_type = ? and user_id = ?", 'Project', @user.id)
|
|
|
|
#@project = Project.visible.where("project_type < ?", 1)
|
2013-10-24 10:13:00 +08:00
|
|
|
@watch_projects = []
|
|
|
|
unless @watch_type.nil?
|
|
|
|
@watch_type.each do |obj|
|
|
|
|
@watch_projects << Project.find(obj.watchable_id)
|
|
|
|
end
|
|
|
|
end
|
2013-10-28 20:09:15 +08:00
|
|
|
@state = 1
|
2013-10-24 10:13:00 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
render :layout => 'base_users'
|
|
|
|
}
|
|
|
|
format.api
|
|
|
|
end
|
2013-10-24 08:24:56 +08:00
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
|
|
|
|
def update
|
|
|
|
@user.admin = params[:user][:admin] if params[:user][:admin]
|
|
|
|
@user.login = params[:user][:login] if params[:user][:login]
|
|
|
|
if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
|
|
|
|
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
|
|
|
|
end
|
|
|
|
@user.safe_attributes = params[:user]
|
|
|
|
# Was the account actived ? (do it before User#save clears the change)
|
|
|
|
was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
|
|
|
|
# TODO: Similar to My#account
|
|
|
|
@user.pref.attributes = params[:pref]
|
|
|
|
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
|
|
|
|
|
|
|
if @user.save
|
|
|
|
@user.pref.save
|
|
|
|
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
|
|
|
|
|
|
|
|
if was_activated
|
|
|
|
Mailer.account_activated(@user).deliver
|
|
|
|
elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil?
|
|
|
|
Mailer.account_information(@user, params[:user][:password]).deliver
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_successful_update)
|
|
|
|
redirect_to_referer_or edit_user_path(@user)
|
|
|
|
}
|
|
|
|
format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@auth_sources = AuthSource.all
|
|
|
|
@membership ||= Member.new
|
|
|
|
# Clear password input
|
|
|
|
@user.password = @user.password_confirmation = nil
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :action => :edit }
|
|
|
|
format.api { render_validation_errors(@user) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@user.destroy
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_back_or_default(users_path) }
|
|
|
|
format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit_membership
|
|
|
|
@membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
|
|
|
|
@membership.save
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_membership
|
|
|
|
@membership = Member.find(params[:membership_id])
|
|
|
|
if @membership.deletable?
|
|
|
|
@membership.destroy
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
################# added by william
|
|
|
|
def tag_save
|
|
|
|
@tags = params[:tag_for_save][:name]
|
|
|
|
@obj_id = params[:tag_for_save][:object_id]
|
|
|
|
@obj_flag = params[:tag_for_save][:object_flag]
|
|
|
|
|
|
|
|
case @obj_flag
|
|
|
|
when '1' then
|
|
|
|
@obj = User.find_by_id(@obj_id)
|
|
|
|
when '2' then
|
|
|
|
@obj = Project.find_by_id(@obj_id)
|
|
|
|
when '3' then
|
|
|
|
@obj = Issue.find_by_id(@obj_id)
|
2013-08-01 21:36:37 +08:00
|
|
|
when '4' then
|
|
|
|
@obj = Bid.find_by_id(@obj_id)
|
2013-08-01 10:33:49 +08:00
|
|
|
else
|
|
|
|
@obj = nil
|
|
|
|
end
|
|
|
|
unless @obj.nil?
|
|
|
|
@obj.tag_list.add(@tags.split(","))
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if @obj.save
|
|
|
|
## 执行成功的操作。
|
|
|
|
else
|
|
|
|
#捕获异常
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.js
|
2013-08-08 22:19:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
###add by huang
|
2013-08-11 15:27:34 +08:00
|
|
|
def user_watchlist
|
2013-08-08 22:19:15 +08:00
|
|
|
end
|
|
|
|
###add by huang
|
2013-08-11 21:09:12 +08:00
|
|
|
def user_fanslist
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
2013-08-14 21:37:55 +08:00
|
|
|
|
|
|
|
#william
|
|
|
|
def update_extensions(user_extensions)
|
|
|
|
user_extensions = params[:user_extensions]
|
|
|
|
unless user_extensions.nil?
|
|
|
|
user_extensions = UserExtensions.find_by_id(user_extensions.user_id)
|
|
|
|
|
|
|
|
# user_extensions.
|
|
|
|
end
|
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
|
2013-08-14 21:37:55 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def find_user
|
|
|
|
if params[:id] == 'current'
|
|
|
|
require_login || return
|
|
|
|
@user = User.current
|
|
|
|
else
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
end
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|