atlascoder / tracker_hider

A plugin for redmine
https://www.redmine.org/plugins/tracker_hider
6 stars 2 forks source link

Hide to certain roles #1

Open lublasco opened 8 years ago

lublasco commented 8 years ago

Hi!

Could you consider the option to hide trackers to roles? IMO it is a better practice to discriminate access in Redmine through roles instead of users.

Thanks for a nice plugin! It works perfectly on Redmine 3.1.

atlascoder commented 8 years ago

Hi, lublasco!

Thanks for the feedback! I guess you are right about the roles. Well, i will do it near days.

lublasco commented 8 years ago

Great! Thank you!

atlascoder commented 8 years ago

Lublasco, i've just uploaded a new version! I appreciate your feedback!

lublasco commented 8 years ago

Hi, thanks a lot for the improvement.

However tests haven't been successful. Error folllows when trying to get the issues of a project ("500: An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator.")

Or just the blank page for other actions like clicking on Activity or Overview. Here you have the production.log:

Started GET "/projects/proyecto-a/activity" for 81.202.186.117 at 2015-11-08 16:56:34 +0000 Processing by ActivitiesController#index as HTML Parameters: {"id"=>"proyecto-a"} Current user: user (id=1) Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL) AND hts.role_id IN (SELECT mr.role_id FROM member_roles AS mr INNER JOIN m' at line 1: SELECT issues.* FROM issues INNER JOIN projects ON projects.id = issues.project_id WHERE (issues.created_on BETWEEN '2015-10-10' AND '2015-11-09') AND (((projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 4))) AND (projects.status <> 9 AND projects.id IN (SELECT em.project_id FROM enabled_modules em WHERE em.name='issue_tracking')) AND (EXISTS(SELECT id FROM enabled_modules AS em WHERE em.project_id=issues.project_id AND em.name='tracker_hider') AND NOT EXISTS( SELECT * from hidden_trackers AS hts WHERE issues.tracker_id=hts.tracker_id AND issues.project_id=hts.project_id AND ( hts.user_id=1 OR ((hts.role_id NOT NULL) AND hts.role_id IN (SELECT mr.role_id FROM member_roles AS mr INNER JOIN members AS m ON mr.member_id=m.id WHERE m.user_id=1 AND m.project_id=issues.project_id)) OR (hts.role_id=2 AND 2=1) OR ((hts.role_id=1) AND NOT EXISTS(SELECT mr.role_id FROM member_roles AS mr INNER JOIN members AS m ON mr.member_id=m.id WHERE m.user_id=1 AND m.project_id=issues.project_id)) )))) Completed 500 Internal Server Error in 7ms (ActiveRecord: 0.9ms)

