Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't enable badge for one user but works when enabled for all #97

Closed
Henderxx opened this issue Jul 23, 2019 · 30 comments
Closed

can't enable badge for one user but works when enabled for all #97

Henderxx opened this issue Jul 23, 2019 · 30 comments
Assignees

Comments

@Henderxx
Copy link

Hello i've just installed aand i got little error, i've tried to enable plugin for some users but the checkbox will drop selection as i save settings and still be unchecked. But when i enabled plugin in plugin settings for all users it just works with standard options therefore i cannot change any setting again in my profile page
I'm using
Redmine version 4.0.1.stable
Ruby version 2.4.5-p335 (2018-10-18) [i386-mingw32]
Rails version 5.2.2

all installed with bitnami on windows machine

@akiko-pusu
Copy link
Owner

Hi, thanks for trying this plugin and reporting issue.
Could you please give me the plugin's version?

@Henderxx
Copy link
Author

Hi it is v0.1.0, latest from here

@akiko-pusu
Copy link
Owner

@Henderxx Thanks for this information. I'll check it.

@akiko-pusu akiko-pusu self-assigned this Jul 25, 2019
@akiko-pusu
Copy link
Owner

akiko-pusu commented Jul 27, 2019

Could you please tell me if you use any other plugins? Also what is the database engine you use?
Related: #96

@Henderxx
Copy link
Author

Sure, i have few other plugins and all is using Mysql database
Redmine plugins:
additionals 2.0.18
redmine_ckeditor 1.2.2
redmine_issue_badge 0.1.0
redmine_lightbox2 0.5.0
redmine_per_project_formatting 0.1.0
redmine_theme_changer 0.4.0

@akiko-pusu
Copy link
Owner

Sorry I could not reproduce this problem.
Are there any plugin that extend user profile like this issue badge plugin?

@Henderxx
Copy link
Author

Henderxx commented Aug 4, 2019

there is one, it's theme changer. it adds one option in users profile, allowing them to change how redmine looks. I'll try tomorrow in new installation of redmine with only issue badge plugin enabled if error exists. If you want some logs i can give them

@Henderxx
Copy link
Author

Henderxx commented Aug 6, 2019

Ok i did some test, i've installed redmine with bitnami on virtual windows machine, then added plugin and make bundle install and rake commands. All installed, then i tried to enable plugin for my admin account effect was the same, option checked but when i pressed save all is gone to defaults and unchecked. I tried it on firefox and then on chrome on both same results.

@mrniemand
Copy link

same problem here. I have no user profile extension plugin installed.
Plugins installed:
Redmine Auto Done
Redmine Issue Badge plugin
Redmine Lightbox 2

@akiko-pusu
Copy link
Owner

@mrniemand Thanks for additional information. It's variable for me.
Could you tell me what is the database engine you use?
Redmine's version, and your OS platform info is welcomed, as possible as you can.

@mrniemand
Copy link

Database: Mysql 5.5
Redmine: 4.0.4.stable
Ruby version 2.5.5-p157 (2019-03-15) [i386-mingw32]
Rails version 5.2.3
Environment production
Database adapter Mysql2

OS is Win7 32bit, redmine is installed manually. All users have been created before i installed the plugin.

@akiko-pusu
Copy link
Owner

akiko-pusu commented Aug 15, 2019

@mrniemand @Henderxx

I could not reproduce in the production env with mysql and using the same plugins....

Could you tell me which browser you use?
Does this defect happen with all the browsers? (Such as IE, Safari, Firefox)
Or only a specific browser?

And if you checked “Enabled” on user’s preference page, the request parameter is sent like this.

badge-enabled

@Henderxx
Copy link
Author

i've tried it on chrome and firefox, both had same issue. I'll try tomorrow on opera and maybe some others. Can you tell me is this plugin using some date and time format when request is send? i have seen some similiar problems on other few programs when date and time format where with different separators. my format is rrrr-MM-dd for short time format and d MMMM rrrr for long format

@mrniemand
Copy link

i used Internet Explorer.
In my database there is no entry for the user. When I add it manually i can change configuration there.

