Merge Request #40

Merged
softwarepublico/colab!40
Created by Gustavo Jaruga Cruz

Private mailman lists

Only show public lists by default. Private lists are only visible if user if a member of that list. That applies to /dashboard /archives/thread and /accounts/username pages. So you cannot view a collaboration of an user in a private-list in their profile if you are not also in the privatelist. Note: You'll need mailman-api running to see this functionality. The tests uses mocked data from the mailman-api.

Milestone: None

Merged by Sergio Oliveira

Source branch has been removed
Commits (13)
3 participants
  • C6b14af78e51fba6beb90142971240cc?s=40&d=identicon
    Gustavo Jaruga Cruz @darksshades

    @rodrigosiqueiramelo @carlospecter

    Choose File ...   File name...
    Cancel
  • 08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
    Carlos Coêlho started a discussion on the diff
    last updated by Carlos Coêlho
    colab/accounts/utils/mailman.py
    97 102 return []
    98 103  
    99 104 return users.json()
      105 +
      106 +
      107 +def get_user_mailinglists(user):
      108 + lists_for_user = []
      109 + emails = ''
      110 +
      111 + if user:
      112 + emails = user.emails.values_list('address', flat=True)
      113 +
      114 + lists_for_user = []
    1
    • 08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
      Carlos Coêlho @carlos

      Why are you initializing the same variable twice with the same value and no other change between the redefinitions?

      Choose File ...   File name...
      Cancel
    08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
    Carlos Coêlho started a discussion on the outdated diff
    last updated by Carlos Coêlho
    colab/accounts/utils/mailman.py
    64 65 return lists.json()
    65 66  
    66 67  
      68 +def is_private_list(name):
      69 + return dict(all_lists(private=True))[name]
      70 +
      71 +
    67 72 def all_lists(*args, **kwargs):
    68   - return address_lists('', *args, **kwargs)
      73 + return mailing_lists(*args, **kwargs)
    1
    08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
    Carlos Coêlho started a discussion on the diff
    last updated by Carlos Coêlho
    colab/accounts/utils/mailman.py
    38 38  
    39 39  
    40 40 def update_subscription(address, lists):
    41   - current_lists = address_lists(address)
      41 + current_lists = mailing_lists(address=address)
    1
    • 08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
      Carlos Coêlho @carlos

      Why not use address_list function instead of mailing_lists? It returns mailing_lists too, but it's only used once in the file.

      Choose File ...   File name...
      Cancel
    08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
    Carlos Coêlho started a discussion on the diff
    last updated by Carlos Coêlho
    colab/accounts/utils/mailman.py
    66 67  
      68 +def is_private_list(name):
      69 + return dict(all_lists(private=True))[name]
      70 +
      71 +
    67 72 def all_lists(*args, **kwargs):
    68   - return address_lists('', *args, **kwargs)
      73 + return mailing_lists(*args, **kwargs)
    69 74  
    70 75  
    71 76 def user_lists(user):
    72 77 list_set = set()
    73 78  
    74 79 for email in user.emails.values_list('address', flat=True):
    75   - list_set.update(address_lists(email))
      80 + list_set.update(mailing_lists(address=email))
    1
    08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
    Carlos Coêlho started a discussion on the outdated diff
    last updated by Carlos Coêlho
    colab/home/views.py
      17 + latest_threads = []
      18 + lists_for_user = []
    15 19  
    16   - latest_threads = Thread.objects.all()[:6]
      20 + user = None
      21 + if request.user.is_authenticated():
      22 + user = User.objects.get(username=request.user)
      23 + lists_for_user = mailman.get_user_mailinglists(user)
    17 24  
    18   - latest_results, count_types = get_collaboration_data()
      25 + for t in all_threads:
      26 + if not t.mailinglist.is_private or \
      27 + t.mailinglist.name in lists_for_user:
      28 + latest_threads.append(t)
      29 +
      30 + hottest_threads = []
    1
    08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
    Carlos Coêlho started a discussion on the outdated diff
    last updated by Carlos Coêlho
    colab/search/utils.py
    6 6 from django.core.cache import cache
    7 7 from django.utils.translation import ugettext as _
    8 8 from django.conf import settings
      9 +from django.db.models import Q
    1
    • 08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
      Carlos Coêlho @carlos

      Just an idea, we believe that the code would be more understandable if you change the name "Q" to something more specific. For example ...import Q as (better_name)...

      Choose File ...   File name...
      Cancel
    08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
    Carlos Coêlho started a discussion on the outdated diff
    last updated by Carlos Coêlho
    colab/search/utils.py
    7 7 from django.utils.translation import ugettext as _
    8 8 from django.conf import settings
      9 +from django.db.models import Q
      10 +
    9 11 from colab.super_archives.models import Thread, Message
    10 12 from colab.proxy.utils.models import Collaboration
      13 +from colab.accounts.utils import mailman
      14 +
      15 +
      16 +def get_visible_threads_queryset(logged_user):
      17 + qs = Thread.objects
      18 + lists_for_user = []
      19 + if logged_user:
      20 + lists_for_user = mailman.get_user_mailinglists(logged_user)
      21 +
      22 + q1 = Q(mailinglist__name__in=lists_for_user)
    1
    08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
    Carlos Coêlho started a discussion on the outdated diff
    last updated by Carlos Coêlho
    colab/accounts/utils/mailman.py
    64 65 return lists.json()
    65 66  
    66 67  
      68 +def is_private_list(name):
      69 + return dict(all_lists(private=True))[name]
    1
    • 08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
      Carlos Coêlho @carlos

      Why not try to validate name, because it'll return KeyError if it doesn't exist, or try to use the get method.

      Choose File ...   File name...
      Cancel
    08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
    Carlos Coêlho started a discussion on the outdated diff
    last updated by Carlos Coêlho
    colab/super_archives/management/commands/message.py
    79 79 return body.strip()
    80 80  
    81 81 def get_received_datetime(self):
    82   - if self not in ('Received'):
      82 + if ('Received') not in self:
    1
    • 08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
      Carlos Coêlho @carlos

      Is this supposed to be a tuple or str? If str, there's no meaning using the parenthesis else add a comma to the end of the str to tell it's a tuple.

      Choose File ...   File name...
      Cancel
    08d286e4ed2d9bc51fc10057fc32a3d4?s=40&d=identicon
    Carlos Coêlho started a discussion on the outdated diff
    last updated by Carlos Coêlho
    colab/super_archives/views.py
    122 134 def get(self, request):
    123 135 MAX = 6
    124 136 context = {}
    125   - all_lists = mailman.all_lists(description=True)
      137 +
      138 + all_privates = {}
      139 + private_mailinglist = MailingList.objects.filter(is_private=True)
      140 + for ml in private_mailinglist:
    1
  • C6b14af78e51fba6beb90142971240cc?s=40&d=identicon
    Gustavo Jaruga Cruz @darksshades

    ALL done.

    Choose File ...   File name...
    Cancel