Пример #1
0
def format_ticket_message(context, message, **kwargs):
    if not issubclass(message.__class__, Message):
        raise TypeError("{} isn't subclass object of".format(message, Message))
    tag_context = {'css_style': '', 'message': message,
                   'css_class': 'form-row',
                   'model': message._meta.model_name,
                   'can_view_report': False}
    if 'helpdesk_user' in context:
        hu = HelpdeskUser(context['helpdesk_user'])
        if hu.is_operator() or hu.is_admin():
            tag_context['can_view_report'] = True

    if 'css_class' in kwargs:
        tag_context.update({'css_class': kwargs['css_class']})
    try:
        if message.report:
            opts = message.report._meta
            tag_context.update({'model': opts.model_name,
                'css_style': 'text-align: right;',
                'view_url': '{}?id={}'.format(
                    reverse(admin_urlname(opts, 'changelist')),
                    message.report.pk)})
    except ObjectDoesNotExist:
        pass
    return tag_context
Пример #2
0
def format_ticket_message(context, message, **kwargs):
    if not issubclass(message.__class__, Message):
        raise TypeError("{} isn't subclass object of".format(message, Message))
    tag_context = {
        'css_style': '',
        'message': message,
        'css_class': 'form-row',
        'model': message._meta.model_name,
        'can_view_report': False
    }
    if 'helpdesk_user' in context:
        hu = HelpdeskUser(context['helpdesk_user'])
        if hu.is_operator() or hu.is_admin():
            tag_context['can_view_report'] = True

    if 'css_class' in kwargs:
        tag_context.update({'css_class': kwargs['css_class']})
    try:
        if message.report:
            opts = message.report._meta
            tag_context.update({
                'model':
                opts.model_name,
                'css_style':
                'text-align: right;',
                'view_url':
                '{}?id={}'.format(reverse(admin_urlname(opts, 'changelist')),
                                  message.report.pk)
            })
    except ObjectDoesNotExist:
        pass
    return tag_context
def format_ticket_message(context, message, **kwargs):
    if not issubclass(message.__class__, Message):
        raise TypeError("{} isn't subclass object of".format(message, Message))
    tag_context = {
        "css_style": "",
        "message": message,
        "css_class": "form-row",
        "model": message._meta.model_name,
        "can_view_report": False,
    }
    if "helpdesk_user" in context:
        hu = HelpdeskUser(context["helpdesk_user"])
        if hu.is_operator() or hu.is_admin():
            tag_context["can_view_report"] = True

    if "css_class" in kwargs:
        tag_context.update({"css_class": kwargs["css_class"]})
    try:
        if message.report:
            opts = message.report._meta
            tag_context.update(
                {
                    "model": opts.model_name,
                    "css_style": "text-align: right;",
                    "view_url": "{}?id={}".format(reverse(admin_urlname(opts, "changelist")), message.report.pk),
                }
            )
    except ObjectDoesNotExist:
        pass
    return tag_context
Пример #4
0
 def test_group_names_property(self, mock_groups):
     user = UserFactory()
     mock_groups.values_list.return_value = ['g1', 'g2']
     hu = HelpdeskUser(user)
     group_names = hu.group_names
     self.assertEqual(group_names, ['g1', 'g2'])
     mock_groups.values_list.assert_called_once_with('name', flat=True)
Пример #5
0
def rf_with_helpdeskuser(request, rf):
    rf.user = None

    class HelpdeskUser(object):
        def is_requester(self):
            return False

        def is_operator(self):
            return False

        def is_admin(self):
            return False

    rf.user = HelpdeskUser()
    return rf
Пример #6
0
 def test_is_requester_return_false(self):
     hu = HelpdeskUser(UserFactory())
     self.assertFalse(hu.is_requester())
Пример #7
0
 def test_is_admins_return_true(self, mock_settings):
     mock_settings.HELPDESK_ADMINS = HELPDESK_ADMINS[0]
     hu = HelpdeskUser(
         UserFactory(groups=[GroupFactory(name=HELPDESK_ADMINS[0])]))
     self.assertTrue(hu.is_admin())
Пример #8
0
 def test_is_operator_return_true(self, mock_settings):
     mock_settings.HELPDESK_OPERATORS = HELPDESK_OPERATORS[0]
     hu = HelpdeskUser(
         UserFactory(groups=[GroupFactory(name=HELPDESK_OPERATORS[0])]))
     self.assertTrue(hu.is_operator())
Пример #9
0
 def test_is_requester_return_true(self, mock_settings):
     mock_settings.HELPDESK_REQUESTERS = HELPDESK_REQUESTERS[0]
     hu = HelpdeskUser(
         UserFactory(groups=[GroupFactory(name=HELPDESK_REQUESTERS[0])]))
     self.assertTrue(hu.is_requester())
Пример #10
0
 def test_is_admin_return_false(self):
     hu = HelpdeskUser(UserFactory())
     self.assertFalse(hu.is_admin())
Пример #11
0
 def test_is_requester_return_false(self):
     hu = HelpdeskUser(UserFactory())
     self.assertFalse(hu.is_requester())
Пример #12
0
 def test_is_admins_return_true(self, mock_settings):
     mock_settings.HELPDESK_ADMINS = HELPDESK_ADMINS[0]
     hu = HelpdeskUser(UserFactory(
         groups=[GroupFactory(name=HELPDESK_ADMINS[0])]))
     self.assertTrue(hu.is_admin())
Пример #13
0
 def test_is_operator_return_true(self, mock_settings):
     mock_settings.HELPDESK_OPERATORS = HELPDESK_OPERATORS[0]
     hu = HelpdeskUser(
         UserFactory(groups=[GroupFactory(name=HELPDESK_OPERATORS[0])]))
     self.assertTrue(hu.is_operator())
Пример #14
0
 def test_is_requester_return_true(self, mock_settings):
     mock_settings.HELPDESK_REQUESTERS = HELPDESK_REQUESTERS[0]
     hu = HelpdeskUser(
         UserFactory(groups=[GroupFactory(name=HELPDESK_REQUESTERS[0])]))
     self.assertTrue(hu.is_requester())
Пример #15
0
 def test_is_admin_return_false(self):
     hu = HelpdeskUser(UserFactory())
     self.assertFalse(hu.is_admin())