Still after adding the line manual no change within the redmine ui is stored there.

Redmine Log is correct and shows the new config:
arted POST "/my/account" for 10.100.134.93 at 2019-08-19 08:04:45 +0200
Processing by MyController#account as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"xxx", "user"=>{"firstname"=>"Andreas", "lastname"=>"xxx", "mail"=>"xxx", "language"=>"de", "mail_notification"=>"only_my_events", "notified_project_ids"=>[""]}, "commit"=>"Speichern", "pref"=>{"no_self_notified"=>"1", "hide_mail"=>"0", "time_zone"=>"Berlin", "comments_sorting"=>"asc", "warn_on_leaving_unsaved"=>"1", "textarea_font"=>""}, "issue_badge"=>{"show_assigned_to_group"=>"0", "badge_order"=>"newest"}}

@Henderxx
Copy link
Author

I got something like this. On Firefox request looks like this
obraz

and production.log shows

Processing by MyController#account as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"EG5MfFM7giZ/8CDutRIdh+Bv6uVaFaNI7/J0h3gk8TT+LBQE1jNOVsCc5VXwEMGo3J4xdhqnz32xSgUVleqRUg==", "user"=>{"firstname"=>"Heniek", "lastname"=>"Admin", "mail"=>"ser@mail.com", "language"=>"pl", "mail_notification"=>"all", "notified_project_ids"=>[""]}, "commit"=>"Zapisz", "pref"=>{"no_self_notified"=>"1", "hide_mail"=>"1", "time_zone"=>"", "comments_sorting"=>"asc", "warn_on_leaving_unsaved"=>"1", "textarea_font"=>""}, "issue_badge"=>{"enabled"=>"1", "show_assigned_to_group"=>"0", "badge_order"=>"oldest"}}

And on Chrome looks like that
obraz

And production log shows

Processing by MyController#account as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"zoRAdZ8LAR4+s4eh5B2jjVuh1EjGdw9jYC+TzMhUZPTDLN1JXMth0RMWVve626HNH8mCnDF4+lyUgWLBkkdBbA==", "user"=>{"firstname"=>"Heniek", "lastname"=>"Admin", "mail"=>"ser@mail.com", "language"=>"pl", "mail_notification"=>"all", "notified_project_ids"=>[""]}, "commit"=>"Zapisz", "pref"=>{"no_self_notified"=>"1", "hide_mail"=>"1", "time_zone"=>"", "comments_sorting"=>"asc", "warn_on_leaving_unsaved"=>"1", "textarea_font"=>""}, "issue_badge"=>{"enabled"=>"1", "show_assigned_to_group"=>"0", "badge_order"=>"oldest"}}

On Internet Explorer

obraz

Processing by MyController#account as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"cbcRm6VJlT+ea2vhtnY4mSGf4bgFKtZ3wiHUIK1mxQIknTorwbEErfFHnRVf5uLOm/v/OgDRWdf4jQFJxavBMA==", "user"=>{"firstname"=>"Heniek", "lastname"=>"Admin", "mail"=>"ser@mail.com", "language"=>"pl", "mail_notification"=>"all", "notified_project_ids"=>[""]}, "commit"=>"Zapisz", "pref"=>{"no_self_notified"=>"1", "hide_mail"=>"1", "time_zone"=>"", "comments_sorting"=>"asc", "warn_on_leaving_unsaved"=>"1", "textarea_font"=>""}, "issue_badge"=>{"enabled"=>"1", "show_assigned_to_group"=>"0", "badge_order"=>"oldest"}}

on all of them post result is 302. Opera same logs as others

obraz

@mrniemand
Copy link

i also get an HTTP Result 302.

@akiko-pusu
Copy link
Owner

@mrniemand @Henderxx Thanks a lot!!

@akiko-pusu
Copy link
Owner

@mrniemand @Henderxx
Hi, could you please try this patch if you can?

