Skip to content

Commit

Permalink
Merge pull request #33 from aki360P/master
Browse files Browse the repository at this point in the history
Redmine 5.0 compatible
  • Loading branch information
dup2 authored Oct 3, 2023
2 parents 468d5f2 + 2cbd212 commit aa19644
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 63 deletions.
17 changes: 0 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ rake redmine:plugins:migrate RAILS_ENV=production
And restart your application server.


## Compatibility

This current version on github is compatible with Redmine 2.1 - 4.2.

It has been imported from lp:redminelocalavatars
incorporating the patch for 2.1 from chrisy at [https://bugs.launchpad.net/redminelocalavatars/+bug/1069808/comments/4](https://bugs.launchpad.net/redminelocalavatars/+bug/1069808/comments/4)

### Incompatibilities

As reported in [issue #12](https://github.com/ncoders/redmine_local_avatars/issues/12), the plugin "mega_calendar" ist not compatible with this plugin due to an issue with the provided users_controller_path.rb file.

### Old version on launchpad
Tested on Redmine trunk r4388 (version 1.0.3). Should be compatible with
all Redmine versions 1.0.x.

At the moment the plugin doesn't work when running in development mode.

## Authors

* A.Chaika wrote the original version:
Expand Down
33 changes: 10 additions & 23 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,21 @@
author 'Andrew Chaika and Luca Pireddu'
author_url 'https://github.com/ncoders/redmine_local_avatars'
description 'This plugin lets users upload avatars directly into Redmine'
version '1.0.6'
version '1.0.7'
requires_redmine version_or_higher: '4.1'
end

receiver = Object.const_defined?('ActiveSupport::Reloader') ? ActiveSupport::Reloader : ActionDispatch::Callbacks
receiver.to_prepare do
require_dependency 'project'
require_dependency 'principal'
require_dependency 'user'

helper_klass = ApplicationHelper.method_defined?(:avatar) ? ApplicationHelper : AvatarsHelper

AccountController.send(:include, LocalAvatarsPlugin::AccountControllerPatch)
helper_klass.send(:include, LocalAvatarsPlugin::ApplicationAvatarPatch)
MyController.send(:include, LocalAvatarsPlugin::MyControllerPatch)
User.send(:include, LocalAvatarsPlugin::UsersAvatarPatch)
UsersController.send(:include, LocalAvatarsPlugin::UsersControllerPatch)
UsersHelper.send(:include, LocalAvatarsPlugin::UsersHelperPatch)
end

require 'local_avatars'
require File.expand_path('../lib/local_avatars', __FILE__)

# patches to Redmine
require "account_controller_patch.rb"
require "application_helper_avatar_patch.rb"
require "my_controller_patch.rb"
require "users_avatar_patch.rb" # User model
require "users_controller_patch.rb"
require "users_helper_avatar_patch.rb" # UsersHelper
require File.expand_path('../lib/account_controller_patch', __FILE__)
require File.expand_path('../lib/application_helper_avatar_patch', __FILE__)
require File.expand_path('../lib/my_controller_patch', __FILE__)
require File.expand_path('../lib/users_avatar_patch', __FILE__) # User model
require File.expand_path('../lib/users_controller_patch', __FILE__)
require File.expand_path('../lib/users_helper_avatar_patch', __FILE__) # UsersHelper

# hooks
require 'redmine_local_avatars/hooks'
require File.expand_path('../lib/redmine_local_avatars/hooks', __FILE__)
8 changes: 5 additions & 3 deletions lib/account_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

require 'local_avatars'

module LocalAvatarsPlugin
require File.expand_path('../local_avatars', __FILE__)

module AccountControllerPatch

def self.included(base) # :nodoc:
Expand All @@ -34,5 +34,7 @@ def get_avatar
@user = User.find(params[:id])
send_avatar(@user)
end

end
end

AccountController.include(AccountControllerPatch)
13 changes: 8 additions & 5 deletions lib/application_helper_avatar_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,31 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

require 'local_avatars'

module LocalAvatarsPlugin
module ApplicationAvatarPatch
module ApplicationHelperAvatarPatch

def self.included(base) # :nodoc:
base.class_eval do
alias_method :avatar_without_local, :avatar
alias_method :avatar, :avatar_with_local
end
end


def avatar_with_local(user, options = { })
if user.is_a?(User)then
av = user.attachments.find_by_description 'avatar'
if av then
image_url = url_for :only_path => true, :controller => 'account', :action => 'get_avatar', :id => user
options[:size] = "64" unless options[:size]
options[:size] = "24" unless options[:size]
title = "#{user.name}"
return "<img class=\"gravatar\" title=\"#{title}\" width=\"#{options[:size]}\" height=\"#{options[:size]}\" src=\"#{image_url}\" />".html_safe
end
end
avatar_without_local(user, options)
end


end
end

AvatarsHelper.include(ApplicationHelperAvatarPatch)
4 changes: 2 additions & 2 deletions lib/local_avatars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

module LocalAvatarsPlugin

module LocalAvatars
def send_avatar(user)
av = user.attachments.find_by_description 'avatar'
Expand Down Expand Up @@ -49,4 +49,4 @@ def save_or_delete
end
end
end
end

6 changes: 3 additions & 3 deletions lib/my_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

require 'local_avatars'
require File.expand_path('../local_avatars', __FILE__)

module LocalAvatarsPlugin
module MyControllerPatch
def self.included(base) # :nodoc:
base.class_eval do
Expand All @@ -45,5 +44,6 @@ def save_avatar
end
end
end
end


MyController.include(MyControllerPatch)
7 changes: 4 additions & 3 deletions lib/users_avatar_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

require 'local_avatars'

module LocalAvatarsPlugin


module UsersAvatarPatch
def self.included(base) # :nodoc:
base.class_eval do
acts_as_attachable
end
end
end
end


User.include(UsersAvatarPatch)
6 changes: 3 additions & 3 deletions lib/users_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

require 'local_avatars'

module LocalAvatarsPlugin
require File.expand_path('../local_avatars', __FILE__)

module UsersControllerPatch

def self.included(base) # :nodoc:
Expand Down Expand Up @@ -46,5 +46,5 @@ def save_avatar
redirect_to :action => 'edit', :id => @user
end
end
end

UsersController.include(UsersControllerPatch)
9 changes: 5 additions & 4 deletions lib/users_helper_avatar_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

require 'local_avatars'

module LocalAvatarsPlugin
module UsersHelperPatch


module UsersHelperAvatarPatch
def self.included(base) # :nodoc:
base.class_eval do
alias_method :user_settings_tabs_without_avatar, :user_settings_tabs
Expand All @@ -32,5 +32,6 @@ def user_settings_tabs_with_avatar
tabs << {:name => 'avatar', :partial => 'my/avatar', :label => :label_avatar}
end
end
end


UsersHelper.include(UsersHelperAvatarPatch)

0 comments on commit aa19644

Please sign in to comment.