# HG changeset patch # User Chris Cannam # Date 1301329976 -3600 # Node ID 6c56a595dc1c2af031acde6fef07d642c96789e3 # Parent 93b4cfd3aaaae757181b642184bd50131f73365e# Parent defe55be97b9d9fb210123aa781221dd144a6e7e Merge from branch "feature_73" diff -r defe55be97b9 -r 6c56a595dc1c app/controllers/attachments_controller.rb --- a/app/controllers/attachments_controller.rb Thu Mar 24 15:48:36 2011 +0000 +++ b/app/controllers/attachments_controller.rb Mon Mar 28 17:32:56 2011 +0100 @@ -16,9 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class AttachmentsController < ApplicationController + before_filter :find_project before_filter :file_readable, :read_authorize, :except => :destroy before_filter :delete_authorize, :only => :destroy + before_filter :active_authorize, :only => :toggle_active verify :method => :post, :only => :destroy @@ -54,6 +56,12 @@ redirect_to :controller => 'projects', :action => 'show', :id => @project end + def toggle_active + @attachment.active = !@attachment.active? + @attachment.save! + render :layout => false + end + private def find_project @attachment = Attachment.find(params[:id]) @@ -77,6 +85,10 @@ @attachment.deletable? ? true : deny_access end + def active_authorize + true + end + def detect_content_type(attachment) content_type = attachment.content_type if content_type.blank? diff -r defe55be97b9 -r 6c56a595dc1c app/controllers/files_controller.rb --- a/app/controllers/files_controller.rb Thu Mar 24 15:48:36 2011 +0000 +++ b/app/controllers/files_controller.rb Mon Mar 28 17:32:56 2011 +0100 @@ -10,6 +10,7 @@ def index sort_init 'filename', 'asc' sort_update 'filename' => "#{Attachment.table_name}.filename", + 'active' => "#{Attachment.table_name}.active", 'created_on' => "#{Attachment.table_name}.created_on", 'size' => "#{Attachment.table_name}.filesize", 'downloads' => "#{Attachment.table_name}.downloads" @@ -33,4 +34,5 @@ end redirect_to project_files_path(@project) end + end diff -r defe55be97b9 -r 6c56a595dc1c app/controllers/members_controller.rb --- a/app/controllers/members_controller.rb Thu Mar 24 15:48:36 2011 +0000 +++ b/app/controllers/members_controller.rb Mon Mar 28 17:32:56 2011 +0100 @@ -28,12 +28,24 @@ attrs = params[:member].dup if (user_ids = attrs.delete(:user_ids)) user_ids.each do |user_id| - members << Member.new(attrs.merge(:user_id => user_id)) + @new_member = Member.new(attrs.merge(:user_id => user_id)) + members << @new_member + + # send notification to member + Mailer.deliver_added_to_project(@new_member, @project) + end else - members << Member.new(attrs) + @new_member = Member.new(attrs) + members << @new_member + + # send notification to member + Mailer.deliver_added_to_project(@new_member, @project) + end + @project.members << members + end respond_to do |format| if members.present? && members.all? {|m| m.valid? } @@ -54,8 +66,8 @@ errors = members.collect {|m| m.errors.full_messages }.flatten.uniq - - page.alert(l(:notice_failed_to_save_members, :errors => errors.join(', '))) + + # page.alert(l(:notice_failed_to_save_members, :errors => errors.join(', '))) } } diff -r defe55be97b9 -r 6c56a595dc1c app/models/mailer.rb --- a/app/models/mailer.rb Thu Mar 24 15:48:36 2011 +0000 +++ b/app/models/mailer.rb Mon Mar 28 17:32:56 2011 +0100 @@ -31,6 +31,27 @@ h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank? { :host => h, :protocol => Setting.protocol } end + + + + # Builds a tmail object used to email the specified user that he was added to a project + # + # Example: + # add_to_project(user) => tmail object + # Mailer.deliver_add_to_project(user) => sends an email to the registered user + def added_to_project(member, project) + + user = User.find(member.user_id) + + set_language_if_valid user.language + recipients user.mail + subject l(:mail_subject_added_to_project, Setting.app_title) + body :project_url => url_for(:controller => 'projects', :action => 'show', :id => project.id), + :project_name => project.name + render_multipart('added_to_project', body) + end + + # Builds a tmail object used to email recipients of the added issue. # @@ -440,3 +461,7 @@ end end end + + + + diff -r defe55be97b9 -r 6c56a595dc1c app/views/attachments/toggle_active.rhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/attachments/toggle_active.rhtml Mon Mar 28 17:32:56 2011 +0100 @@ -0,0 +1,7 @@ +<%= +file = Attachment.find(params[:id]) +active_id = "active-" + file.id.to_s +link_to_remote image_tag(file.active? ? 'fav.png' : 'fav_off.png'), + :url => {:controller => 'attachments', :action => 'toggle_active', :project_id => @project.id, :id => file}, + :update => active_id +%> diff -r defe55be97b9 -r 6c56a595dc1c app/views/files/index.html.erb --- a/app/views/files/index.html.erb Thu Mar 24 15:48:36 2011 +0000 +++ b/app/views/files/index.html.erb Mon Mar 28 17:32:56 2011 +0100 @@ -5,29 +5,51 @@
MD5 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
+ | <%= link_to(h(container), {:controller => 'versions', :action => 'show', :id => container}, :class => "icon icon-package") %> | |||||||||||
<%= link_to_attachment file, :download => true, :title => file.description %> | +||||||||||||
+ <% have_file = true %>
+ <% if active_change_allowed
+ active_id = "active-" + file.id.to_s -%>
+
+ <%= link_to_remote image_tag(file.active? ? 'fav.png' : 'fav_off.png'),
+ :url => {:controller => 'attachments', :action => 'toggle_active', :project_id => @project.id, :id => file},
+ :update => active_id
+ %>
+
+ <% else -%>
+ <%= image_tag('fav.png') if file.active? %>
+ <% end -%>
+ |
+ <% if file.active? %>
+ <%= link_to_attachment file, :download => true %> <%= h(file.description) %> |
+ <% else %>
+ <%= link_to_attachment file, :download => true, :title => file.description %> + <% end %> + | <%= format_time(file.created_on) %> | <%= number_to_human_size(file.filesize) %> | <%= file.downloads %> | @@ -43,4 +65,6 @@
<%= l(:notice_added_to_project, :project_name => @project_name) %>
+<%= l(:notice_project_homepage, :project_url => @project_url) %>
+ diff -r defe55be97b9 -r 6c56a595dc1c app/views/mailer/added_to_project.text.plain.rhtml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/mailer/added_to_project.text.plain.rhtml Mon Mar 28 17:32:56 2011 +0100 @@ -0,0 +1,2 @@ +<%= l(:notice_added_to_project, :project_name => @project_name) %> +<%= l(:notice_project_homepage, :project_url => @project_url) %> diff -r defe55be97b9 -r 6c56a595dc1c app/views/projects/settings/_members.rhtml --- a/app/views/projects/settings/_members.rhtml Thu Mar 24 15:48:36 2011 +0000 +++ b/app/views/projects/settings/_members.rhtml Mon Mar 28 17:32:56 2011 +0100 @@ -2,6 +2,7 @@ <% roles = Role.find_all_givable members = @project.member_principals.find(:all, :include => [:roles, :principal]).sort %> +