diff --git a/init.rb b/init.rb
index 2a5b4f4..c0d4212 100644
--- a/init.rb
+++ b/init.rb
@@ -51,6 +51,13 @@ Redmine::Plugin.register :redmine_issue_badge do
                'activate_for_all_users' => 'false',
                'enabled_polling' => false
              }
+
+    Rails.configuration.to_prepare do
+      require_dependency 'my_controller'
+      unless MyController.included_modules.include?(IssueBadge::MyControllerPatch)
+        MyController.prepend IssueBadge::MyControllerPatch
+      end
+    end
   rescue ::Redmine::PluginRequirementError => e
     raise ::Redmine::PluginRequirementError.new(issue_badge_version_message(e.message)) # rubocop:disable Style/RaiseArgs
   end
diff --git a/lib/issue_badge/my_controller_patch.rb b/lib/issue_badge/my_controller_patch.rb
index f1f2d83..7e61856 100644
--- a/lib/issue_badge/my_controller_patch.rb
+++ b/lib/issue_badge/my_controller_patch.rb
@@ -26,4 +26,3 @@ module IssueBadge
   end
 end
 
-MyController.prepend IssueBadge::MyControllerPatch

※ v0.1.x (Support Redmine3.x) was applied this workaround to prevent some conflict or unloaded issue. But I’m sorry I have not much experiences about Redmine4.x which running various environment, rails application server and so on.
So your information is quite helpful.

If above is effective, I’m going to apply soon.


And here is my log when submitting account setting,
Though rails env is development mode, IssueBadgeUserSetting table updates or inserts record if controller patch works collectry.
Hope this would be any help.