ActiveRecord::StatementInvalid (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL) AND hts.role_id IN (SELECT mr.role_id FROM member_roles AS mr INNER JOIN m' at line 1: SELECT issues.* FROM issues INNER JOIN projects ON projects.id = issues.project_id WHERE (issues.created_on BETWEEN '2015-10-10' AND '2015-11-09') AND (((projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 4))) AND (projects.status <> 9 AND projects.id IN (SELECT em.project_id FROM enabled_modules em WHERE em.name='issue_tracking')) AND (EXISTS(SELECT id FROM enabled_modules AS em WHERE em.project_id=issues.project_id AND em.name='tracker_hider') AND NOT EXISTS( SELECT * from hidden_trackers AS hts WHERE issues.tracker_id=hts.tracker_id AND issues.project_id=hts.project_id AND ( hts.user_id=1 OR ((hts.role_id NOT NULL) AND hts.role_id IN (SELECT mr.role_id FROM member_roles AS mr INNER JOIN members AS m ON mr.member_id=m.id WHERE m.user_id=1 AND m.project_id=issues.project_id)) OR (hts.role_id=2 AND 2=1) OR ((hts.role_id=1) AND NOT EXISTS(SELECT mr.role_id FROM member_roles AS mr INNER JOIN members AS m ON mr.member_id=m.id WHERE m.user_id=1 AND m.project_id=issues.project_id)) ))))): lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb:81:in find_events' lib/redmine/activity/fetcher.rb:91:inblock (2 levels) in events' lib/redmine/activity/fetcher.rb:90:in each' lib/redmine/activity/fetcher.rb:90:inblock in events' lib/redmine/activity/fetcher.rb:89:in each' lib/redmine/activity/fetcher.rb:89:inevents' app/controllers/activities_controller.rb:43:in index' lib/redmine/sudo_mode.rb:63:insudo_mode'

Started GET "/projects/proyecto-a" for 81.202.186.117 at 2015-11-08 16:56:37 +0000 Processing by ProjectsController#show as HTML Parameters: {"id"=>"proyecto-a"} Current user: user (id=1) Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL) AND hts.role_id IN (SELECT mr.role_id FROM member_roles AS mr INNER JOIN m' at line 1: SELECT COUNT() AS count_all, tracker_id AS tracker_id FROM issues INNER JOIN projects ON projects.id = issues.project_id INNER JOIN issue_statuses ON issue_statuses.id = issues.status_id WHERE (projects.status <> 9 AND projects.id IN (SELECT em.project_id FROM enabled_modules em WHERE em.name='issue_tracking') AND (EXISTS(SELECT id FROM enabled_modules AS em WHERE em.project_id=issues.project_id AND em.name='tracker_hider') AND NOT EXISTS( SELECT \ from hidden_trackers AS hts WHERE issues.tracker_id=hts.tracker_id AND issues.project_id=hts.project_id AND ( hts.user_id=1 OR ((hts.role_id NOT NULL) AND hts.role_id IN (SELECT mr.role_id FROM member_roles AS mr INNER JOIN members AS m ON mr.member_id=m.id WHERE m.user_id=1 AND m.project_id=issues.project_id)) OR (hts.role_id=2 AND 2=1) OR ((hts.role_id=1) AND NOT EXISTS(SELECT mr.role_id FROM member_roles AS mr INNER JOIN members AS m ON mr.member_id=m.id WHERE m.user_id=1 AND m.project_id=issues.project_id)) )))) AND (issue_statuses.is_closed = 0) AND ((projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 4))) GROUP BY issues.tracker_id Completed 500 Internal Server Error in 12ms (ActiveRecord: 1.3ms)

ActiveRecord::StatementInvalid (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL) AND hts.role_id IN (SELECT mr.role_id FROM member_roles AS mr INNER JOIN m' at line 1: SELECT COUNT() AS count_all, tracker_id AS tracker_id FROM issues INNER JOIN projects ON projects.id = issues.project_id INNER JOIN issue_statuses ON issue_statuses.id = issues.status_id WHERE (projects.status <> 9 AND projects.id IN (SELECT em.project_id FROM enabled_modules em WHERE em.name='issue_tracking') AND (EXISTS(SELECT id FROM enabled_modules AS em WHERE em.project_id=issues.project_id AND em.name='tracker_hider') AND NOT EXISTS( SELECT \ from hidden_trackers AS hts WHERE issues.tracker_id=hts.tracker_id AND issues.project_id=hts.project_id AND ( hts.user_id=1 OR ((hts.role_id NOT NULL) AND hts.role_id IN (SELECT mr.role_id FROM member_roles AS mr INNER JOIN members AS m ON mr.member_id=m.id WHERE m.user_id=1 AND m.project_id=issues.project_id)) OR (hts.role_id=2 AND 2=1) OR ((hts.role_id=1) AND NOT EXISTS(SELECT mr.role_id FROM member_roles AS mr INNER JOIN members AS m ON mr.member_id=m.id WHERE m.user_id=1 AND m.project_id=issues.project_id)) )))) AND (issue_statuses.is_closed = 0) AND ((projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 4))) GROUP BY issues.tracker_id): app/controllers/projects_controller.rb:144:in show' lib/redmine/sudo_mode.rb:63:insudo_mode'

atlascoder commented 8 years ago

Many thanks to you! The matter is that i have tested it on sqlite3 and the problem wasn't occure. Noh i've checked on mysql and i have the same error.

The problem is there where 'hts.role_id NOT NULL', it should be 'hts.role_id IS NOT NULL'. I have fixed this and it doesn't case error 500. You can checkout already.

But reagrding tests the questions is still opened. What test did you run?

atlascoder commented 8 years ago

Oh, i've catched 1 more great luck in the logic of SQL((( Sorry for that.. It is about checking for the module is enabled.. I suggest that this cases tests to crash.

I Will fix now.

atlascoder commented 8 years ago

lublasco, could you check the last commit please? There was a serious mistake in SQL which i have put in my production too, but due today is weekend it was lasted behind... Now it's fixed and i don't see related issues from test, and i tested manually the functionality. Thanks once more!

lublasco commented 8 years ago

Hi, atlascoder.

Now the functionality seems to be working perfectly, inspite of a last question: user with tracker curtain should not be able to see the hidden tracker in the "new issue" form. They can't see hidden tracker's issues on the reports but they CAN create new issues. I think this should be avoid too.

Thanks!

atlascoder commented 8 years ago

Actually i thought about it. It can be obtained by managing of issues workflow, but I will try it, I guess it is possible. However I think that it is reasonable to have ability to initiate an issue in hidden workflow but you have to be able to see this issue while it is resolving. I guess that it may be implemented principially, but it is more complex filter of an issue visibilty and overlaps with workflow. I think it could be next an option in further fersions.

Thanks!

atlascoder commented 8 years ago

lublasco hi! Have you tested the plugin? Could you tell me your Redmine and Rails versions? Thanks!

lublasco commented 8 years ago

Hi,

The plugin is working correctly, no errors. I still believe that users should not be able to see/create issues with tracker curtains. And I can't do it by means of workflow management. I have disabled all statuses for this role-tracker pair, but the user still is able to create a new issue.

My installation details: Environment: Redmine version 3.1.1.stable Ruby version 2.0.0-p647 (2015-08-18) [x86_64-linux] Rails version 4.2.4 Environment production Database adapter Mysql2

Thank you!

atlascoder commented 8 years ago

luiblasco, thanks for reply!

It seems that it's really imposible to hide the tracker when creting/editing an issue as i have mentioned before. And you are right that there have to be a way to do it. I'll will look for a way to do it.

Peter-Petrik commented 8 years ago

Great plugin.

+1 to hide the tracker when creating/editing an issue. I would also suggest the ability to support "Groups" in addition to individual users.

atlascoder commented 8 years ago

Hi, Skvare! Yes, groups weren't considered before. I think it possible, but how do you think if it has sense at the project level? I've tried this on my production with many projects it make many routines. Antoher problem is that you cannot overiview all permittions. Probably it is a reason to move this function on the Admin level, isn't?

Thanks!

Peter-Petrik commented 8 years ago

In our experience, a group is a collection of users with possibly different roles. So while not critical, it is a possible "nice to have" as an additional way of implementing the functionality.

atlascoder commented 8 years ago

But what about the rules definition level? Is it better as a project module or as predefined rules at the Admin level?

Peter-Petrik commented 8 years ago

At the project module level - same as it is currently set up with users and roles.

mko-ilim commented 8 years ago

There is still something wrong with "users_roles". After installing plugin and having accomplished its basic configuration I had internal server error. Error occured instantly after switching to Sprints tab or Issues. There are some custom roles and groups defined in the system.


Started GET "/projects/epk35-epica/issues" for 192.168.1.xxx at 2016-02-02 10:16:12 +0100 Processing by IssuesController#index as HTML Parameters: {"project_id"=>"epk35-epica"} Current user: user1 (id=6) Rendered queries/_filters.html.erb (8.3ms) Rendered queries/_columns.html.erb (2.1ms) Rendered issues/_list.html.erb (19.2ms) Rendered issues/_sidebar.html.erb (1.8ms) Rendered issues/index.html.erb within layouts/base (38.9ms) Rendered plugins/scrum/app/views/scrum_hooks/_head.html.erb (0.2ms) Rendered plugins/scrum/app/views/scrum_hooks/_scrum_tips.html.erb (1.7ms) Completed 200 OK in 106ms (Views: 56.0ms | ActiveRecord: 5.4ms) Started GET "/issues/20" for 192.168.1.xxx at 2016-02-02 10:16:14 +0100 Processing by IssuesController#show as HTML Parameters: {"id"=>"20"} Current user: user1 (id=6) Completed 500 Internal Server Error in 8ms (ActiveRecord: 1.3ms)

ActiveRecord::StatementInvalid (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))))' at line 1: SELECT hidden_trackers.* FROM hidden_trackers WHERE (tracker_id='4' AND project_id='6' AND ((user_id='6') OR (role_id IN ())))): app/controllers/application_controller.rb:345:in find_issue' lib/redmine/sudo_mode.rb:63:insudo_mode'


