Skip to content

Commit fd427aa

Browse files
authored
Merge pull request #166 from arBmind/feature/fix_time_bookings_visibility
Fix time bookings visibility
2 parents d60be8b + 7be999c commit fd427aa

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

.github/data/Gemfile.local.5.1.2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
# workaround for Redmine < 5.1.3
3+
gem 'blankslate'
4+
5+
# pin ruby gem to avoid rails <7 error
6+
gem 'concurrent-ruby', '<= 1.3.4'

.github/data/Gemfile.local.5.1.6

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
# pin ruby gem to avoid rails <7 error
3+
gem 'concurrent-ruby', '<= 1.3.4'

.github/workflows/main.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,9 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
redmine: [ '5.1.2', '4.2.9' ]
13-
ruby: [ '2.7.7' ]
12+
redmine: [ '5.1.2', '5.1.6' ]
13+
ruby: [ '2.7.7', '3.2.7' ]
1414
database: [ 'sqlite3', 'postgresql', 'mysql2' ]
15-
include:
16-
- redmine: '5.1.2'
17-
ruby: '3.2.2'
18-
database: 'postgresql'
19-
- redmine: '5.1.2'
20-
ruby: '3.2.2'
21-
database: 'mysql2'
2215

2316
services:
2417
postgresql:
@@ -47,12 +40,14 @@ jobs:
4740
- name: Install redmine
4841
run: wget https://github.com/redmine/redmine/archive/${{ matrix.redmine }}.tar.gz -qO- | tar -C $GITHUB_WORKSPACE -xz --strip=1 --show-transformed -f -
4942

50-
- uses: actions/checkout@v3
43+
- uses: actions/checkout@v4
5144
with:
5245
path: 'plugins/redmine_hourglass'
5346

5447
- name: Create database config
55-
run: cp $GITHUB_WORKSPACE/plugins/redmine_hourglass/.github/data/${{ matrix.database }}_database.yml $GITHUB_WORKSPACE/config/database.yml
48+
run: |
49+
cp $GITHUB_WORKSPACE/plugins/redmine_hourglass/.github/data/${{ matrix.database }}_database.yml $GITHUB_WORKSPACE/config/database.yml
50+
cp $GITHUB_WORKSPACE/plugins/redmine_hourglass/.github/data/Gemfile.local.${{ matrix.redmine }} $GITHUB_WORKSPACE/Gemfile.local
5651
5752
- name: Install dependencies
5853
run: |

app/models/hourglass/time_booking.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ class TimeBooking < ApplicationRecord
2929
delegate :id, to: :user, prefix: true, allow_nil: true
3030
delegate :comments, :comments=, :hours, :project_id=, :save_custom_field_values, to: :time_entry, allow_nil: true
3131

32-
scope :visible, lambda { |*args| joins(:project).where(projects: {id: visible_condition(args.shift || User.current, *args)})
32+
scope :visible, lambda { |*args|
33+
user = args.shift || User.current
34+
joins(:user).and(
35+
TimeBooking.where(projects: { id: visible_own_project_ids(user, *args) }, users: { id: user.id }).
36+
or(TimeBooking.where(projects: { id: visible_project_ids(user, *args) })))
3337
}
3438

3539
def update(args = {})
@@ -61,10 +65,12 @@ def time_tracker_params
6165
end
6266

6367
private
64-
def self.visible_condition(user, _options = {})
65-
project_ids = Project.allowed_to(user, :hourglass_view_booked_time).pluck :id
66-
project_ids += Project.allowed_to(user, :hourglass_view_own_booked_time).pluck :id
67-
project_ids.uniq
68+
def self.visible_own_project_ids(user, _options = {})
69+
Project.allowed_to(user, :hourglass_view_own_booked_time).pluck :id
70+
end
71+
72+
def self.visible_project_ids(user, _options = {})
73+
Project.allowed_to(user, :hourglass_view_booked_time).pluck :id
6874
end
6975

7076
def fix_nil_hours

0 commit comments

Comments
 (0)