Started PUT "/my/account" for ::1 at 2019-08-22 14:14:18 +0900
Processing by MyController#account as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>”xxxx", "user"=>{"firstname"=>"Redmine", "lastname"=>"Admin", "mail"=>"admin@example.net", "language"=>"en", "mail_notification"=>"all", "notified_project_ids"=>[""]}, "commit"=>"Save", "pref"=>{"no_self_notified"=>"1", "hide_mail"=>"1", "time_zone"=>"", "comments_sorting"=>"asc", "warn_on_leaving_unsaved"=>"1", "textarea_font"=>"", "recently_used_projects"=>"3", "history_default_tab"=>"notes"}, "issue_badge"=>{"enabled"=>"1", "show_assigned_to_group"=>"1", "badge_order"=>"oldest"}}
  Token Update All (1.7ms)  UPDATE "tokens" SET "updated_on" = '2019-08-22 14:14:18.446712' WHERE "tokens"."user_id" = ? AND "tokens"."value" = ? AND "tokens"."action" = ?  [["user_id", 1], ["value", “xxxxxx"], ["action", "session"]]
   (0.2ms)  SELECT MAX("settings"."updated_on") FROM "settings"
  User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."type" IN ('User', 'AnonymousUser') AND "users"."status" = ? AND "users"."id" = ? LIMIT ?  [["status", 1], ["id", 1], ["LIMIT", 1]]
  Current user: admin (id=1)
  IssueBadgeUserSetting Load (0.9ms)  SELECT  "issue_badge_user_settings".* FROM "issue_badge_user_settings" WHERE "issue_badge_user_settings"."user_id" = ? LIMIT ?  [["user_id", 1], ["LIMIT", 1]]
{"enabled"=>"1", "show_assigned_to_group"=>"1", "badge_order"=>"oldest"}
   (0.2ms)  begin transaction
  User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."type" IN ('User', 'AnonymousUser') AND "users"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  IssueBadgeUserSetting Update (0.9ms)  UPDATE "issue_badge_user_settings" SET "enabled" = ?, "updated_on" = ? WHERE "issue_badge_user_settings"."id" = ?  [["enabled", 1], ["updated_on", "2019-08-22 14:14:18.459522"], ["id", 1]]
   (1.3ms)  commit transaction
  UserPreference Load (0.2ms)  SELECT  "user_preferences".* FROM "user_preferences" WHERE "user_preferences"."user_id" = ? LIMIT ?  [["user_id", 1], ["LIMIT", 1]]
  EmailAddress Load (0.1ms)  SELECT  "email_addresses".* FROM "email_addresses" WHERE "email_addresses"."user_id" = ? AND "email_addresses"."is_default" = ? LIMIT ?  [["user_id", 1], ["is_default", 1], ["LIMIT", 1]]
   (0.1ms)  begin transaction
  CustomField Load (0.6ms)  SELECT "custom_fields".* FROM "custom_fields" WHERE (type = 'UserCustomField') ORDER BY "custom_fields"."position" ASC
  CustomValue Load (0.2ms)  SELECT "custom_values".* FROM "custom_values" WHERE "custom_values"."customized_id" = ? AND "custom_values"."customized_type" = ?  [["customized_id", 1], ["customized_type", "Principal"]]
  Member Update All (0.3ms)  UPDATE "members" SET "mail_notification" = 0 WHERE "members"."user_id" = ?  [["user_id", 1]]
   (0.1ms)  commit transaction
   (0.1ms)  begin transaction
   (0.1ms)  commit transaction
Redirected to http://localhost:3000/my/account
Completed 302 Found in 45ms (ActiveRecord: 7.5ms)

(0.2ms) begin transaction
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."type" IN ('User', 'AnonymousUser') AND "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
IssueBadgeUserSetting Update (0.9ms) UPDATE "issue_badge_user_settings" SET "enabled" = ?, "updated_on" = ? WHERE "issue_badge_user_settings"."id" = ? [["enabled", 1], ["updated_on", "2019-08-22 14:14:18.459522"], ["id", 1]]
(1.3ms) commit transaction

@tanertas
Copy link

Don't test this patch on production installation!
I tested the patch. Unfortunately it didn't work on my installation. I can't save settings and enable plugin on user settings.
'''
I tried to remove and then reinstall the plugin. After I removed the plugin redmine got "Internal Error" and stoppped working. Here is the error log:

ActionView::Template::Error (PG::UndefinedTable: ERROR: relation "issue_badge_user_settings" does not exist
LINE 8: WHERE a.attrelid = '"issue_badge_user_setting...
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
c.collname, col_description(a.attrelid, a.attnum) AS comment
FROM pg_attribute a
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
LEFT JOIN pg_type t ON a.atttypid = t.oid
LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
WHERE a.attrelid = '"issue_badge_user_settings"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
):
13: <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
14: <%= javascript_heads %>
15: <%= heads_for_theme %>
16: <%= call_hook :view_layouts_base_html_head %>
17:
18: <%= yield :header_tags -%>
19:
'''

@tanertas
Copy link

The error above was related the plugin folder. I removed the plugin's folder after uninstall, then "Internal Error" gone.
Re-installing the patched plugin didn't solve the problem either.

@akiko-pusu
Copy link
Owner

akiko-pusu commented Aug 28, 2019

Hi, @tanertas

After I removed the plugin

Are you also remove the plugin folder from REDMINE_ROOT/plugins?
And restart Redmine?

I removed the plugin's folder after uninstall, then "Internal Error" gone.

Yes, to uninstall, you have to run migration VERSION=0 task, remove plugin’s folder and restart Redmine.

@akiko-pusu
Copy link
Owner

akiko-pusu commented Aug 28, 2019

Hi, @tanertas @mrniemand @Henderxx
Could you please confirm the Request method when updating your account (use preference) including IssueBadge setting?

Following this code, updating IssueBadgeUserSetting is done when request method is “PUT”.

The log I provided, controller is received as ‘PUT’ method.
#97 (comment)

Started PUT "/my/account" for ::1 at 2019-08-22 14:14:18 +0900
Processing by MyController#account as HTML

If your requests always sent via “POST” method, I think this workaround is effective.
(Maybe I have to confirm in various environment and add test code.)

Change from

if request.put?

To

if request.put? || request.post?

@Henderxx
Copy link
Author

Hi, @akiko-pusu i'm back from short offline. I'll do test in this week with patch. But for quick test i did change in

if request.put? || request.post?

And this one did the trick for me

Processing by MyController#account as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"HpVA==", "user"=>{"firstname"=>"Łukasz", "lastname"=>"xxx", "mail"=>"xxx", "language"=>"pl", "mail_notification"=>"only_my_events", "notified_project_ids"=>[""]}, "pref"=>{"theme"=>"black circle", "no_self_notified"=>"1", "hide_mail"=>"0", "time_zone"=>"Warsaw", "comments_sorting"=>"asc", "warn_on_leaving_unsaved"=>"1", "textarea_font"=>"proportional"}, "commit"=>"Zapisz", "issue_badge"=>{"enabled"=>"1", "show_assigned_to_group"=>"0", "badge_order"=>"oldest"}} Current user: henio (id=5) {"enabled"=>"1", "show_assigned_to_group"=>"0", "badge_order"=>"oldest"} Redirected to http://192.168.0.153/redmine/my/account Completed 302 Found in 163ms (ActiveRecord: 93.8ms) Started GET "/redmine/my/account" for 127.0.0.1 at

@akiko-pusu
Copy link
Owner

@Henderxx Thanks for your cooperation.

If you could, please try this patch.
I hope to confirm if the patch is recognized correctly via logging.

--- a/lib/issue_badge/my_controller_patch.rb
+++ b/lib/issue_badge/my_controller_patch.rb
@@ -6,8 +6,12 @@ module IssueBadge
 
     def account
       user = User.current
+
+      logger.info "[info] IssueBadge::MyControllerPatch is applied: #{request.method} / request.put? : #{request.put?}}"
+
       @issue_badge = IssueBadgeUserSetting.find_or_create_by_user_id(user)
-      if request.put?
+
+      if request.put? || request.post?
         begin
           logger.info(badge_params)
           logger.warn "Can't save IssueBadge." unless @issue_badge.update(badge_params)
@@ -26,4 +30,3 @@ module IssueBadge
   end
 end

When get my account:

[info] IssueBadge::MyControllerPatch is applied: GET / request.put? : false}

When update my account:

[info] IssueBadge::MyControllerPatch is applied: POST / request.put? : true}

