Prints out a users permissions
976484
def print_permissions(permissions):
    """"""

    table = formatting.Table(['keyName', 'Description'])
    for perm in permissions:
        table.add_row([perm['keyName'], perm['name']])
    return table
969415
def detail_permissions(self, request, pk=None):
        """"""
        obj = self.get_object()

        if request.method == 'POST':
            content_type = ContentType.objects.get_for_model(obj)
            payload = request.data
            share_content = strtobool(payload.pop('share_content', 'false'))
            user = request.user
            is_owner = user.has_perm('owner_{}'.format(content_type), obj=obj)

            allow_owner = is_owner or user.is_superuser
            check_owner_permission(payload, allow_owner)
            check_public_permissions(payload)
            check_user_permissions(payload, request.user.pk)

            with transaction.atomic():
                update_permission(obj, payload)

                owner_count = UserObjectPermission.objects.filter(
                    object_pk=obj.id,
                    content_type=content_type,
                    permission__codename__startswith='owner_'
                ).count()

                if not owner_count:
                    raise exceptions.ParseError('Object must have at least one owner.')

            if share_content:
                self.set_content_permissions(user, obj, payload)

        return Response(get_object_perms(obj))
1347708
def get_user_permissions(self, username):
        

        path = Client.urls['user_permissions'] % (username,)
        conns = self._call(path, 'GET')
        return conns
893014
def cli(obj, scopes):
    """"""
    client = obj['client']
    query = [('scopes', s) for s in scopes]

    if obj['output'] == 'json':
        r = client.http.get('/perms', query)
        click.echo(json.dumps(r['permissions'], sort_keys=True, indent=4, ensure_ascii=False))
    else:
        headers = {'id': 'ID', 'scopes': 'SCOPES', 'match': 'ROLE'}
        click.echo(tabulate([p.tabular() for p in client.get_perms(query)], headers=headers, tablefmt=obj['output']))
516109
def permission_to_04_acls(permissions):
    
    acls = []
    for perm in permissions:
        if perm.type == "user":
            acls.append((perm.user.id, perm.perm_name))
        elif perm.type == "group":
            acls.append(("group:%s" % perm.group.id, perm.perm_name))
    return acls
516657
def _get_all_permissions(opts):
    ""
    perms = []
    for action in settings.DEFAULT_PERMISSIONS:
        perms.append((_get_permission_codename(action, opts), 'Can %s %s' % (action, opts.verbose_name_raw)))
    return perms + list(opts.permissions)
339565
private void ajaxGetPermissions(final Project project, final HashMap<String, Object> ret) {
    final ArrayList<HashMap<String, Object>> permissions =
        new ArrayList<>();
    for (final Pair<String, Permission> perm : project.getUserPermissions()) {
      final HashMap<String, Object> permObj = new HashMap<>();
      final String userId = perm.getFirst();
      permObj.put("username", userId);
      permObj.put("permission", perm.getSecond().toStringArray());

      permissions.add(permObj);
    }

    ret.put("permissions", permissions);
  }
317087
def _permission_trees(permissions):
        """"""
        treecache = PermissionTreeCache()
        cached = treecache.get()
        if not cached:
            tree = PermissionTreeBuilder()
            for permission in permissions:
                tree.insert(permission)
            result = tree.serialize()
            treecache.set(result)
            return result
        return cached
984114
def _check_permission(self, request):
        

        if self.access_controller:
            self.access_controller.check_perm(request, self)
690241
def _load_permissions(campus, calendarid, resp_fragment, permission_list):
    
    for record in resp_fragment:
        if not _is_valid_email(record['Email']):
            # skip the non UW users
            continue
        perm = Permission()
        perm.calendarid = calendarid
        perm.campus = campus
        perm.uwnetid = _extract_uwnetid(record['Email'])
        perm.level = record['Level']
        perm.name = str(record['Name'])
        permission_list.append(perm)
1337935
def get_permissions(self, role):
        """"""
        target_role = AuthGroup.objects(role=role, creator=self.client).first()
        if not target_role:
            return '[]'
        targets = AuthPermission.objects(groups=target_role, creator=self.client).only('name')
        return json.loads(targets.to_json())
54040
def parse_permissions(perms):
    
    if isinstance(perms, six.string_types):
        perms = perms.split(',')
    perms = [perm.strip().lower() for perm in perms]
    if 'all' in perms:
        return ALL_PERMISSIONS
    return validate_permissions(perms)
1166463
def handle(self, **options):
        """"""
        perm_map = {}
        with open('eighth_activity_permissions.csv', 'r') as absperms:
            perms = csv.reader(absperms)
            for row in perms:
                aid, uid = row
                try:
                    usr = User.objects.get(id=uid)
                except User.DoesNotExist:
                    self.stdout.write("User {} doesn't exist, aid {}".format(uid, aid))
                else:
                    if aid in perm_map:
                        perm_map[aid].append(usr)
                    else:
                        perm_map[aid] = [usr]

        for aid in perm_map:
            try:
                act = EighthActivity.objects.get(id=aid)
            except EighthActivity.DoesNotExist:
                self.stdout.write("Activity {} doesn't exist".format(aid))
            else:
                self.stdout.write("{}: {}".format(aid, EighthActivity.objects.get(id=aid)))
                grp, _ = Group.objects.get_or_create(name="{} -- Permissions".format("{}".format(act)[:55]))
                users = perm_map[aid]
                for u in users:
                    u.groups.add(grp)
                    u.save()
                act.groups_allowed.add(grp)
                act.save()

        self.stdout.write("Done.")
447738
def check_permissions(self, request):
        
        obj = (
            hasattr(self, 'get_controlled_object') and self.get_controlled_object() or
            hasattr(self, 'get_object') and self.get_object() or getattr(self, 'object', None)
        )
        user = request.user

        # Get the permissions to check
        perms = self.get_required_permissions(self)

        # Check permissions
        has_permissions = self.perform_permissions_check(user, obj, perms)

        if not has_permissions and not user.is_authenticated:
            return HttpResponseRedirect('{}?{}={}'.format(
                resolve_url(self.login_url),
                self.redirect_field_name,
                urlquote(request.get_full_path())
            ))
        elif not has_permissions:
            raise PermissionDenied
926398
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_access_moderation_queue(user)
609237
def permissions(self):
        """"""
        perms = set()
        for g in self.groups:
            perms = perms | set(g.permissions)
        return perms
1239598
def permission_table(user_permissions, all_permissions):
    """"""

    table = formatting.Table(['Description', 'KeyName', 'Assigned'])
    table.align['KeyName'] = 'l'
    table.align['Description'] = 'l'
    table.align['Assigned'] = 'l'
    for perm in all_permissions:
        assigned = user_permissions.get(perm['keyName'], False)
        table.add_row([perm['name'], perm['keyName'], assigned])
    return table