# HG changeset patch # User Chris Cannam # Date 1299154313 0 # Node ID 73ff0e6a11b156dcaa5b00b3386b03bef56a8310 # Parent eeebe205a0562c9814c0b2c39e1cc019f43cf0df# Parent 7cec015f07ce4a03f4928f1dcf11dc26da6369ac * Merge from branch cannam-pre-20110113-merge diff -r eeebe205a056 -r 73ff0e6a11b1 app/controllers/account_controller.rb --- a/app/controllers/account_controller.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/controllers/account_controller.rb Thu Mar 03 12:11:53 2011 +0000 @@ -108,7 +108,9 @@ # associates the 2 objects @user.ssamr_user_detail = @ssamr_user_details + @selected_institution_id = params[:ssamr_user_details][:institution_id].to_i + case Setting.self_registration when '1' register_by_email_activation(@user) diff -r eeebe205a056 -r 73ff0e6a11b1 app/controllers/application_controller.rb --- a/app/controllers/application_controller.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/controllers/application_controller.rb Thu Mar 03 12:11:53 2011 +0000 @@ -263,6 +263,12 @@ uri = URI.parse(back_url) # do not redirect user to another host or to the login or register page if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)}) + # soundsoftware: if login page is https but back_url http, + # switch back_url to https to ensure cookie validity (#83) + if (uri.scheme == "http") && (URI.parse(request.url).scheme == "https") + uri.scheme = "https" + back_url = uri.to_s + end redirect_to(back_url) return end diff -r eeebe205a056 -r 73ff0e6a11b1 app/controllers/issues_controller.rb --- a/app/controllers/issues_controller.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/controllers/issues_controller.rb Thu Mar 03 12:11:53 2011 +0000 @@ -139,15 +139,12 @@ call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) - # Adds user to watcher's list - @issue.add_watcher(User.current) - # Also adds the assignee to the watcher's list - if params[:issue][:assigned_to_id] && !params[:issue][:assigned_to_id].empty?: - unless @issue.watcher_ids.include?(params[:issue][:assigned_to_id]): - @issue.add_watcher(User.find(params[:issue][:assigned_to_id])) - end + if params[:issue][:assigned_to_id] && !params[:issue][:assigned_to_id].empty?: + unless @issue.watcher_ids.include?(params[:issue][:assigned_to_id]): + @issue.add_watcher(User.find(params[:issue][:assigned_to_id])) end + end respond_to do |format| format.html { @@ -289,9 +286,9 @@ # if not, adds it. if params[:issue][:assigned_to_id] && !params[:issue][:assigned_to_id].empty?: - unless @issue.watcher_ids.include?(params[:issue][:assigned_to_id]): - @issue.add_watcher(User.find(params[:issue][:assigned_to_id])) - end + unless @issue.watched_by?(User.find(params[:issue][:assigned_to_id])): + @issue.add_watcher(User.find(params[:issue][:assigned_to_id])) + end end diff -r eeebe205a056 -r 73ff0e6a11b1 app/controllers/my_controller.rb --- a/app/controllers/my_controller.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/controllers/my_controller.rb Thu Mar 03 12:11:53 2011 +0000 @@ -53,10 +53,39 @@ def account @user = User.current @pref = @user.pref + @ssamr_user_details = @user.ssamr_user_detail + + + if @user.ssamr_user_detail == nil + @selected_institution_id = nil + else + @selected_institution_id = @ssamr_user_details.institution_id.to_i + end + if request.post? @user.safe_attributes = params[:user] @user.pref.attributes = params[:pref] @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') + + if @user.ssamr_user_detail == nil + @ssamr_user_details = SsamrUserDetail.new() + @user.ssamr_user_detail = @ssamr_user_details + else + @ssamr_user_details = @user.ssamr_user_detail + end + + if params[:ssamr_user_details].nil? or params[:ssamr_user_details].empty? + @ssamr_user_details.description = @user.ssamr_user_detail.description + @ssamr_user_details.institution_id = @user.ssamr_user_detail.institution_id + @institution_type = @ssamr_user_details.institution_type + @other_institution = @ssamr_user_details.other_institution + else + @ssamr_user_details.description = params[:ssamr_user_details][:description] + @ssamr_user_details.institution_id = params[:ssamr_user_details][:institution_id] + @ssamr_user_details.institution_type = params[:ssamr_user_details][:institution_type] + @ssamr_user_details.other_institution = params[:ssamr_user_details][:other_institution] + end + if @user.save @user.pref.save @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) diff -r eeebe205a056 -r 73ff0e6a11b1 app/controllers/projects_controller.rb --- a/app/controllers/projects_controller.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/controllers/projects_controller.rb Thu Mar 03 12:11:53 2011 +0000 @@ -43,19 +43,20 @@ include RepositoriesHelper include ProjectsHelper - # Lists visible projects + # Lists visible projects. Paginator is for top-level projects only + # (subprojects belong to them) def index respond_to do |format| format.html { - sort_init 'lft' - sort_update %w(lft title created_on updated_on) + sort_init 'name' + sort_update %w(name lft created_on updated_on) @limit = per_page_option - @project_count = Project.visible.count + @project_count = Project.visible_roots.count @project_pages = Paginator.new self, @project_count, @limit, params['page'] @offset ||= @project_pages.current.offset - @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => sort_clause) + @projects = Project.visible_roots.all(:offset => @offset, :limit => @limit, :order => sort_clause) if User.current.logged? - @user_projects = User.current.projects.sort_by(&:lft) + @user_projects = User.current.projects.sort_by(&:name) end render :template => 'projects/index.rhtml', :layout => !request.xhr? } diff -r eeebe205a056 -r 73ff0e6a11b1 app/controllers/sys_controller.rb --- a/app/controllers/sys_controller.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/controllers/sys_controller.rb Thu Mar 03 12:11:53 2011 +0000 @@ -55,6 +55,31 @@ render :nothing => true, :status => 404 end + def set_embedded_active + project = Project.find(params[:id]) + mods = project.enabled_modules + enable = (params[:enable] == "1") + if mods.detect {|m| m.name == "embedded"} + logger.info "Project #{project.name} currently has Embedded enabled" + if !enable + logger.info "Disabling Embedded" + modnames = mods.all(:select => :name).collect{|m| m.name}.reject{|n| n == "embedded"} + project.enabled_module_names = modnames + end + else + logger.info "Project #{project.name} currently has Embedded disabled" + if enable + logger.info "Enabling Embedded" + modnames = mods.all(:select => :name).collect{|m| m.name} + modnames << "embedded" + project.enabled_module_names = modnames + end + end + render :nothing => true, :status => 200 + rescue ActiveRecord::RecordNotFound + render :nothing => true, :status => 404 + end + protected def check_enabled diff -r eeebe205a056 -r 73ff0e6a11b1 app/controllers/users_controller.rb --- a/app/controllers/users_controller.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/controllers/users_controller.rb Thu Mar 03 12:11:53 2011 +0000 @@ -65,6 +65,15 @@ if @user.ssamr_user_detail != nil @description = @user.ssamr_user_detail.description + + if @user.ssamr_user_detail.institution_type != nil + # institution_type is true for listed institutions + if (@user.ssamr_user_detail.institution_type) + @institution_name = Institution.find(@user.ssamr_user_detail.institution_id).name + else + @institution_name = @user.ssamr_user_detail.other_institution + end + end end # show projects based on current user visibility @@ -91,7 +100,6 @@ @auth_sources = AuthSource.find(:all) @ssamr_user_details = SsamrUserDetail.new - end verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } @@ -146,6 +154,12 @@ @ssamr_user_details = @user.ssamr_user_detail + if @user.ssamr_user_detail == nil + @selected_institution_id = nil + else + @selected_institution_id = @user.ssamr_user_detail.institution_id.to_i + end + @auth_sources = AuthSource.find(:all) @membership ||= Member.new end @@ -170,13 +184,18 @@ else @ssamr_user_details = @user.ssamr_user_detail end - - + if params[:ssamr_user_details].nil? or params[:ssamr_user_details].empty? @ssamr_user_details.description = @user.ssamr_user_detail.description + @ssamr_user_details.institution_id = @user.ssamr_user_detail.institution_id + @ssamr_user_details.other_institution = @user.ssamr_user_detail.other_institution + @ssamr_user_details.institution_type = @user.ssamr_user_detail.institution_type + else @ssamr_user_details.description = params[:ssamr_user_details][:description] - @ssamr_user_details.save! + @ssamr_user_details.institution_id = params[:ssamr_user_details][:institution_id] + @ssamr_user_details.other_institution = params[:ssamr_user_details][:other_institution] + @ssamr_user_details.institution_type = params[:ssamr_user_details][:institution_type] end if @user.save diff -r eeebe205a056 -r 73ff0e6a11b1 app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/helpers/application_helper.rb Thu Mar 03 12:11:53 2011 +0000 @@ -52,7 +52,7 @@ if user.is_a?(User) name = h(user.name(options[:format])) if user.active? - link_to name, :controller => 'users', :action => 'show', :id => user + link_to(name, :controller => 'users', :action => 'show', :id => user) else name end @@ -395,21 +395,28 @@ def page_header_title if @project.nil? || @project.new_record? - h(Setting.app_title) + a = [h(Setting.app_title), ''] + else + pname = [] b = [] ancestors = (@project.root? ? [] : @project.ancestors.visible) if ancestors.any? root = ancestors.shift b << link_to_project(root, {:jump => current_menu_item}, :class => 'root') if ancestors.size > 2 - b << '…' + b << '…' ancestors = ancestors[-2, 2] end b += ancestors.collect {|p| link_to_project(p, {:jump => current_menu_item}, :class => 'ancestor') } + b = b.join(' » ') + b << (' »') end - b << h(@project) - b.join(' » ') + + pname << h(@project) + + a = [pname, b] + end end diff -r eeebe205a056 -r 73ff0e6a11b1 app/helpers/projects_helper.rb --- a/app/helpers/projects_helper.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/helpers/projects_helper.rb Thu Mar 03 12:11:53 2011 +0000 @@ -163,82 +163,91 @@ s << "" s << "" - s << sort_header_tag('lft', :caption => l("field_name"), :default_order => 'desc') + s << sort_header_tag('name', :caption => l("field_name")) s << "" s << sort_header_tag('created_on', :default_order => 'desc') s << sort_header_tag('updated_on', :default_order => 'desc') s << "" - ancestors = [] original_project = @project - oddeven = 'even' + level = 0 projects.each do |project| + s << render_project_in_table(project, cycle('odd', 'even'), 0) + end - # set the project environment to please macros. + s << "
" << l("label_managers") << "
" - @project = project - - if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) - level = level + 1 - else + @project = original_project + s level = 0 oddeven = cycle('odd','even') - ancestors.pop - while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) - ancestors.pop - end - end + end + + + def render_project_in_table(project, oddeven, level) + + # set the project environment to please macros. + @project = project + + classes = (level == 0 ? 'root' : 'child') + + s = "" + + s << "" + s << "
" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}"); + s << "
" + unless project.description.blank? + s << "
" + s << textilizable(project.short_description, :project => project) + s << "
" + end - classes = (ancestors.empty? ? 'root' : 'child') + s << "" - s << "" - s << "" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}") << "" - s << "" - - u = project.users_by_role - if u - u.keys.each do |r| - if r.allowed_to?(:edit_project) - mgrs = [] - u[r].sort.each do |m| + u = project.users_by_role + if u + u.keys.each do |r| + if r.allowed_to?(:edit_project) + mgrs = [] + u[r].sort.each do |m| + mgrs << link_to_user(m) + end + if mgrs.size < 3 + s << '' << mgrs.join(', ') << '' mgrs << link_to_user(m) end if mgrs.size < 3 s << '' << mgrs.join(', ') << '' - else - s << mgrs.join(', ') + else + s << mgrs.join(', ') end end end end - - s << "" - s << "" << format_date(project.created_on) << "" - s << "" << format_date(project.updated_on) << "" - - s << "" - s << "" - s << "" - s << textilizable(project.short_description, :project => project) unless project.description.blank? - s << "" - s << " " s << "" ancestors << project end - s << "" + s << "" + s << "" << format_date(project.created_on) << "" + s << "" << format_date(project.updated_on) << "" + + s << "" - @project = original_project - + project.children.each do |child| + s << render_project_in_table(child, oddeven, level + 1) + end + s end - # Returns a set of options for a select field, grouped by project. def version_options_for_select(versions, selected=nil) grouped = Hash.new {|h,k| h[k] = []} diff -r eeebe205a056 -r 73ff0e6a11b1 app/models/institution.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/models/institution.rb Thu Mar 03 12:11:53 2011 +0000 @@ -0,0 +1,2 @@ +class Institution < ActiveRecord::Base +end diff -r eeebe205a056 -r 73ff0e6a11b1 app/models/issue.rb --- a/app/models/issue.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/models/issue.rb Thu Mar 03 12:11:53 2011 +0000 @@ -90,7 +90,7 @@ before_save :close_duplicates, :update_done_ratio_from_issue_status after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal after_destroy :update_parent_attributes - + # Returns true if usr or current user is allowed to view the issue def visible?(usr=nil) (usr || User.current).allowed_to?(:view_issues, self.project) @@ -529,7 +529,8 @@ # Returns a string of css classes that apply to the issue def css_classes - s = "issue status-#{status.position} priority-#{priority.position}" + s = "issue status-#{status.position} " + s << "priority-#{priority.position}" s << ' closed' if closed? s << ' overdue' if overdue? s << ' created-by-me' if User.current.logged? && author_id == User.current.id diff -r eeebe205a056 -r 73ff0e6a11b1 app/models/project.rb --- a/app/models/project.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/models/project.rb Thu Mar 03 12:11:53 2011 +0000 @@ -85,6 +85,7 @@ named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"} named_scope :all_public, { :conditions => { :is_public => true } } named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } } + named_scope :visible_roots, lambda { { :conditions => Project.root_visible_by(User.current) } } def initialize(attributes = nil) super @@ -134,6 +135,10 @@ end end + def self.root_visible_by(user=nil) + return "#{Project.table_name}.parent_id IS NULL AND " + visible_by(user) + end + def self.allowed_to_condition(user, permission, options={}) statements = [] base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}" diff -r eeebe205a056 -r 73ff0e6a11b1 app/models/ssamr_user_detail.rb --- a/app/models/ssamr_user_detail.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/models/ssamr_user_detail.rb Thu Mar 03 12:11:53 2011 +0000 @@ -2,4 +2,13 @@ belongs_to :user validates_presence_of :description + + validate :check_institution + + def check_institution() + errors.add(:institution_id, "Please insert an institution") if + institution_id.blank? and other_institution.blank? + end + + end diff -r eeebe205a056 -r 73ff0e6a11b1 app/models/user.rb --- a/app/models/user.rb Thu Mar 03 12:02:03 2011 +0000 +++ b/app/models/user.rb Thu Mar 03 12:11:53 2011 +0000 @@ -82,6 +82,8 @@ before_destroy :remove_references_before_destroy + validates_acceptance_of :terms_and_conditions, :on => :create, :message => :must_accept_terms_and_conditions + def before_create self.mail_notification = Setting.default_notification_option if self.mail_notification.blank? true diff -r eeebe205a056 -r 73ff0e6a11b1 app/views/account/register.rhtml --- a/app/views/account/register.rhtml Thu Mar 03 12:02:03 2011 +0000 +++ b/app/views/account/register.rhtml Thu Mar 03 12:11:53 2011 +0000 @@ -1,3 +1,6 @@ +<%= javascript_include_tag "ssamr_institutions" %> +<%= javascript_include_tag "ssamr_registration" %> +

<%=l(:label_register)%> <%=link_to l(:label_login_with_open_id_option), signin_url if Setting.openid? %>

<% form_tag({:action => 'register'}, :class => "tabular") do %> @@ -34,17 +37,21 @@ <% fields_for :ssamr_user_details, :builder => TabularFormBuilder, :lang => current_language do |ssamr_user_detail| %>

+ <%= ssamr_user_detail.text_area :description, :rows => 3, :cols => 40, :required => true, :class => 'wiki-edit' %> + <%=l(:text_user_ssamr_description_info)%> +

- <%= ssamr_user_detail.text_area :description, :rows => 3, :cols => 40, :required => true, :class => 'wiki-edit' %> - <%= wikitoolbar_for 'ssamr_user_details_description' %> +

+ <%= ssamr_user_detail.radio_button :institution_type, true %> + <%= ssamr_user_detail.collection_select(:institution_id, Institution.find(:all, :order => "institutions.order"), :id, :name, {:selected => @selected_institution_id, :prompt => true}).gsub('&', '&') %> +

- <%=l(:text_user_ssamr_description_info)%> +

+ <%= ssamr_user_detail.radio_button :institution_type, false %> Other: + <%= ssamr_user_detail.text_field(:other_institution) %>

<% end %> - - - <% if Setting.openid? %>