@tanertas
Copy link

tanertas commented Sep 1, 2019

Change from

if request.put?

To

if request.put? || request.post?

This also worked for me. Thanks.

@Henderxx
Copy link
Author

Henderxx commented Sep 2, 2019

I got some troubles with applying this changes as patch for plugin. it was my first one :) and hey everyday we learn something new. First i got some problem with searching file

obraz

But i managed to do it. I deleted two "end's" from last two lines and then was something like success and file was changed

obraz

Then i restarted redmine and i think it works

Started` GET "/redmine/my/account" for 127.0.0.1 at 2019-09-02 11:02:53 +0200
Processing by MyController#account as HTML
  Current user: henio (id=1)
[info] IssueBadge::MyControllerPatch is applied: GET / request.put? : false}
  Rendering my/account.html.erb within layouts/base
  Rendered users/_mail_notifications.html.erb (8.3ms)
  Rendered users/_preferences.html.erb (14.2ms)
  Rendered plugins/redmine_issue_badge/app/views/my/_issue_badge_form.erb (1.8ms)
  Rendered my/_sidebar.html.erb (7.1ms)
  Rendered my/account.html.erb within layouts/base (50.5ms)
Completed 200 OK in 143ms (Views: 55.5ms | ActiveRecord: 76.2ms)

@akiko-pusu
Copy link
Owner

@tanertas Thanks for your trying and telling your situation!
I could find one of the reason for this problem.

@Henderxx
Are you still having the trouble? Badge setting at user’s preference page works correctly or not?

It seems you use BitNami Redmine and Apache as web server. This is also an important information for me :)

@Henderxx
Copy link
Author

Henderxx commented Sep 4, 2019

@akiko-pusu
No, i don't see problem for now, every setting is saved correctly. and yes i forgot to tell about apache :)

@akiko-pusu
Copy link
Owner

Workaround is merged into master on commit: 59bd9f3.
Please try and confirm how it works.

@tanertas
Copy link

tanertas commented Sep 9, 2019

I tested with latest master( 60ddcd4) but i didn't work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants