示例#1
0
 def test_user_has_no_permissions(self):
     self.client.force_login(self.user2)
     clean_actions = actor_stream(self.user)
     filtered_actions = check_activity_permissions(self.user2,
                                                   clean_actions)
     # the filtered actions must be empty because the user2 has no permissions
     self.assertEqual(filtered_actions.count(), 0)
     pass
示例#2
0
def update_activity_stream_for_user(user, actor=False):
    user = get_user_model().objects.get(username=user)
    if actor:
        item_list = actor_stream(user)
        cache.set('activity_items_actor_'+user.username, item_list, 60*60*24*31)
    else:
        item_list = check_activity_permissions(user, user_stream(user))
        cache.set('activity_items_'+user.username, item_list, 60*60*24*31)
    return
示例#3
0
    def get_context_data(self, **kwargs):
        # get the user for this profile page
        user = get_r_object_or_404(self.request.user, get_user_model(), username=self.kwargs.get("username"))
        # get the actor stream for the requested user profile
        item_list = cache.get('activity_items_actor_'+user.username)
        if not item_list:
            item_list = actor_stream(user)
            cache.set('activity_items_actor_'+user.username, item_list, 60*60*24*31)

        # filter out actions with targets the requesting user is not part of
        self.item_list = check_activity_permissions(self.request.user, item_list)

        # get this user
        selfuser = get_r_object_or_404(self.request.user, get_user_model(), username=self.request.user.username)
        sharedprojects = Project.objects.filter(developer=user).filter(developer=selfuser)
        sharedissues = Issue.objects.filter(assignee=user).filter(assignee=selfuser)

        # create the context
        context = super(ShowProfilePageView, self).get_context_data(**kwargs)
        context['sharedprojects'] = sharedprojects
        context['sharedissues'] = sharedissues
        context['nocollapse'] = self.request.session.get('nocollapse', '')
        if context['nocollapse'] != '':
            del self.request.session['nocollapse']

        # add data for notifications

        prefs = {}
        try:
            prefs = json.loads(user.get_preference('notify_mail'))
        except (TypeError, json.JSONDecodeError):
            pass

        # there shall be an entry for every project the user is member of
        for uproj in user.get_projects():
            if uproj.name_short not in prefs:
                prefs[uproj.name_short] = []

        context['notify_mail'] = prefs

        notitypes = []

        for t in Notitype.NOTI_TYPES:
            notitypes.append([t[0], t[1]])

        context['possible_notis'] = notitypes

        # add data for activity chart type
        if self.request.GET.get('data') is not None:
            self.request.user.set_preference('activity_chart_type',
                                             self.request.GET.get('data'))
        data = self.request.user.get_preference('activity_chart_type',
                                                default="timelog")
        context['chart_type'] = data

        return context
示例#4
0
文件: views.py 项目: yasir2000/iguana
    def get(self, request, *args, **kwargs):
        # show dashboard if a user is logged in
        if request.user.is_authenticated:
            self.template_name = "landing_page/dashboard.html"

            # check if the user wants to unfollow a project
            if request.GET.get("unfollow", "") != "":
                unfollow_project(
                    request.user,
                    Project.objects.get(pk=request.GET['unfollow']))

            # get the items of the activity stream
            self.item_list = cache.get('activity_items_' +
                                       request.user.username)
            if not self.item_list:
                self.item_list = check_activity_permissions(
                    request.user, user_stream(request.user))
                cache.set('activity_items_' + request.user.username,
                          self.item_list, 60 * 60 * 24 * 31)

        else:
            self.template_name = "landing_page/home.html"

        return TemplateView.get(self, request, *args, **kwargs)
示例#5
0
 def test_user_has_permissions(self):
     clean_actions = actor_stream(self.user)
     filtered_actions = check_activity_permissions(self.user, clean_actions)
     # the two query sets must be equal when the user has permissions on the issue/project
     self.assertQuerysetEqual(clean_actions,
                              [a.__repr__() for a in filtered_actions])