Commit f37089f5 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

v0.2.0

git-svn-id: http://redmine.rubyforge.org/svn/trunk@7 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 366ca57c
......@@ -16,31 +16,30 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class AccountController < ApplicationController
layout 'base'
layout 'base'
# prevents login action to be filtered by check_if_login_required application scope filter
skip_before_filter :check_if_login_required, :only => :login
before_filter :require_login, :except => [:show, :login]
before_filter :require_login, :except => [:show, :login]
def show
@user = User.find(params[:id])
end
# Login request and validation
def login
if request.get?
session[:user] = nil
@user = User.new
else
@user = User.new(params[:user])
logged_in_user = @user.try_to_login
if logged_in_user
session[:user] = logged_in_user
redirect_back_or_default :controller => 'account', :action => 'my_page'
else
flash[:notice] = _('Invalid user/password')
end
end
end
def show
@user = User.find(params[:id])
end
# Login request and validation
def login
if request.get?
session[:user] = nil
else
logged_in_user = User.try_to_login(params[:login], params[:password])
if logged_in_user
session[:user] = logged_in_user
redirect_back_or_default :controller => 'account', :action => 'my_page'
else
flash[:notice] = _('Invalid user/password')
end
end
end
# Log out current user and redirect to welcome page
def logout
......@@ -64,20 +63,15 @@ class AccountController < ApplicationController
end
end
# Change current user's password
def change_password
@user = User.find(session[:user].id)
if @user.check_password?(@params[:old_password])
if @params[:new_password] == @params[:new_password_confirmation]
if @user.change_password(@params[:old_password], @params[:new_password])
flash[:notice] = 'Password was successfully updated.'
end
else
flash[:notice] = 'Password confirmation doesn\'t match!'
end
else
flash[:notice] = 'Wrong password'
end
render :action => 'my_account'
end
# Change current user's password
def change_password
@user = User.find(session[:user].id)
if @user.check_password?(@params[:password])
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
flash[:notice] = 'Password was successfully updated.' if @user.save
else
flash[:notice] = 'Wrong password'
end
render :action => 'my_account'
end
end
......@@ -16,26 +16,32 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class AdminController < ApplicationController
layout 'base'
before_filter :require_admin
helper :sort
include SortHelper
layout 'base'
before_filter :require_admin
helper :sort
include SortHelper
def index
end
def index
end
def projects
sort_init 'projects.name', 'asc'
sort_update
@project_pages, @projects = paginate :projects, :per_page => 15, :order => sort_clause
sort_init 'name', 'asc'
sort_update
@project_count = Project.count
@project_pages = Paginator.new self, @project_count,
15,
@params['page']
@projects = Project.find :all, :order => sort_clause,
:limit => @project_pages.items_per_page,
:offset => @project_pages.current.offset
end
def mail_options
@actions = Permission.find(:all, :conditions => ["mail_option=?", true]) || []
@actions = Permission.find(:all, :conditions => ["mail_option=?", true]) || []
if request.post?
@actions.each { |a|
a.mail_enabled = params[:action_ids].include? a.id.to_s
a.mail_enabled = (params[:action_ids] || []).include? a.id.to_s
a.save
}
flash[:notice] = "Mail options were successfully updated."
......@@ -44,6 +50,5 @@ class AdminController < ApplicationController
def info
@adapter_name = ActiveRecord::Base.connection.adapter_name
end
end
end
......@@ -24,63 +24,73 @@ class ApplicationController < ActionController::Base
end
def set_localization
Localization.lang = session[:user].nil? ? RDM_DEFAULT_LANG : (session[:user].language || RDM_DEFAULT_LANG)
Localization.lang = begin
if session[:user]
session[:user].language
elsif request.env['HTTP_ACCEPT_LANGUAGE']
accept_lang = HTTPUtils.parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first
if Localization.langs.collect{ |l| l[1] }.include? accept_lang
accept_lang
end
end
rescue
nil
end || RDM_DEFAULT_LANG
end
def require_login
unless session[:user]
store_location
redirect_to(:controller => "account", :action => "login")
end
end
def require_login
unless session[:user]
store_location
redirect_to(:controller => "account", :action => "login")
end
end
def require_admin
if session[:user].nil?
store_location
redirect_to(:controller => "account", :action => "login")
else
unless session[:user].admin?
flash[:notice] = "Acces not allowed"
redirect_to(:controller => "projects", :action => "list")
end
end
end
def require_admin
if session[:user].nil?
store_location
redirect_to(:controller => "account", :action => "login")
else
unless session[:user].admin?
flash[:notice] = "Acces not allowed"
redirect_to(:controller => "projects", :action => "list")
end
end
end
# authorizes the user for the requested action.
def authorize
# authorizes the user for the requested action.
def authorize
# check if action is allowed on public projects
if @project.public? and Permission.allowed_to_public "%s/%s" % [ @params[:controller], @params[:action] ]
if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ @params[:controller], @params[:action] ]
return true
end
# if user is not logged in, he is redirect to login form
unless session[:user]
store_location
redirect_to(:controller => "account", :action => "login")
return false
end
# check if user is authorized
# if user not logged in, redirect to login form
unless session[:user]
store_location
redirect_to(:controller => "account", :action => "login")
return false
end
# if logged in, check if authorized
if session[:user].admin? or Permission.allowed_to_role( "%s/%s" % [ @params[:controller], @params[:action] ], session[:user].role_for_project(@project.id) )
return true
end
end
flash[:notice] = "Acces denied"
redirect_to(:controller => "")
return false
end
false
end
# store current uri in the session.
# we can return to this location by calling redirect_back_or_default
def store_location
session[:return_to] = @request.request_uri
end
# move to the last store_location call or to the passed default one
def redirect_back_or_default(default)
if session[:return_to].nil?
redirect_to default
else
redirect_to_url session[:return_to]
session[:return_to] = nil
end
end
# store current uri in session.
# return to this location by calling redirect_back_or_default
def store_location
session[:return_to] = @request.request_uri
end
# move to the last store_location call or to the passed default one
def redirect_back_or_default(default)
if session[:return_to].nil?
redirect_to default
else
redirect_to_url session[:return_to]
session[:return_to] = nil
end
end
end
\ No newline at end of file
......@@ -16,28 +16,32 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class HelpController < ApplicationController
skip_before_filter :check_if_login_required
before_filter :load_help_config
before_filter :load_help_config
def index
if @params[:ctrl] and @help_config[@params[:ctrl]]
if @params[:page] and @help_config[@params[:ctrl]][@params[:page]]
template = @help_config[@params[:ctrl]][@params[:page]]
else
template = @help_config[@params[:ctrl]]['index']
end
end
# displays help page for the requested controller/action
def index
# select help page to display
if @params[:ctrl] and @help_config['pages'][@params[:ctrl]]
if @params[:page] and @help_config['pages'][@params[:ctrl]][@params[:page]]
template = @help_config['pages'][@params[:ctrl]][@params[:page]]
else
template = @help_config['pages'][@params[:ctrl]]['index']
end
end
# choose language according to available help translations
lang = (@help_config['langs'].include? Localization.lang) ? Localization.lang : @help_config['langs'].first
if template
redirect_to "/manual/#{template}"
redirect_to "/manual/#{lang}/#{template}"
else
redirect_to "/manual/"
redirect_to "/manual/#{lang}/"
end
end
end
private
def load_help_config
@help_config = YAML::load(File.open("#{RAILS_ROOT}/config/help.yml"))
end
def load_help_config
@help_config = YAML::load(File.open("#{RAILS_ROOT}/config/help.yml"))
end
end
......@@ -32,58 +32,62 @@ class ProjectsController < ApplicationController
render :action => 'list'
end
# Lists public projects
def list
sort_init 'projects.name', 'asc'
sort_update
@project_count = Project.count(["public=?", true])
@project_pages = Paginator.new self, @project_count,
# Lists public projects
def list
sort_init 'name', 'asc'
sort_update
@project_count = Project.count(["is_public=?", true])
@project_pages = Paginator.new self, @project_count,
15,
@params['page']
@projects = Project.find :all, :order => sort_clause,
:conditions => ["public=?", true],
@projects = Project.find :all, :order => sort_clause,
:conditions => ["is_public=?", true],
:limit => @project_pages.items_per_page,
:offset => @project_pages.current.offset
end
# Add a new project
def add
@custom_fields = CustomField::find_all
@project = Project.new(params[:project])
if request.post?
@project.custom_fields = CustomField.find(@params[:custom_field_ids]) if @params[:custom_field_ids]
if @project.save
flash[:notice] = 'Project was successfully created.'
redirect_to :controller => 'admin', :action => 'projects'
end
end
end
def add
@custom_fields = CustomField::find_all
@root_projects = Project::find(:all, :conditions => "parent_id is null")
@project = Project.new(params[:project])
if request.post?
@project.custom_fields = CustomField.find(@params[:custom_field_ids]) if @params[:custom_field_ids]
if @project.save
flash[:notice] = 'Project was successfully created.'
redirect_to :controller => 'admin', :action => 'projects'
end
end
end
# Show @project
def show
@members = @project.members.find(:all, :include => [:user, :role])
end
# Show @project
def show
@members = @project.members.find(:all, :include => [:user, :role])
@subprojects = @project.children if @project.children_count > 0
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "news.created_on DESC")
end
def settings
@custom_fields = CustomField::find_all
@issue_category ||= IssueCategory.new
@root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
@custom_fields = CustomField::find_all
@issue_category ||= IssueCategory.new
@member ||= @project.members.new
@roles = Role.find_all
@users = User.find_all - @project.members.find(:all, :include => :user).collect{|m| m.user }
end
# Edit @project
def edit
if request.post?
@project.custom_fields = CustomField.find(@params[:custom_field_ids]) if @params[:custom_field_ids]
if @project.update_attributes(params[:project])
flash[:notice] = 'Project was successfully updated.'
redirect_to :action => 'settings', :id => @project
# Edit @project
def edit
if request.post?
@project.custom_fields = CustomField.find(@params[:custom_field_ids]) if @params[:custom_field_ids]
if @project.update_attributes(params[:project])
flash[:notice] = 'Project was successfully updated.'
redirect_to :action => 'settings', :id => @project
else
settings
render :action => 'settings'
end
end
end
end
end
# Delete @project
......@@ -181,7 +185,7 @@ class ProjectsController < ApplicationController
end
end
# Show issues list of @project
# Show filtered/sorted issues list of @project
def list_issues
sort_init 'issues.id', 'desc'
sort_update
......@@ -189,10 +193,10 @@ class ProjectsController < ApplicationController
search_filter_init_list_issues
search_filter_update if params[:set_filter] or request.post?
@issue_count = Issue.count(:include => :status, :conditions => search_filter_clause)
@issue_count = Issue.count(:include => [:status, :project], :conditions => search_filter_clause)
@issue_pages = Paginator.new self, @issue_count, 15, @params['page']
@issues = Issue.find :all, :order => sort_clause,
:include => [ :author, :status, :tracker ],
:include => [ :author, :status, :tracker, :project ],
:conditions => search_filter_clause,
:limit => @issue_pages.items_per_page,
:offset => @issue_pages.current.offset
......@@ -206,7 +210,7 @@ class ProjectsController < ApplicationController
search_filter_init_list_issues
@issues = Issue.find :all, :order => sort_clause,
:include => [ :author, :status, :tracker ],
:include => [ :author, :status, :tracker, :project ],
:conditions => search_filter_clause
export = StringIO.new
......
......@@ -62,9 +62,6 @@ class RolesController < ApplicationController
end
def workflow
@roles = Role.find_all
@trackers = Tracker.find_all
@statuses = IssueStatus.find_all
@role = Role.find_by_id(params[:role_id])
@tracker = Tracker.find_by_id(params[:tracker_id])
......@@ -80,5 +77,8 @@ class RolesController < ApplicationController
flash[:notice] = 'Workflow was successfully updated.'
end
end
@roles = Role.find_all
@trackers = Tracker.find_all
@statuses = IssueStatus.find(:all, :include => :workflows)
end
end
......@@ -16,58 +16,62 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class UsersController < ApplicationController
layout 'base'
before_filter :require_admin
helper :sort
include SortHelper
def index
list
render :action => 'list'
end
layout 'base'
before_filter :require_admin
helper :sort
include SortHelper
def index
list
render :action => 'list'
end
def list
sort_init 'users.login', 'asc'
sort_update
@user_count = User.count
@user_pages = Paginator.new self, @user_count,
def list
sort_init 'login', 'asc'
sort_update
@user_count = User.count
@user_pages = Paginator.new self, @user_count,
15,
@params['page']
@users = User.find :all, :order => sort_clause,
@users = User.find :all,:order => sort_clause,
:limit => @user_pages.items_per_page,
:offset => @user_pages.current.offset
end
end
def add
if request.get?
@user = User.new
else
@user = User.new(params[:user])
@user.admin = params[:user][:admin]
if @user.save
flash[:notice] = 'User was successfully created.'
redirect_to :action => 'list'
end
end
end
def add
if request.get?
@user = User.new
else
@user = User.new(params[:user])
@user.admin = params[:user][:admin] || false
@user.login = params[:user][:login]
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
if @user.save
flash[:notice] = 'User was successfully created.'
redirect_to :action => 'list'
end
end
end
def edit
@user = User.find(params[:id])
if request.post?
@user.admin = params[:user][:admin] if params[:user][:admin]
if @user.update_attributes(params[:user])
flash[:notice] = 'User was successfully updated.'
redirect_to :action => 'list'
end
end
end
def edit
@user = User.find(params[:id])
if request.post?
@user.admin = params[:user][:admin] if params[:user][:admin]
@user.login = params[:user][:login] if params[:user][:login]
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty?
if @user.update_attributes(params[:user])
flash[:notice] = 'User was successfully updated.'
redirect_to :action => 'list'
end
end
end
def destroy
User.find(params[:id]).destroy
redirect_to :action => 'list'
def destroy
User.find(params[:id]).destroy
redirect_to :action => 'list'
rescue
flash[:notice] = "Unable to delete user"
redirect_to :action => 'list'
end
end
end
......@@ -38,6 +38,9 @@ class VersionsController < ApplicationController
@attachment = @version.attachments.find(params[:attachment_id])
@attachment.increment_download
send_file @attachment.diskfile, :filename => @attachment.filename
rescue
flash[:notice]="Requested file doesn't exist or has been deleted."
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
end
def destroy_file
......
......@@ -27,7 +27,7 @@ module ApplicationHelper
def authorize_for(controller, action)
# check if action is allowed on public projects
if @project.public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
return true
end
# check if user is authorized
......
......@@ -18,68 +18,73 @@
module SearchFilterHelper
def search_filter_criteria(name, options = {})
session[:search_filter] ||= {}
session[:search_filter][name] ||= {}
unless session[:search_filter][name][:options] and session[:search_filter][name][:conditions]
session[:search_filter][name][:options] = []
session[:search_filter][name][:conditions] = {}
yield.each { |c|
session[:search_filter][name][:options] << [c[0], c[1].to_s]
session[:search_filter][name][:conditions].store(c[1].to_s, c[2])
}
end
@search_filter ||= {}
@search_filter[name] ||= {}
@search_filter[name][:options] = []
@search_filter[name][:conditions] = {}
yield.each { |c|
@search_filter[name][:options] << [c[0], c[1].to_s]
@search_filter[name][:conditions].store(c[1].to_s, c[2])
}
end
def search_filter_update
session[:search_filter].each_key {|field| session[:search_filter][field][:value] = params[field] }
@search_filter.each_key {|field| session[:search_filter][field] = params[field] }
end
def search_filter_clause
clause = ["issues.project_id=?", @project.id]
session[:search_filter].each { |k, v|
v[:value] ||= v[:options][0][1]
if (!v[:conditions][v[:value]][0].empty?)
clause[0] = clause[0] + " AND " + v[:conditions][v[:value]][0]
clause << v[:conditions][v[:value]][1] if !v[:conditions][v[:value]][1].nil?
clause = ["1=1"]
@search_filter.each { |k, v|
filter_value = session[:search_filter][k] || v[:options][0][1]
if v[:conditions][filter_value]
clause[0] = clause[0] + " AND " + v[:conditions][filter_value].first
clause += v[:conditions][filter_value][1..-1]
end
}
clause
end
def search_filter_tag(criteria)