Class: ModelPolicy

Inherits:
ApplicationPolicy show all
Defined in:
app/policies/model_policy.rb

Defined Under Namespace

Classes: Scope

Constant Summary

Constants inherited from ApplicationPolicy

ApplicationPolicy::STANDARD_EDIT_PERMISSIONS, ApplicationPolicy::STANDARD_VIEW_PERMISSIONS

Instance Attribute Summary

Attributes inherited from ApplicationPolicy

#record, #user

Instance Method Summary collapse

Methods inherited from ApplicationPolicy

#create?, #destroy_all?, #edit?, #index?, #initialize, #new?, #update?

Constructor Details

This class inherits a constructor from ApplicationPolicy

Instance Method Details

#bulk_edit? ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/policies/model_policy.rb', line 43

def bulk_edit?
  user&.is_moderator?
end

#bulk_update? ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/policies/model_policy.rb', line 47

def bulk_update?
  user&.is_moderator?
end

#configure_merge? ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'app/policies/model_policy.rb', line 6

def configure_merge?
  merge?
end

#destroy? ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/policies/model_policy.rb', line 27

def destroy?
  super && (record.is_a?(Model) ? !record.contains_other_models? : true)
end

#download? ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/policies/model_policy.rb', line 23

def download?
  check_permissions(record, ["view", "edit", "own"], user)
end

#merge? ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
# File 'app/policies/model_policy.rb', line 10

def merge?
  all_of(
    update?,
    none_of(
      SiteSettings.demo_mode_enabled?
    )
  )
end

#organize? ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/policies/model_policy.rb', line 39

def organize?
  edit?
end

#scan? ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/policies/model_policy.rb', line 31

def scan?
  user&.is_contributor?
end

#show? ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
# File 'app/policies/model_policy.rb', line 2

def show?
  super && !(user&.sensitive_content_handling == "hide" && record.sensitive)
end

#sync? ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/policies/model_policy.rb', line 35

def sync?
  update?
end

#upload? ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/policies/model_policy.rb', line 19

def upload?
  edit? && UploadPolicy.new(user, record).create?
end