Exemple #1
0
 def webext_permissions(self):
     """Return permissions that should be displayed, with descriptions, in
     defined order:
     1) match all urls (e.g. <all-urls>)
     2) known permissions, in constants order (alphabetically),
     3) match urls for sites
     """
     out, urls = [], []
     for name in self.webext_permissions_list:
         perm = WEBEXT_PERMISSIONS.get(name, None)
         if perm:
             # Add known permissions, including match-alls.
             if perm not in out:
                 # We don't want duplicates.
                 out.append(perm)
         elif '//' in name:
             # Filter out match urls so we can group them.
             urls.append(name)
         # Other strings are unknown permissions we don't care about
     out.sort()
     if len(urls) == 1:
         out.append(Permission(
             u'single-match',
             _(u'Access your data for {name}')
             .format(name=urls[0]), ''))
     elif len(urls) > 1:
         details = (u'<details><summary>{copy}</summary><ul>{sites}</ul>'
                    u'</details>')
         copy = _(u'Access your data on various websites')
         sites = ''.join(
             [u'<li>%s</li>' % jinja2_escape(name) for name in urls])
         out.append(Permission(
             u'multiple-match',
             mark_safe(details.format(copy=copy, sites=sites)), ''))
     return out
Exemple #2
0
def trap_duplicate(request, manifest_url):
    # See if this user has any other apps with the same manifest.
    owned = request.user.addonuser_set.filter(addon__manifest_url=manifest_url)
    if not owned:
        return
    try:
        app = owned[0].addon
    except Webapp.DoesNotExist:
        return
    error_url = app.get_dev_url()
    msg = None
    if app.status == mkt.STATUS_PUBLIC:
        msg = _(
            u"Oops, looks like you already submitted that manifest "
            "for %s, which is currently public. "
            '<a href="%s">Edit app</a>'
        )
    elif app.status == mkt.STATUS_PENDING:
        msg = _(
            u"Oops, looks like you already submitted that manifest "
            "for %s, which is currently pending. "
            '<a href="%s">Edit app</a>'
        )
    elif app.status == mkt.STATUS_NULL:
        msg = _(
            u"Oops, looks like you already submitted that manifest "
            "for %s, which is currently incomplete. "
            '<a href="%s">Resume app</a>'
        )
    elif app.status == mkt.STATUS_REJECTED:
        msg = _(
            u"Oops, looks like you already submitted that manifest "
            "for %s, which is currently rejected. "
            '<a href="%s">Edit app</a>'
        )
    elif app.status == mkt.STATUS_DISABLED:
        msg = _(
            u"Oops, looks like you already submitted that manifest "
            "for %s, which is currently banned on Marketplace. "
            '<a href="%s">Edit app</a>'
        )
    elif app.disabled_by_user:
        msg = _(
            u"Oops, looks like you already submitted that manifest "
            "for %s, which is currently disabled. "
            '<a href="%s">Edit app</a>'
        )
    if msg:
        return msg % (jinja2_escape(app.name), error_url)
Exemple #3
0
    def webext_permissions(self):
        """Return permissions that should be displayed, with descriptions, in
        defined order:
        1) Either the match all permission, if present (e.g. <all-urls>), or
           match urls for sites (<all-urls> takes preference over match urls)
        2) nativeMessaging permission, if present
        3) other known permissions in alphabetical order
        """
        knowns = list(
            WebextPermissionDescription.objects.filter(
                name__in=self.webext_permissions_list))

        urls = []
        match_url = None
        for name in self.webext_permissions_list:
            if re.match(WebextPermissionDescription.MATCH_ALL_REGEX, name):
                match_url = WebextPermissionDescription.ALL_URLS_PERMISSION
            elif name == WebextPermission.NATIVE_MESSAGING_NAME:
                # Move nativeMessaging to front of the list
                for index, perm in enumerate(knowns):
                    if perm.name == WebextPermission.NATIVE_MESSAGING_NAME:
                        knowns.pop(index)
                        knowns.insert(0, perm)
                        break
            elif '//' in name:
                # Filter out match urls so we can group them.
                urls.append(name)
            # Other strings are unknown permissions we don't care about

        if match_url is None and len(urls) == 1:
            match_url = Permission(
                u'single-match',
                ugettext(u'Access your data for {name}').format(name=urls[0]))
        elif match_url is None and len(urls) > 1:
            details = (u'<details><summary>{copy}</summary><ul>{sites}</ul>'
                       u'</details>')
            copy = ugettext(u'Access your data on the following websites:')
            sites = ''.join(
                [u'<li>%s</li>' % jinja2_escape(name) for name in urls])
            match_url = Permission(
                u'multiple-match',
                mark_safe(details.format(copy=copy, sites=sites)))

        return ([match_url] if match_url else []) + knowns
