1、部分代码优化。2、未参加课程或项目的用户个人主页界面不显示对应的tab页

This commit is contained in:
z9hang 2014-10-17 15:02:09 +08:00
parent 2cabec22f2
commit e4ff85894d
10 changed files with 62 additions and 23 deletions

View File

@ -88,3 +88,12 @@ bundle exec rake db:migrate:down VERSION=20140811022947
bundle exec rake db:migrate:up VERSION=20140811022947
bundle exec rake db:migrate
bundle exec rake project_score:calculate
=================================[2014-10-17]====================================
kw:数据迁移web_footer_oranizers表已存在
bundle exec rake db:migrate:down VERSION=20141013014908
bundle exec rake db:migrate:up VERSION=20141013014908
bundle exec rake db:migrate
kw:数据迁移web_footer_companies表已存在
bundle exec rake db:migrate:down VERSION=20141013023400
bundle exec rake db:migrate:up VERSION=20141013023400
bundle exec rake db:migrate

View File

@ -159,7 +159,7 @@ class AdminController < ApplicationController
respond_to do |format|
flash[:notice] = l(:notice_successful_update)
format.html {
redirect_to admin_first_page_made_url
redirect_to first_page_made_url
}
format.api { render_api_ok }
#format.json { render json: @first_page, status: :created, location: @first_page }
@ -194,7 +194,7 @@ class AdminController < ApplicationController
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)
redirect_to admin_course_page_made_url
redirect_to course_page_made_url
}
format.api { render_api_ok }
end
@ -235,7 +235,7 @@ class AdminController < ApplicationController
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)
redirect_to admin_contest_page_made_url
redirect_to contest_page_made_url
}
format.api { render_api_ok }
end
@ -270,7 +270,7 @@ class AdminController < ApplicationController
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)
redirect_to admin_web_footer_made_url
redirect_to web_footer_made_url
}
format.api { render_api_ok }
end

View File

@ -766,7 +766,7 @@ class ApplicationController < ActionController::Base
end
def find_web_footer
@organize = WebFooterOranizer.first
@organizer = WebFooterOranizer.first
@companies = WebFooterCompany.all
end
end

View File

@ -39,9 +39,10 @@ class UsersController < ApplicationController
:user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
:watch_bids, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index]
:activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index]
before_filter :auth_user_extension, only: :show
before_filter :rest_user_score, only: :show
#before_filter :select_entry, only: :user_projects
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
#william
@ -80,6 +81,21 @@ class UsersController < ApplicationController
end
end
def user_projects_index
if User.current.admin?
memberships = @user.memberships.all(conditions: "projects.project_type = #{Project::ProjectType_project}").first
else
cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1"
memberships = @user.memberships.all(:conditions => cond).first
end
watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', @user.id).first
if memberships.nil? && watch_projects
redirect_to(:watch_projects_user) and return
else
redirect_to(:user_projects_user) and return
end
end
#added by young
def user_projects
@ -92,8 +108,6 @@ class UsersController < ApplicationController
#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?)

View File

@ -8,8 +8,9 @@ class ContestingProject < ActiveRecord::Base
DESCRIPTION_LENGTH_LIMIT = 500
validates :description, length: {maximum:DESCRIPTION_LENGTH_LIMIT }
validates :user_id, presence: true
validates :contest_id, presence: true, uniqueness: {:scope => :project_id}
validates :contest_id, presence: true, uniqueness: {scope: :project_id}
validates :project_id, presence: true
validate :validate_user
validate :validate_contest
validate :validate_project

View File

@ -7,14 +7,12 @@
<!--gcm-->
<p>
<%= @organize.description.html_safe unless @organize.nil?%>
<%= @organizer.description.html_safe unless @organizer.nil?%>
</p>
<div id="logo_link">
<% unless @companies.nil?%>
<% @companies.each do |company| %>
<% @companies && @companies.each do |company| %>
<span class="footer_logo_link"><%= link_to image_tag(url_to_avatar(company),:size=>"100x30",:alt=>company.name),company.url, :target => "_blank" %></span>
<% end %>
<% end %>
</div>
<!--gcm-->

View File

@ -274,7 +274,7 @@
<% if @user.user_extensions.identity == 2 %>
<%= render_menu :user_enterprise_menu %>
<% else %>
<%= render_menu :user_menu %>
<%= render_menu :user_menu,@user %>
<% end %>
</div>

View File

@ -241,6 +241,7 @@ RedmineApp::Application.routes.draw do
match "tag_saveEx" , :via => [:get, :post]
end
member do
match 'user_projects_index', :to => 'users#user_projects_index', :via => :get
match 'user_projects', :to => 'users#user_projects', :via => :get
match 'user_activities', :to => 'users#user_activities', :via => :get, :as => "user_activities"
match 'user_newfeedback', :to => 'users#user_newfeedback', :via => :get, :as => "user_newfeedback"
@ -592,10 +593,10 @@ RedmineApp::Application.routes.draw do
match 'admin', :to => 'admin#index', :via => :get
match 'admin/projects', :via => :get
match 'admin/users', :via => :get
match 'admin/first_page_made', :via => [:get,:post]
match 'admin/course_page_made', :via => [:get,:post]
match 'admin/contest_page_made', :via => [:get,:post]
match 'admin/web_footer_made', :via => [:get,:post]
match 'admin/first_page_made', as: :first_page_made
match 'admin/course_page_made', as: :course_page_made
match 'admin/contest_page_made', as: :contest_page_made
match 'admin/web_footer_made', as: :web_footer_made
match 'admin/search', :via => [:get, :post]
match 'admin/plugins', :via => :get
match 'admin/info', :via => :get

View File

@ -415,9 +415,25 @@ Redmine::MenuManager.map :course_menu do |menu|
end
Redmine::MenuManager.map :user_menu do |menu|
menu.push :activity, {:controller => 'users', :action => 'show', :host => Setting.user_domain }
menu.push :user_course, {:controller => 'users', :action => 'user_courses'},:if => Proc.new {|c| FirstPage.find_by_page_type('project').show_course != 2}
menu.push :user_course, {:controller => 'users', :action => 'user_courses'},
:if => Proc.new {|u| if User.current == u || User.current.admin?
membership = u.coursememberships.all
else
membership = u.coursememberships.all(:conditions => Course.visible_condition(User.current))
end
FirstPage.find_by_page_type('project').show_course != 2 && membership && membership.count > 0
}
#menu.push :user_homework, {:controller => 'users', :action => 'user_homeworks'} by huang
menu.push :user_project, {:controller => 'users', :action => 'user_projects', :host => Setting.project_domain}
menu.push :user_project, {:controller => 'users', :action => 'user_projects_index', :host => Setting.project_domain},
:if => Proc.new {|u| if User.current.admin?
memberships = u.memberships.all(conditions: "projects.project_type = #{Project::ProjectType_project}").first
else
cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1"
memberships = u.memberships.all(:conditions => cond).first
end
watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', u.id).first
memberships || watch_projects
}
# menu.push :requirement_focus, {:controller => 'users', :action => 'watch_bids'} by huang
menu.push :user_newfeedback, {:controller => 'users', :action => 'user_newfeedback', :host => Setting.user_domain}

View File

@ -216,7 +216,7 @@ module Redmine
# * Checking the url target (project only)
# * Checking the conditions of the item
def allowed_node?(node, user, project)
if project && user && !user.allowed_to?(node.url, project)
if project && project.is_a?(Project) && user && !user.allowed_to?(node.url, project)
return false
end
if node.condition && !node.condition.call(project)