Skip to content

Commit 38d775a

Browse files
committed
fix(serializers): auto-correct rubocop offenses in serializers and policies
Applied rubocop auto-corrections to: - All serializers - All policy files
1 parent 4af41f4 commit 38d775a

23 files changed

Lines changed: 932 additions & 842 deletions

app/policies/application_policy.rb

Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,75 @@
1-
class ApplicationPolicy
2-
attr_reader :user, :record
3-
4-
def initialize(user, record)
5-
@user = user
6-
@record = record
7-
end
8-
9-
def index?
10-
false
11-
end
12-
13-
def show?
14-
false
15-
end
16-
17-
def create?
18-
false
19-
end
20-
21-
def new?
22-
create?
23-
end
24-
25-
def update?
26-
false
27-
end
28-
29-
def edit?
30-
update?
31-
end
32-
33-
def destroy?
34-
false
35-
end
36-
37-
class Scope
38-
def initialize(user, scope)
39-
@user = user
40-
@scope = scope
41-
end
42-
43-
def resolve
44-
raise NotImplementedError, "You must define #resolve in #{self.class}"
45-
end
46-
47-
private
48-
49-
attr_reader :user, :scope
50-
end
51-
52-
private
53-
54-
def owner?
55-
user.role == 'owner'
56-
end
57-
58-
def admin?
59-
user.role == 'admin' || user.role == 'owner'
60-
end
61-
62-
def coach?
63-
%w[coach admin owner].include?(user.role)
64-
end
65-
66-
def analyst?
67-
%w[analyst coach admin owner].include?(user.role)
68-
end
69-
70-
def same_organization?
71-
record.respond_to?(:organization_id) && record.organization_id == user.organization_id
72-
end
73-
end
1+
# frozen_string_literal: true
2+
3+
class ApplicationPolicy
4+
attr_reader :user, :record
5+
6+
def initialize(user, record)
7+
@user = user
8+
@record = record
9+
end
10+
11+
def index?
12+
false
13+
end
14+
15+
def show?
16+
false
17+
end
18+
19+
def create?
20+
false
21+
end
22+
23+
def new?
24+
create?
25+
end
26+
27+
def update?
28+
false
29+
end
30+
31+
def edit?
32+
update?
33+
end
34+
35+
def destroy?
36+
false
37+
end
38+
39+
class Scope
40+
def initialize(user, scope)
41+
@user = user
42+
@scope = scope
43+
end
44+
45+
def resolve
46+
raise NotImplementedError, "You must define #resolve in #{self.class}"
47+
end
48+
49+
private
50+
51+
attr_reader :user, :scope
52+
end
53+
54+
private
55+
56+
def owner?
57+
user.role == 'owner'
58+
end
59+
60+
def admin?
61+
%w[admin owner].include?(user.role)
62+
end
63+
64+
def coach?
65+
%w[coach admin owner].include?(user.role)
66+
end
67+
68+
def analyst?
69+
%w[analyst coach admin owner].include?(user.role)
70+
end
71+
72+
def same_organization?
73+
record.respond_to?(:organization_id) && record.organization_id == user.organization_id
74+
end
75+
end

app/policies/match_policy.rb

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
class MatchPolicy < ApplicationPolicy
2-
def index?
3-
true
4-
end
5-
6-
def show?
7-
same_organization?
8-
end
9-
10-
def create?
11-
coach?
12-
end
13-
14-
def update?
15-
coach? && same_organization?
16-
end
17-
18-
def destroy?
19-
admin? && same_organization?
20-
end
21-
22-
def stats?
23-
same_organization?
24-
end
25-
26-
def import?
27-
coach? && same_organization?
28-
end
29-
30-
class Scope < Scope
31-
def resolve
32-
scope.where(organization: user.organization)
33-
end
34-
end
35-
end
1+
# frozen_string_literal: true
2+
3+
class MatchPolicy < ApplicationPolicy
4+
def index?
5+
true
6+
end
7+
8+
def show?
9+
same_organization?
10+
end
11+
12+
def create?
13+
coach?
14+
end
15+
16+
def update?
17+
coach? && same_organization?
18+
end
19+
20+
def destroy?
21+
admin? && same_organization?
22+
end
23+
24+
def stats?
25+
same_organization?
26+
end
27+
28+
def import?
29+
coach? && same_organization?
30+
end
31+
32+
class Scope < Scope
33+
def resolve
34+
scope.where(organization: user.organization)
35+
end
36+
end
37+
end