Exemple #4
0
    def webext_permissions(self):
        """Return permissions that should be displayed, with descriptions, in
        defined order:
        1) Either the match all permission, if present (e.g. <all-urls>), or
           match urls for sites (<all-urls> takes preference over match urls)
        2) nativeMessaging permission, if present
        3) other known permissions in alphabetical order
        """
        knowns = list(WebextPermissionDescription.objects.filter(
            name__in=self.webext_permissions_list).iterator())

        urls = []
        match_url = None
        for name in self.webext_permissions_list:
            if re.match(WebextPermissionDescription.MATCH_ALL_REGEX, name):
                match_url = WebextPermissionDescription.ALL_URLS_PERMISSION
            elif name == WebextPermission.NATIVE_MESSAGING_NAME:
                # Move nativeMessaging to front of the list
                for index, perm in enumerate(knowns):
                    if perm.name == WebextPermission.NATIVE_MESSAGING_NAME:
                        knowns.pop(index)
                        knowns.insert(0, perm)
                        break
            elif '//' in name:
                # Filter out match urls so we can group them.
                urls.append(name)
            # Other strings are unknown permissions we don't care about

        if match_url is None and len(urls) == 1:
            match_url = Permission(
                u'single-match',
                ugettext(u'Access your data for {name}')
                .format(name=urls[0]))
        elif match_url is None and len(urls) > 1:
            details = (u'<details><summary>{copy}</summary><ul>{sites}</ul>'
                       u'</details>')
            copy = ugettext(u'Access your data on the following websites:')
            sites = ''.join(
                [u'<li>%s</li>' % jinja2_escape(name) for name in urls])
            match_url = Permission(
                u'multiple-match',
                mark_safe(details.format(copy=copy, sites=sites)))

        return ([match_url] if match_url else []) + knowns
Exemple #5
0
def trap_duplicate(request, manifest_url):
    # See if this user has any other apps with the same manifest.
    owned = (request.user.addonuser_set
             .filter(addon__manifest_url=manifest_url))
    if not owned:
        return
    try:
        app = owned[0].addon
    except Webapp.DoesNotExist:
        return
    error_url = app.get_dev_url()
    msg = None
    if app.status == mkt.STATUS_PUBLIC:
        msg = _(u'Oops, looks like you already submitted that manifest '
                'for %s, which is currently public. '
                '<a href="%s">Edit app</a>')
    elif app.status == mkt.STATUS_PENDING:
        msg = _(u'Oops, looks like you already submitted that manifest '
                'for %s, which is currently pending. '
                '<a href="%s">Edit app</a>')
    elif app.status == mkt.STATUS_NULL:
        msg = _(u'Oops, looks like you already submitted that manifest '
                'for %s, which is currently incomplete. '
                '<a href="%s">Resume app</a>')
    elif app.status == mkt.STATUS_REJECTED:
        msg = _(u'Oops, looks like you already submitted that manifest '
                'for %s, which is currently rejected. '
                '<a href="%s">Edit app</a>')
    elif app.status == mkt.STATUS_DISABLED:
        msg = _(u'Oops, looks like you already submitted that manifest '
                'for %s, which is currently banned on Marketplace. '
                '<a href="%s">Edit app</a>')
    elif app.disabled_by_user:
        msg = _(u'Oops, looks like you already submitted that manifest '
                'for %s, which is currently disabled. '
                '<a href="%s">Edit app</a>')
    if msg:
        return msg % (jinja2_escape(app.name), error_url)