Skip to content

Commit

Permalink
complite
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Brodnitskiy committed Feb 18, 2013
1 parent 2e41099 commit 463ad68
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 8 deletions.
23 changes: 23 additions & 0 deletions lib/patches/redmine_attachments_helper_incognito_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module RedmineAttachmentsHelperIncognitoPatch
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
alias_method_chain :link_to_attachments, :incognito
end
end

module InstanceMethods
def link_to_attachments_with_incognito(container, options = {})
options.assert_valid_keys(:author, :thumbnails)

project = params[:project_id] ? Project.find(params[:project_id]) : Issue.find(params[:id]).project if params[:controller] == 'issues'
if container.attachments.any? && User.current.allowed_to?(:no_show_names, project) && !User.current.admin?
options = {:deletable => container.attachments_deletable?, :author => false}.merge(options)
render :partial => 'attachments/links',
:locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)}
else
link_to_attachments_without_incognito(container, options)
end
end
end
end
7 changes: 7 additions & 0 deletions lib/patches/redmine_group_incognito_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module RedmineGroupIncognitoPatch
def self.included(base)
base.class_eval do

end
end
end
34 changes: 34 additions & 0 deletions lib/patches/redmine_issues_helper_incognito_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module RedmineIssuesHelperIncognitoPatch
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
alias_method_chain :find_name_by_reflection, :incognito
end
end

module InstanceMethods
def find_name_by_reflection_with_incognito(field, id)
association = Issue.reflect_on_association(field.to_sym)
if association
record = association.class_name.constantize.find_by_id(id)

if record
if field == 'assigned_to'
if params[:controller] == 'issues'
project = params[:project_id] ? Project.find(params[:project_id]) : Issue.find(params[:id]).project
elsif params[:controller] == 'projects'
project = Project.find(params[:id])
end

if User.current.allowed_to?(:no_show_names, project) && !User.current.admin? && params[:controller] = 'issues'||'projects'
return record.roles_for_project(project).collect{|role| "#{role.name}" }.join(' ')
end
end
find_name_by_reflection_without_incognito(field, id)
end

end
end

end
end
31 changes: 31 additions & 0 deletions lib/patches/redmine_queries_helper_incognito_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module RedmineQueriesHelperIncognitoPatch
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
alias_method_chain :retrieve_query, :incognito
end
end

module InstanceMethods

def retrieve_query_with_incognito
retrieve_query_without_incognito
if params[:controller] == 'issues'
project = params[:project_id] ? Project.find(params[:project_id]) : Issue.find(params[:id]).project
elsif params[:controller] == 'projects'
project = Project.find(params[:id])
end

if User.current.allowed_to?(:no_show_names, project) && !User.current.admin?
af = @query.available_filters
%w(author_id assigned_to_id assigned_to_role watcher_id member_of_group).each do |filter|
af.delete(filter)
@query.available_filters = af
end
else
retrieve_query_without_incognito
end
end

end
end
11 changes: 11 additions & 0 deletions lib/patches/redmine_query_incognito_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module RedmineQueryIncognitoPatch
def self.included(base)
base.class_eval do

def available_filters=(value)
@available_filters = value
end

end
end
end
15 changes: 7 additions & 8 deletions lib/patches/redmine_user_incognito_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
alias_method_chain :link_to_user , :incognito

end
end

module InstanceMethods
def link_to_user_with_incognito(user, options={})
p "params======================================="
p params

if user == User.current || User.current.admin?
link_to_user_without_incognito(user, options)

elsif user.is_a?(Group)
'Group'

'is a Group'
elsif user.is_a?(User)

if params[:controller] == 'issues'
Expand All @@ -25,20 +24,20 @@ def link_to_user_with_incognito(user, options={})
end

if User.current.allowed_to?(:no_show_names, project)

case params[:controller]
when 'projects'
user.roles_for_project(project).collect{|role| "#{role.name}" }.join(' ')
when'issues'
when 'issues'
user.roles_for_project(project).collect{|role| "#{role.name}" }.join(' ')
else
'left controller'
end

else
"my option disabled"
""
end

else
"no USER no GROUP"
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions lib/redmine_user_incognito.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
require 'patches/redmine_user_incognito_patch'
require 'patches/redmine_issues_helper_incognito_patch'
require 'patches/redmine_query_incognito_patch'
require 'patches/redmine_queries_helper_incognito_patch'
require 'patches/redmine_attachments_helper_incognito_patch'

Rails.configuration.to_prepare do
ApplicationHelper.send(:include, RedmineUserIncognitoPatch)
IssuesHelper.send(:include, RedmineIssuesHelperIncognitoPatch)
Query.send(:include, RedmineQueryIncognitoPatch)
QueriesHelper.send(:include, RedmineQueriesHelperIncognitoPatch)
AttachmentsHelper.send(:include, RedmineAttachmentsHelperIncognitoPatch)


end

0 comments on commit 463ad68

Please sign in to comment.