app/policies/player_policy.rb

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
1-
class PlayerPolicy < ApplicationPolicy
2-
def index?
3-
true # All authenticated users can view players
4-
end
5-
6-
def show?
7-
same_organization?
8-
end
9-
10-
def create?
11-
admin?
12-
end
13-
14-
def update?
15-
admin? && same_organization?
16-
end
17-
18-
def destroy?
19-
owner? && same_organization?
20-
end
21-
22-
def stats?
23-
same_organization?
24-
end
25-
26-
def matches?
27-
same_organization?
28-
end
29-
30-
def import?
31-
admin? && same_organization?
32-
end
33-
34-
class Scope < Scope
35-
def resolve
36-
scope.where(organization: user.organization)
37-
end
38-
end
39-
end
1+
# frozen_string_literal: true
2+
3+
class PlayerPolicy < ApplicationPolicy
4+
def index?
5+
true # All authenticated users can view players
6+
end
7+
8+
def show?
9+
same_organization?
10+
end
11+
12+
def create?
13+
admin?
14+
end
15+
16+
def update?
17+
admin? && same_organization?
18+
end
19+
20+
def destroy?
21+
owner? && same_organization?
22+
end
23+
24+
def stats?
25+
same_organization?
26+
end
27+
28+
def matches?
29+
same_organization?
30+
end
31+
32+
def import?
33+
admin? && same_organization?
34+
end
35+
36+
class Scope < Scope
37+
def resolve
38+
scope.where(organization: user.organization)
39+
end
40+
end
41+
end

app/policies/pro_match_policy.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class ProMatchPolicy < ApplicationPolicy
24
def index?
35
true # All authenticated users can view pro matches

app/policies/riot_data_policy.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
class RiotDataPolicy < ApplicationPolicy
2-
def manage?
3-
user.admin_or_owner?
4-
end
5-
6-
class Scope < Scope
7-
def resolve
8-
scope.all
9-
end
10-
end
11-
end
1+
# frozen_string_literal: true
2+
3+
class RiotDataPolicy < ApplicationPolicy
4+
def manage?
5+
user.admin_or_owner?
6+
end
7+
8+
class Scope < Scope
9+
def resolve
10+
scope.all
11+
end
12+
end
13+
end

app/policies/schedule_policy.rb

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
class SchedulePolicy < ApplicationPolicy
2-
def index?
3-
true
4-
end
5-
6-
def show?
7-
same_organization?
8-
end
9-
10-
def create?
11-
coach?
12-
end
13-
14-
def update?
15-
coach? && same_organization?
16-
end
17-
18-
def destroy?
19-
admin? && same_organization?
20-
end
21-
22-
class Scope < Scope
23-
def resolve
24-
scope.where(organization: user.organization)
25-
end
26-
end
27-
end
1+
# frozen_string_literal: true
2+
3+
class SchedulePolicy < ApplicationPolicy
4+
def index?
5+
true
6+
end
7+
8+
def show?
9+
same_organization?
10+
end
11+
12+
def create?
13+
coach?
14+
end
15+
16+
def update?
17+
coach? && same_organization?
18+
end
19+
20+
def destroy?
21+
admin? && same_organization?
22+
end
23+
24+
class Scope < Scope
25+
def resolve
26+
scope.where(organization: user.organization)
27+
end
28+
end
29+
end

0 commit comments

Comments
 (0)