<%= text_field 'user', 'identity_url' %>

@@ -56,5 +63,9 @@ +<%= check_box :user, :terms_and_conditions %> <%= l(:accept_terms_and_conditions) %> <%= link_to("Terms and Conditions", "https://code.soundsoftware.ac.uk/projects/soundsoftware-site/wiki/TandCs", {:target => "_blank"}) %>. +
+
+ <%= submit_tag l(:button_submit) %> <% end %> diff -r eeebe205a056 -r 73ff0e6a11b1 app/views/issues/_attributes.rhtml --- a/app/views/issues/_attributes.rhtml Thu Mar 03 12:02:03 2011 +0000 +++ b/app/views/issues/_attributes.rhtml Thu Mar 03 12:11:53 2011 +0000 @@ -8,7 +8,7 @@ <% end %>

<%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), {:required => true}, :disabled => !@issue.leaf? %>

-

<%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %>

+

<%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), {:include_blank => true} %>

<% unless @project.issue_categories.empty? %>

<%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %> <%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'), diff -r eeebe205a056 -r 73ff0e6a11b1 app/views/issues/_form.rhtml --- a/app/views/issues/_form.rhtml Thu Mar 03 12:02:03 2011 +0000 +++ b/app/views/issues/_form.rhtml Thu Mar 03 12:11:53 2011 +0000 @@ -35,7 +35,7 @@ <% if @issue.new_record? && User.current.allowed_to?(:add_issue_watchers, @project) -%>

<% @issue.project.users.sort.each do |user| -%> - + <% end -%>

<% end %> diff -r eeebe205a056 -r 73ff0e6a11b1 app/views/layouts/base.rhtml --- a/app/views/layouts/base.rhtml Thu Mar 03 12:02:03 2011 +0000 +++ b/app/views/layouts/base.rhtml Thu Mar 03 12:11:53 2011 +0000 @@ -3,8 +3,8 @@ <%=h html_title %> - - + + <%= favicon %> <%= stylesheet_link_tag 'application', :media => 'all' %> <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> @@ -33,17 +33,32 @@ <%= tag('div', {:id => 'header', :class => (display_main_menu?(@project) ? 'header-project' : 'header-general')}, true) %> -