noosfero | WIP: Improvements on AccessLevel class, in order to center how noosfero display content to users. (!1361)

Rodrigo Souto gitlab at mg.gitlab.com
Tue Dec 19 13:38:47 BRST 2017


Rodrigo Souto started a new discussion on app/concerns/profile_access_levels.rb:

> +class ProfileAccessLevels < Levels
> +
> +  # Add new checkers here, and it will be automatically run.

Maybe we can modularize this `CHECK` and the `permission` method just by moving them to `Levels`, transforming both constants `CHECK_BY_PROFILE` and `CHECK_BY_CONTENT` into class methods overloaded on both subclasses and rewrite the `permission` signature to receive a hash of context variables instead of a specified parameter list.

Something like:
```
class Levels
  def self.checks
    [] # Overwrite on subclasses
  end

  def self.permission(user, context={})
    return @@value if high_permission
    checks.each do |method|
      send(method, context)
    end
    @@value
  end

  ...

end

class ProfileAccessLevels
  def self.checks
    %w(me? view_private_content? moderator? friend_or_member? visible?)
  end

  def self.me?(user, contenxt)
    @@value = mixed_levels[:self] if user == context[:profile]
  end

  ...
end
```

What do you think?

---
Reply to this email directly or view it on GitLab: https://gitlab.com/noosfero/noosfero/merge_requests/1361#note_52006583
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20171219/fe8bf2b2/attachment-0001.html>


More information about the Noosfero-dev mailing list