diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ad8aca864..7fa6dc8e8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2708,7 +2708,7 @@ class UsersController < ApplicationController # 资源库 分为全部 课程资源 项目资源 附件 def user_resource # 别人的资源库是没有权限去看的 - if User.current.id.to_i != params[:id].to_i + if User.current.id.to_i != @user.id.to_i render_403 return end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9b19b8c7c..00f29dfe9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,6 +33,19 @@ module ApplicationHelper extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + + def user_path(resource, parameters = {}) + if Fixnum === resource + resource = User.find(resource) + end + super + end + + # def user_blogs_path(resource,parameters={}) + # super + # end + + def update_visiti_count container container.update_column(:visits, container.visits + 1) end diff --git a/app/models/user.rb b/app/models/user.rb index 9b8cb2b8d..2030adfdf 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1072,16 +1072,25 @@ class User < Principal anonymous_user end + def self.is_id?(id) + Fixnum===id || id.to_i.to_s == id + end + # refactor User model find function, # return anonymous user when can not find user id = user_id def self.find (*args, &block) begin + return find_by_login(args.first) if args.size==1 && !is_id?(args.first) super rescue self.anonymous end # super end + + def to_param + login + end # Salts all existing unsalted passwords # It changes password storage scheme from SHA1(password) to SHA1(salt + SHA1(password)) # This method is used in the SaltPasswords migration and is to be kept as is diff --git a/config/routes.rb b/config/routes.rb index df46d342f..989875495 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -522,6 +522,10 @@ RedmineApp::Application.routes.draw do match 'courses/:course_id/news/index', :to => 'news#index', :via => [:get, :post], :as => 'new_course_news' match 'courses/:course_id/news/new', :to => 'news#new', :via => [:get, :post] + scope ":username" do + resources :posts + end + #added by young resources :users do collection do