Started GET "/sprints/6" for 192.168.1.xxx at 2016-02-02 10:09:05 +0100 Processing by SprintsController#show as HTML Parameters: {"id"=>"6"} Current user: Designer-PO (id=30) Rendered plugins/scrum/app/views/common/_scrum_sprint_menu.html.erb (8.1ms) Rendered plugins/scrum/app/views/post_its/sprint_board/_head.html.erb (4.4ms) Rendered inline template (0.4ms) Rendered plugins/scrum/app/views/post_its/sprint_board/_fields.html.erb (1.9ms) Rendered plugins/scrum/app/views/post_its/sprint_board/_custom_fields.html.erb (7.5ms) Rendered plugins/scrum/app/views/common/_scrum_editable_value.html.erb (1.0ms) Rendered plugins/scrum/app/views/common/_scrum_story_points.html.erb (7.4ms) Rendered inline template (0.4ms) Rendered inline template (0.3ms) Rendered plugins/scrum/app/views/post_its/sprint_board/_pbi.html.erb (75.3ms) Rendered plugins/scrum/app/views/post_its/sprint_board/_pbi_row.html.erb (89.9ms) Rendered plugins/scrum/app/views/sprints/show.html.erb within layouts/base (119.2ms) Completed 500 Internal Server Error in 140ms (ActiveRecord: 12.2ms)

