Patch #24623 » 0015-Implements-permissions-and-restrictions-to-issue-att-fix2-4.1.patch
| app/controllers/issues_controller.rb | ||
|---|---|---|
|
@journals = @issue.visible_journals_with_index
|
||
|
@has_changesets = @issue.changesets.visible.preload(:repository, :user).exists?
|
||
|
@relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
|
||
|
@attachments = @issue.attachments_visible?(User.current) ? @issue.attachments : []
|
||
|
@journals.reverse! if User.current.wants_comments_in_reverse_order?
|
||
| ... | ... | |
|
raise ::Unauthorized
|
||
|
end
|
||
|
call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
|
||
|
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
||
|
if @issue.attachments_addable?(User.current)
|
||
|
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
||
|
end
|
||
|
if @issue.save
|
||
|
call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
|
||
|
respond_to do |format|
|
||
| ... | ... | |
|
def edit
|
||
|
return unless update_issue_from_params
|
||
|
@attachments = @issue.attachments_visible?(User.current) ? @issue.attachments : []
|
||
|
respond_to do |format|
|
||
|
format.html { }
|
||
|
format.js
|
||
| ... | ... | |
|
def update
|
||
|
return unless update_issue_from_params
|
||
|
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
||
|
if @issue.attachments_addable?(User.current)
|
||
|
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
|
||
|
end
|
||
|
saved = false
|
||
|
begin
|
||
|
saved = save_issue_with_child_records
|
||
| ... | ... | |
|
@versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
|
||
|
@categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
|
||
|
if @copy
|
||
|
@attachments_present = @issues.detect {|i| i.attachments.any?}.present?
|
||
|
@attachments_present = @issues.detect {|i| i.attachments.any? && i.attachments_visible?(User.current)}.present?
|
||
|
@subtasks_present = @issues.detect {|i| !i.leaf?}.present?
|
||
|
@watchers_present = User.current.allowed_to?(:add_issue_watchers, @projects) &&
|
||
|
Watcher.where(:watchable_type => 'Issue',
|
||
| ... | ... | |
|
end
|
||
|
journal = issue.init_journal(User.current, params[:notes])
|
||
|
issue.safe_attributes = attributes
|
||
|
issue.attachments = [] unless issue.attachments_addable?(User.current) if @copy
|
||
|
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
|
||
|
if issue.save
|
||
|
saved_issues << issue
|
||
| ... | ... | |
|
@priorities = IssuePriority.active
|
||
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||
|
@issue.attachments = [] unless @issue.attachments_addable?(User.current)
|
||
|
end
|
||
|
# Saves @issue and a time_entry from the parameters
|
||
| app/models/issue.rb | ||
|---|---|---|
|
has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
|
||
|
has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
|
||
|
acts_as_attachable :after_add => :attachment_added, :after_remove => :attachment_removed
|
||
|
acts_as_attachable :after_add => :attachment_added, :after_remove => :attachment_removed,
|
||
|
:view_permission => :view_attachments, :edit_permission => :edit_attachments,
|
||
|
:delete_permission => :delete_attachments
|
||
|
acts_as_customizable
|
||
|
acts_as_watchable
|
||
|
acts_as_searchable :columns => ['subject', "#{table_name}.description"],
|
||
| ... | ... | |
|
)
|
||
|
end
|
||
|
# Overrides Redmine::Acts::Attachable::InstanceMethods#attachments_editable?
|
||
|
def attachments_visible?(user=User.current)
|
||
|
user_tracker_permission?(user, :view_attachments)
|
||
|
end
|
||
|
# Returns true if user or current user is allowed to add the attachment to the issue
|
||
|
def attachments_addable?(user=User.current)
|
||
|
user_tracker_permission?(user, :add_attachments)
|
||
|
end
|
||
|
# Overrides Redmine::Acts::Attachable::InstanceMethods#attachments_editable?
|
||
|
def attachments_editable?(user=User.current)
|
||
|
attributes_editable?(user)
|
||
|
user_tracker_permission?(user, :edit_attachments)
|
||
|
end
|
||
|
# Overrides Redmine::Acts::Attachable::InstanceMethods#attachments_editable?
|
||
|
def attachments_deletable?(user=User.current)
|
||
|
user_tracker_permission?(user, :delete_attachments)
|
||
|
end
|
||
|
# Returns true if user or current user is allowed to add notes to the issue
|
||
| ... | ... | |
|
self.status = issue.status
|
||
|
end
|
||
|
self.author = User.current
|
||
|
unless options[:attachments] == false
|
||
|
if options[:attachments] == true && issue.attachments_visible?(user=User.current)
|
||
|
self.attachments = issue.attachments.map do |attachement|
|
||
|
attachement.copy(:container => self)
|
||
|
end
|
||
| ... | ... | |
|
copy.parent_issue_id = copied_issue_ids[child.parent_id]
|
||
|
copy.fixed_version_id = nil unless child.fixed_version.present? && child.fixed_version.status == 'open'
|
||
|
copy.assigned_to = nil unless child.assigned_to_id.present? && child.assigned_to.status == User::STATUS_ACTIVE
|
||
|
copy.attachments = [] unless copy.attachments_addable?(User.current)
|
||
|
unless copy.save
|
||
|
logger.error "Could not copy subtask ##{child.id} while copying ##{@copied_from.id} to ##{id} due to validation errors: #{copy.errors.full_messages.join(', ')}" if logger
|
||
|
next
|
||
| app/models/journal.rb | ||
|---|---|---|
|
detail.custom_field && detail.custom_field.visible_by?(project, user)
|
||
|
elsif detail.property == 'relation'
|
||
|
Issue.find_by_id(detail.value || detail.old_value).try(:visible?, user)
|
||
|
elsif detail.property == 'attachment'
|
||
|
self.issue.attachments_visible?(User.current)
|
||
|
else
|
||
|
true
|
||
|
end
|
||
| app/models/mailer.rb | ||
|---|---|---|
|
end
|
||
|
# Builds a mail for notifying user about an issue update
|
||
|
def issue_edit(user, journal)
|
||
|
def issue_edit(user, journal, att=false)
|
||
|
issue = journal.journalized
|
||
|
redmine_headers 'Project' => issue.project.identifier,
|
||
|
'Issue-Tracker' => issue.tracker.name,
|
||
| ... | ... | |
|
@journal = journal
|
||
|
@journal_details = journal.visible_details
|
||
|
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}")
|
||
|
@att = att
|
||
|
mail :to => user,
|
||
|
:subject => s
|
||
| ... | ... | |
|
journal.notes? || journal.visible_details(user).any?
|
||
|
end
|
||
|
users.each do |user|
|
||
|
issue_edit(user, journal).deliver_later
|
||
|
issue_edit(user, journal, journal.issue.attachments_visible?(user)).deliver_later
|
||
|
end
|
||
|
end
|
||
| app/views/issues/_edit.html.erb | ||
|---|---|---|
|
<%= call_hook(:view_issues_edit_notes_bottom, { :issue => @issue, :notes => @notes, :form => f }) %>
|
||
|
</fieldset>
|
||
|
<fieldset><legend><%= l(:label_attachment_plural) %></legend>
|
||
|
<% if @issue.attachments.any? && @issue.safe_attribute?('deleted_attachment_ids') %>
|
||
|
<fieldset id="attachments_form" style="<%= "display: none;" unless @issue.attachments_addable?(User.current) %>"><legend><%= l(:label_attachment_plural) %></legend>
|
||
|
<% if @attachments.any? && @issue.safe_attribute?('deleted_attachment_ids') %>
|
||
|
<div class="contextual"><%= link_to l(:label_edit_attachments), '#', :onclick => "$('#existing-attachments').toggle(); return false;" %></div>
|
||
|
<div id="existing-attachments" style="<%= @issue.deleted_attachment_ids.blank? ? 'display:none;' : '' %>">
|
||
|
<% @issue.attachments.each do |attachment| %>
|
||
|
<% @attachments.each do |attachment| %>
|
||
|
<span class="existing-attachment">
|
||
|
<%= text_field_tag '', attachment.filename, :class => "icon icon-attachment filename", :disabled => true %>
|
||
|
<label>
|
||
| app/views/issues/edit.js.erb | ||
|---|---|---|
|
<% else %>
|
||
|
$('#log_time').hide();
|
||
|
<% end %>
|
||
|
<% if @issue.attachments_addable?(User.current) %>
|
||
|
$('#attachments_form').show();
|
||
|
<% else %>
|
||
|
$('#attachments_form').hide();
|
||
|
<% end %>
|
||
| app/views/issues/index.api.rsb | ||
|---|---|---|
|
api.array :attachments do
|
||
|
issue.attachments.each do |attachment|
|
||
|
render_api_attachment(attachment, api)
|
||
|
end
|
||
|
end if issue.attachments_visible?
|
||
|
end if include_in_api_response?('attachments')
|
||
|
api.array :relations do
|
||
| app/views/issues/new.html.erb | ||
|---|---|---|
|
</p>
|
||
|
<% end %>
|
||
|
<% if @copy_from && @copy_from.attachments.any? %>
|
||
|
<p>
|
||
|
<p style="<%= "display: none;" unless @copy_from.attachments_visible?(User.current) && @issue.attachments_addable?(User.current) %>">
|
||
|
<label for="copy_attachments"><%= l(:label_copy_attachments) %></label>
|
||
|
<%= check_box_tag 'copy_attachments', '1', @copy_attachments %>
|
||
|
</p>
|
||
| ... | ... | |
|
</p>
|
||
|
<% end %>
|
||
|
<p id="attachments_form"><label><%= l(:label_attachment_plural) %></label><%= render :partial => 'attachments/form', :locals => {:container => @issue} %></p>
|
||
|
<p id="attachments_form" style="<%= "display: none;" unless @issue.attachments_addable?(User.current) %>"><label><%= l(:label_attachment_plural) %></label><%= render :partial => 'attachments/form', :locals => {:container => @issue} %></p>
|
||
|
<div id="watchers_form_container">
|
||
|
<%= render :partial => 'issues/watchers_form' %>
|
||
| app/views/issues/new.js.erb | ||
|---|---|---|
|
<% when "issue_category_id" %>
|
||
|
$('#issue_assigned_to_id').find('option').first().html('<%= escape_javascript(@issue.category.try(:assigned_to).try(:name)).presence || ' '.html_safe %>');
|
||
|
<% end %>
|
||
|
<% if @issue.attachments_addable?(User.current) %>
|
||
|
<% if @copy_from && @copy_from.attachments_visible?(User.current) %>
|
||
|
$('#copy_attachments').parent().show();
|
||
|
<% else %>
|
||
|
$('#copy_attachments').parent().hide();
|
||
|
<% end %>
|
||
|
$('#attachments_form').show();
|
||
|
<% else %>
|
||
|
$('#copy_attachments').parent().hide();
|
||
|
$('#attachments_form').hide();
|
||
|
<% end %>
|
||
| app/views/issues/show.api.rsb | ||
|---|---|---|
|
render_api_issue_children(@issue, api) if include_in_api_response?('children')
|
||
|
api.array :attachments do
|
||
|
@issue.attachments.each do |attachment|
|
||
|
@attachments.each do |attachment|
|
||
|
render_api_attachment(attachment, api)
|
||
|
end
|
||
|
end if include_in_api_response?('attachments')
|
||
| app/views/issues/show.html.erb | ||
|---|---|---|
|
<p><strong><%=l(:field_description)%></strong></p>
|
||
|
<div class="wiki">
|
||
|
<%= textilizable @issue, :description, :attachments => @issue.attachments %>
|
||
|
<%= textilizable @issue, :description, :attachments => @attachments %>
|
||
|
</div>
|
||
|
</div>
|
||
|
<% end %>
|
||
|
<% if @issue.attachments.any? %>
|
||
|
<% if @attachments.any? %>
|
||
|
<hr />
|
||
|
<p><strong><%=l(:label_attachment_plural)%></strong></p>
|
||
|
<%= link_to_attachments @issue, :thumbnails => true %>
|
||
| app/views/mailer/_issue.html.erb | ||
|---|---|---|
|
<%= textilizable(issue, :description, :only_path => false) %>
|
||
|
<% if issue.attachments.any? %>
|
||
|
<% if issue.attachments.any? && @att %>
|
||
|
<fieldset class="attachments"><legend><%= l(:label_attachment_plural) %></legend>
|
||
|
<% issue.attachments.each do |attachment| %>
|
||
|
<%= link_to_attachment attachment, :download => true, :only_path => false %>
|
||
| app/views/mailer/_issue.text.erb | ||
|---|---|---|
|
----------------------------------------
|
||
|
<%= issue.description %>
|
||
|
<% if issue.attachments.any? -%>
|
||
|
<% if issue.attachments.any? && @att -%>
|
||
|
---<%= l(:label_attachment_plural).ljust(37, '-') %>
|
||
|
<% issue.attachments.each do |attachment| -%>
|
||
|
<%= attachment.filename %> (<%= number_to_human_size(attachment.filesize) %>)
|
||
| app/views/roles/_form.html.erb | ||
|---|---|---|
|
<div id="role-permissions-trackers" class="view_issues_shown">
|
||
|
<h3><%= l(:label_issue_tracking) %></h3>
|
||
|
<% permissions = [:view_issues, :add_issues, :edit_issues, :add_issue_notes, :delete_issues] & setable_permissions.collect(&:name) %>
|
||
|
<% permissions = [:view_issues, :add_issues, :edit_issues, :add_issue_notes, :delete_issues, :view_attachments, :add_attachments, :edit_attachments, :delete_attachments] & setable_permissions.collect(&:name) %>
|
||
|
<div class="autoscroll">
|
||
|
<table class="list">
|
||
| config/locales/en.yml | ||
|---|---|---|
|
permission_view_private_notes: View private notes
|
||
|
permission_set_notes_private: Set notes as private
|
||
|
permission_delete_issues: Delete issues
|
||
|
permission_view_attachments: View attachments
|
||
|
permission_add_attachments: Add attachments
|
||
|
permission_edit_attachments: Edit attachments
|
||
|
permission_delete_attachments: Delete attachments
|
||
|
permission_manage_public_queries: Manage public queries
|
||
|
permission_save_queries: Save queries
|
||
|
permission_view_gantt: View gantt chart
|
||
| config/locales/pt-BR.yml | ||
|---|---|---|
|
permission_manage_members: Gerenciar membros
|
||
|
permission_edit_messages: Editar mensagens
|
||
|
permission_delete_issues: Excluir tarefas
|
||
|
permission_view_attachments: Ver arquivos anexos
|
||
|
permission_add_attachments: Adicionar arquivos anexos
|
||
|
permission_edit_attachments: Editar arquivos anexos
|
||
|
permission_delete_attachments: Apagar arquivos anexos
|
||
|
permission_view_issue_watchers: Ver lista de observadores
|
||
|
permission_manage_repository: Gerenciar repositório
|
||
|
permission_commit_access: Acesso do commit
|
||
| db/migrate/20161215142110_add_attachments_permissions.rb | ||
|---|---|---|
|
class AddAttachmentsPermissions < ActiveRecord::Migration[4.2]
|
||
|
def self.up
|
||
|
Role.all.each do |r|
|
||
|
r.add_permission!(:view_attachments) if r.has_permission?(:view_issues)
|
||
|
r.add_permission!(:add_attachments) if r.has_permission?(:add_issues)
|
||
|
r.add_permission!(:edit_attachments) if r.has_permission?(:edit_issues)
|
||
|
r.add_permission!(:delete_attachments) if r.has_permission?(:delete_issues)
|
||
|
end
|
||
|
end
|
||
|
def self.down
|
||
|
Role.all.each do |r|
|
||
|
r.remove_permission!(:view_attachments)
|
||
|
r.remove_permission!(:add_attachments)
|
||
|
r.remove_permission!(:edit_attachments)
|
||
|
r.remove_permission!(:delete_attachments)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb | ||
|---|---|---|
|
r |= fetch_ranks_and_ids(
|
||
|
search_scope(user, projects, options).
|
||
|
joins(:attachments).
|
||
|
where("#{Project.allowed_to_condition(user, :view_attachments)}", false).
|
||
|
where(search_tokens_condition(["#{Attachment.table_name}.filename", "#{Attachment.table_name}.description"], tokens, options[:all_words])),
|
||
|
options[:limit]
|
||
|
)
|
||
| lib/redmine.rb | ||
|---|---|---|
|
:queries => :index,
|
||
|
:reports => [:issue_report, :issue_report_details]},
|
||
|
:read => true
|
||
|
map.permission :add_issues, {:issues => [:new, :create], :attachments => :upload}
|
||
|
map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update], :journals => [:new], :attachments => :upload}
|
||
|
map.permission :edit_own_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update], :journals => [:new], :attachments => :upload}
|
||
|
map.permission :copy_issues, {:issues => [:new, :create, :bulk_edit, :bulk_update], :attachments => :upload}
|
||
|
map.permission :add_issues, {:issues => [:new, :create]}
|
||
|
map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update], :journals => [:new]}
|
||
|
map.permission :edit_own_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update], :journals => [:new]}
|
||
|
map.permission :copy_issues, {:issues => [:new, :create, :bulk_edit, :bulk_update]}
|
||
|
map.permission :manage_issue_relations, {:issue_relations => [:index, :show, :create, :destroy]}
|
||
|
map.permission :manage_subtasks, {}
|
||
|
map.permission :set_issues_private, {}
|
||
|
map.permission :set_own_issues_private, {}, :require => :loggedin
|
||
|
map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload}
|
||
|
map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new]}
|
||
|
map.permission :edit_issue_notes, {:journals => [:edit, :update]}, :require => :loggedin
|
||
|
map.permission :edit_own_issue_notes, {:journals => [:edit, :update]}, :require => :loggedin
|
||
|
map.permission :view_private_notes, {}, :read => true, :require => :member
|
||
|
map.permission :set_notes_private, {}, :require => :member
|
||
|
map.permission :delete_issues, {:issues => :destroy}, :require => :member
|
||
|
# Attachments
|
||
|
map.permission :add_attachments, {:attachments => :upload}
|
||
|
map.permission :view_attachments, {}
|
||
|
map.permission :edit_attachments, {}
|
||
|
map.permission :delete_attachments, {:attachments => :destroy}, :require => :member
|
||
|
# Watchers
|
||
|
map.permission :view_issue_watchers, {}, :read => true
|
||
|
map.permission :add_issue_watchers, {:watchers => [:new, :create, :append, :autocomplete_for_user]}
|
||
| lib/redmine/export/pdf/issues_pdf_helper.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
if issue.attachments.any?
|
||
|
if issue.attachments.any? && issue.attachments_visible?(User.current)
|
||
|
pdf.SetFontStyle('B',9)
|
||
|
pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
|
||
|
pdf.ln
|
||