Skip to content

Commit 26c4df2

Browse files
committed
unify and mark with question boolean methods in update contract
1 parent d02f355 commit 26c4df2

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

app/contracts/projects/update_contract.rb

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
module Projects
3232
class UpdateContract < BaseContract
3333
def writable_attributes
34-
if allow_project_attributes_only
34+
if allow_project_attributes_only?
3535
with_available_custom_fields_only(super)
36-
elsif allow_edit_attributes_only
36+
elsif allow_edit_attributes_only?
3737
without_custom_fields(super)
38-
elsif allow_all_attributes
38+
elsif allow_all_attributes?
3939
# When all attributes are updated (API-only case), allow writing to all available custom
4040
# fields (including disabled ones) to maintain backward compatibility with the API.
4141
with_all_available_custom_fields(super)
@@ -46,21 +46,24 @@ def writable_attributes
4646

4747
private
4848

49-
def project_attributes_only = options[:project_attributes_only].present?
49+
def project_attributes_only? = options[:project_attributes_only].present?
5050

51-
def edit_project = user.allowed_in_project?(:edit_project, model)
51+
def allow_edit_project? = user.allowed_in_project?(:edit_project, model)
5252

53-
def edit_project_attributes = user.allowed_in_project?(:edit_project_attributes, model)
53+
def allow_edit_project_attributes? = user.allowed_in_project?(:edit_project_attributes, model)
5454

55-
def allow_edit_attributes_only = edit_project && !project_attributes_only && !edit_project_attributes
55+
def allow_edit_attributes_only?
56+
allow_edit_project? && !project_attributes_only? && !allow_edit_project_attributes?
57+
end
5658

57-
def allow_project_attributes_only
58-
edit_project_attributes && (project_attributes_only || !edit_project)
59+
def allow_project_attributes_only?
60+
allow_edit_project_attributes? && (project_attributes_only? || !allow_edit_project?)
5961
end
6062

61-
def allow_all_attributes
62-
(edit_project && edit_project_attributes && !project_attributes_only) ||
63-
(changed_by_user == ["active"]) # Allow archiving, permission checked in manage_permission
63+
def allow_all_attributes?
64+
return true if allow_edit_project? && allow_edit_project_attributes? && !project_attributes_only?
65+
66+
changed_by_user == ["active"] # Allow archiving, permission checked in manage_permission
6467
end
6568

6669
def without_custom_fields(changes) = changes.grep_v(/^custom_(field|comment)_/)
@@ -74,7 +77,7 @@ def with_all_available_custom_fields(changes)
7477
def manage_permission
7578
if changed_by_user == ["active"]
7679
:archive_project
77-
elsif project_attributes_only
80+
elsif project_attributes_only?
7881
:edit_project_attributes
7982
else
8083
# if "active" is changed, :archive_project permission will also be

0 commit comments

Comments
 (0)