ref: master
plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
class RequireAuthToCommentPlugin < Noosfero::Plugin include ActionView::Helpers::TagHelper include ActionView::Helpers::FormTagHelper include FormsHelper def self.plugin_name "RequireAuthToCommentPlugin" end def self.plugin_description _("Requires users to authenticate in order to post comments.") end def filter_comment(c) c.reject! unless logged_in? || allowed_by_profile end def profile_editor_extras lambda do render 'require_auth_to_comment/profile_editor_extras' end end def stylesheet? !display_login_popup? end def display_login_popup? settings = Noosfero::Plugin::Settings.new(environment, self.class) settings.require_type == 'display_login_popup' end def self.require_type_default_setting 'hide_button' end def js_files ['hide_comment_form.js', 'jquery.livequery.min.js'] + (display_login_popup? ? ['comment_require_login.js'] : []) end def body_beginning tag :meta, name: 'profile.allow_unauthenticated_comments' if allowed_by_profile end protected def logged_in? context.send(:logged_in?) end def allowed_by_profile context.profile && context.profile.allow_unauthenticated_comments end end |