ActionView::Template::Error (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))))' at line 1: SELECT hidden_trackers.* FROM hidden_trackers WHERE (tracker_id='5' AND project_id='10' AND ((user_id='30') OR (role_id IN ())))): 4: <%= render :partial => 'post_its/sprint_board/pbi', :formats => [:html], 5: :locals => {:project => project, :pbi => pbi, :read_only => false} %> 6: 7: <%- tasks = pbi.tasks_by_status_id 8: task_statuses.each do |status| -%> 9: <%- pbi_statusid = "pbi#{pbi.id}status#{status.id}" 10: other_pbi_status_ids = task_statuses.select{|other| other != status}.collect{ lib/redmine/sudo_mode.rb:63:in `sudo_mode'


Instance configuration: Environment: Redmine version 3.1.3.stable Ruby version 2.2.4-p230 (2015-12-16) [x86_64-linux-gnu] Rails version 4.2.5 Environment production Database adapter Mysql2 Mysql Ver 14.14 Distrib 5.5.47, for debian-linux-gnu (x86_64) using readline 6.3 SCM: Subversion 1.8.8 Mercurial 2.8.2 Git 1.9.1 Redmine plugins: redmine_ckeditor 1.1.3 scrum 0.13.0 tracker_hider 0.0.1


I will provide any additional information, if needed.

atlascoder commented 8 years ago

HI, @mko-ilim !

Thank you for the feedback! I see the problem in the SQL statement, I will fix it near time and update the repo

atlascoder commented 8 years ago

@mko-ilim please pull the update and let me know your result.

mko-ilim commented 8 years ago

Hi, After initial tests it looks like everything works fine - I didn't get any 500 Internal Error. Tests are still in progress, if I find any bugs, I'll report. Thank you @atlascoder.

atlascoder commented 8 years ago

Thanks @mko-ilim for initiating this improvement