Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 89a8aecade402965517fd3fe59e4e51d03e12f5b @jkraemer jkraemer committed May 10, 2012
@@ -0,0 +1,63 @@
+= RedmineLocalAvatars
+
+This plugin allows Redmine users to upload a picture to be used as
+an avatar (instead of depending on images from Gravatar).
+
+Users can set their image through the /my/account page. The administrator
+can also manage users' avatars through the /users section.
+
+== Installation
+
+Simply place the plugin in the vendors/plugins directory of your Redmine
+installation (or create a symlink).
+
+== Compatibility
+
+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:
+* http://www.redmine.org/boards/3/topics/5365
+* https://github.com/Ubik/redmine_local_avatars
+
+Luca Pireddu <pireddu@gmail.com> at CRS4 (http://www.crs4.it),
+contributed updates and improvements.
+
+
+== Warranty. What warranty?
+
+This plugin was written for use in an intranet with simple requirements in
+mind. In particular, not much attention has been payed to security issues
+and there hasn't been any thorough testing. Use it at your own risk.
+Patches are welcome.
+
+
+== Implementation Notes
+
+Avatar images are treated as attachments to User objects
+with the description 'avatar'. The AccountController is patched
+to provide the images, and the UsersController and MyController are
+patched to provide mechanisms to add/delete avatars.
+
+
+== License
+
+Copyright (C) 2010 Andrew Chaika, Luca Pireddu
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@@ -0,0 +1 @@
+- <%= link_to(l(:button_change_avatar), :action => 'avatar') %>
@@ -0,0 +1,11 @@
+<div class="box">
+<h3><%= l(:label_avatar)%></h3>
+<div style="width: 128px; height: 128px; border: 1px silver solid;">
+<%= avatar(@user, :size => "128") %>
+</div><br>
+<% form_tag( { :action => 'save_avatar', :id => @user }, :multipart => true) do %>
+ <%= file_field_tag "avatar" %><br />
+ <%= submit_tag l(:button_save) %>
+ <%= submit_tag l(:button_delete), :confirm => l(:are_you_sure_delete_avatar) %>
+<% end %>
+</div>
@@ -0,0 +1,9 @@
+# Bulgarian translation by Ivan Cenov
+# https://bugs.launchpad.net/redminelocalavatars/+bug/887451
+bg:
+ label_avatar: "Аватар"
+ message_avatar_uploaded: "Аватарът е зареден успешно"
+ button_change_avatar: "Промяна на локален аватар"
+ are_you_sure_delete_avatar: "Сигурен ли сте, че искате да изтриете Вашия аватар?"
+ avatar_deleted: "Аватарът е изтрит"
+ unable_to_delete_avatar: "Грешка при опит за изтриване на аватара"
@@ -0,0 +1,10 @@
+# German translation by cforce
+# https://bugs.launchpad.net/redminelocalavatars/+bug/680548
+
+de:
+ label_avatar: "Avatar"
+ message_avatar_uploaded: "Avatar erfolgreich hochgeladen"
+ button_change_avatar: "Avatar anpassen"
+ are_you_sure_delete_avatar: "Wollen Sie den Avatar entfernen?"
+ avatar_deleted: "Avatar entfernt."
+ unable_to_delete_avatar: "Leider ist beim Löschen des Avatars ein Problem aufgetreten!"
@@ -0,0 +1,8 @@
+# English strings go here
+en:
+ label_avatar: "Avatar"
+ message_avatar_uploaded: "Avatar uploaded successfully"
+ button_change_avatar: "Change local avatar"
+ are_you_sure_delete_avatar: "Are you sure you want to delete your avatar?"
+ avatar_deleted: "Avatar deleted"
+ unable_to_delete_avatar: "Sorry. There was an error deleting the avatar"
@@ -0,0 +1,10 @@
+# Spanish strings go here
+# Courtesy of Anibal Avelar
+# https://bugs.launchpad.net/redminelocalavatars/+bug/716663
+es:
+ label_avatar: "Avatar"
+ message_avatar_uploaded: "Avatar descargado exitosamente"
+ button_change_avatar: "Cambiar avatar"
+ are_you_sure_delete_avatar: "¿Estas seguro que quieres borrar tu avatar?"
+ avatar_deleted: "Avatar borrado"
+ unable_to_delete_avatar: "Lo sentimos. Hubo un error borrando el avatar"
@@ -0,0 +1,9 @@
+# French translation courtesy of luigifab
+# https://bugs.launchpad.net/redminelocalavatars/+bug/692969
+fr:
+ label_avatar: "Avatar"
+ message_avatar_uploaded: "Avatar enregistré"
+ button_change_avatar: "Modifier l'avatar"
+ are_you_sure_delete_avatar: "Êtes-vous certain de vouloir supprimer votre avatar?"
+ avatar_deleted: "Avatar supprimé"
+ unable_to_delete_avatar: "Une erreur est survenue lors de la suppression de l'avatar."
@@ -0,0 +1,8 @@
+# Italian strings go here
+it:
+ label_avatar: Immagine
+ message_avatar_uploaded: Immagine salvata
+ button_change_avatar: Cambia la tua immagine
+ are_you_sure_delete_avatar: "Sicuro di volere eliminare l'immagine?"
+ avatar_deleted: Immagine eliminata
+ unable_to_delete_avatar: "Mi dispiace. C'è stato un error eliminando l'immagine"
@@ -0,0 +1,9 @@
+# Portugues Brazil strings go here
+# Courtesy of Felipe Pinheiro
+pt-BR:
+ label_avatar: "Avatar"
+ message_avatar_uploaded: "Avatar carregado com sucesso"
+ button_change_avatar: "Mude sua imagem de exibição."
+ are_you_sure_delete_avatar: "Voc tem certeza que deseja apagar seu avatar?"
+ avatar_deleted: "Avatar apagado"
+ unable_to_delete_avatar: "Desculpe. Houve um erro apagando o avatar."
@@ -0,0 +1,7 @@
+ru:
+ label_avatar: "Фотография"
+ message_avatar_uploaded: "Фотография загружена на сервер"
+ button_change_avatar: "Изменить фотографию"
+ are_you_sure_delete_avatar: "Вы действительно хотите удалить свою фотографию?"
+ avatar_deleted: "Фотография удалена"
+ unable_to_delete_avatar: "При удалении фотографии произошла ошибка"
@@ -0,0 +1,8 @@
+# Simplified Chinese strings go here
+zh-TW:
+ label_avatar: "頭像"
+ message_avatar_uploaded: "成功上傳頭像"
+ button_change_avatar: "更改頭像"
+ are_you_sure_delete_avatar: "確定刪除頭像嗎?"
+ avatar_deleted: "頭像已刪除"
+ unable_to_delete_avatar: "對不起,刪除頭像發生錯誤"
@@ -0,0 +1,8 @@
+# Simplified Chinese strings go here
+zh:
+ label_avatar: "头像"
+ message_avatar_uploaded: "成功上传头像"
+ button_change_avatar: "更改头像"
+ are_you_sure_delete_avatar: "确定删除头像吗?"
+ avatar_deleted: "头像已删除"
+ unable_to_delete_avatar: "对不起,删除头像发生错误"
@@ -0,0 +1,7 @@
+ActionController::Routing::Routes.draw do |map|
+ map.connect 'my/avatar', :controller => 'my', :action => 'avatar', :conditions => {:method => [:get, :post]}
+ map.connect 'my/save_avatar/:id', :controller => 'my', :action => 'save_avatar', :id=>/\d+/, :conditions => {:method => [:get, :post]}
+ map.connect 'account/get_avatar/:id', :controller => 'account', :action => 'get_avatar', :id=>/\d+/, :conditions => {:method => [:get, :post]}
+ map.connect 'users/save_avatar/:id', :controller => 'users', :action => 'save_avatar', :id=>/\d+/, :conditions => {:method => [:get, :post]}
+ map.connect 'users/get_avatar/:id', :controller => 'users', :action => 'get_avatar', :id=>/\d+/, :conditions => {:method => [:get, :post]}
+end
52 init.rb
@@ -0,0 +1,52 @@
+# Redmine Local Avatars plugin
+#
+# Copyright (C) 2010 Andrew Chaika, Luca Pireddu
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require 'redmine'
+
+Redmine::Plugin.register :redmine_local_avatars do
+ name 'Redmine Local Avatars plugin'
+ author 'Andrew Chaika and Luca Pireddu'
+ description 'This plugin lets users upload avatars directly into Redmine'
+ version '0.1.1'
+end
+require 'dispatcher'
+
+Dispatcher.to_prepare(:redmine_local_avatars_prep) do
+ require_dependency 'principal'
+ require_dependency 'user'
+
+ AccountController.send(:include, LocalAvatarsPlugin::AccountControllerPatch)
+ ApplicationHelper.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'
+
+# 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
+
+# hooks
+require 'redmine_local_avatars/hooks'
@@ -0,0 +1,38 @@
+# Redmine Local Avatars plugin
+#
+# Copyright (C) 2010 Andrew Chaika, Luca Pireddu
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# 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 AccountControllerPatch
+
+ def self.included(base) # :nodoc:
+ base.class_eval do
+ helper :attachments
+ include AttachmentsHelper
+ end
+ end
+
+ include LocalAvatars
+
+ def get_avatar
+ @user = User.find(params[:id])
+ send_avatar(@user)
+ end
+ end
+end
@@ -0,0 +1,41 @@
+# Redmine Local Avatars plugin
+#
+# Copyright (C) 2010 Andrew Chaika, Luca Pireddu
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# 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
+ def self.included(base) # :nodoc:
+ base.class_eval do
+ alias_method_chain :avatar, :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 => false, :controller => 'account', :action => 'get_avatar', :id => user
+ options[:size] = "64" unless options[:size]
+ return "<img class=\"gravatar\" width=\"#{options[:size]}\" height=\"#{options[:size]}\" src=\"#{image_url}\" />"
+ end
+ end
+ avatar_without_local(user, options)
+ end
+ end
+end
@@ -0,0 +1,52 @@
+# Redmine Local Avatars plugin
+#
+# Copyright (C) 2010 Andrew Chaika, Luca Pireddu
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# 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'
+ send_file(av.diskfile, :filename => filename_for_content_disposition(av.filename),
+ :type => av.content_type,
+ :disposition => (av.image? ? 'inline' : 'attachment')) if av
+ end
+
+ # expects @user to be set.
+ # In case of error, raises an exception and sets @possible_error
+ def save_or_delete
+ # clear the attachments. Then, save if
+ # we have to delete. Otherwise add the new
+ # avatar and then save
+ # TODO: This doesn't play nice with any other possible
+ # attachments on the user (just because there aren't any
+ # now doesn't mean there won't be in the future. It should
+ # be changed to only remove an attachment with description == 'avatar'
+ @user.attachments.clear
+ if params[:commit] == l(:button_delete) then
+ @possible_error = l(:unable_to_delete_avatar)
+ @user.save!
+ flash[:notice] = l(:avatar_deleted)
+ else # take anything else as save
+ file_field = params[:avatar]
+ Attachment.attach_files(@user, {'first' => {'file' => file_field, 'description' => 'avatar'}})
+ @possible_error = l(:error_saving_avatar)
+ @user.save!
+ flash[:notice] = l(:message_avatar_uploaded)
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 89a8aec

Please sign in to comment.