Check per-field privacy rules in aggregations.

        Privacy is checked by making sure user has access to the fields
        used in aggregations.
774162
def check_aggregations_privacy(self, aggregations_params):
        
        fields = self.get_aggregations_fields(aggregations_params)
        fields_dict = dictset.fromkeys(fields)
        fields_dict['_type'] = self.view.Model.__name__

        try:
            validate_data_privacy(self.view.request, fields_dict)
        except wrappers.ValidationError as ex:
            raise JHTTPForbidden(
                'Not enough permissions to aggregate on '
                'fields: {}'.format(ex))
585875
def has_perm(self, perm, obj, check_groups=True, approved=True):
        
        if self.user:
            if self.has_user_perms(perm, obj, approved, check_groups):
                return True
        if self.group:
            return self.has_group_perms(perm, obj, approved)
        return False
665717
def check_permissions(self):
        
        # Variable to supply some feedback
        changed_permissions = []
        changed_users = []
        warnings = []

        # Check that all the permissions are available.
        for model, perms in ASSIGNED_PERMISSIONS.items():
            if model == 'profile':
                model_obj = get_profile_model()
            else: model_obj = get_user_model()

            model_content_type = ContentType.objects.get_for_model(model_obj)

            for perm in perms:
                try:
                    Permission.objects.get(codename=perm[0],
                                           content_type=model_content_type)
                except Permission.DoesNotExist:
                    changed_permissions.append(perm[1])
                    Permission.objects.create(name=perm[1],
                                              codename=perm[0],
                                              content_type=model_content_type)

        # it is safe to rely on settings.ANONYMOUS_USER_NAME since it is a
        # requirement of django-guardian
        for user in get_user_model().objects.exclude(username=settings.ANONYMOUS_USER_NAME):
            try:
                user_profile = get_user_profile(user=user)
            except ObjectDoesNotExist:
                warnings.append(_("No profile found for %(username)s") \
                                    % {'username': user.username})
            else:
                all_permissions = get_perms(user, user_profile) + get_perms(user, user)

                for model, perms in ASSIGNED_PERMISSIONS.items():
                    if model == 'profile':
                        perm_object = get_user_profile(user=user)
                    else: perm_object = user

                    for perm in perms:
                        if perm[0] not in all_permissions:
                            assign_perm(perm[0], user, perm_object)
                            changed_users.append(user)

        return (changed_permissions, changed_users, warnings)
6132
public boolean checkIndexField(BaseField field)
    {
        for (int iKeySeq = 0; iKeySeq < this.getRecord().getKeyAreaCount(); iKeySeq++)
        {
            KeyArea keyArea = this.getRecord().getKeyArea(iKeySeq);
            if (keyArea.getField(0) == field)
                if (field != this.getRecord().getCounterField())
                    return true;
        }
        return false;
    }
394815
def validate_with_permissions(self, val, caller_permissions):
        
        self.validate(val)
        self.validate_fields_only_with_permissions(val, caller_permissions)
        return val
1047192
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_update_topics_to_sticky_topics(obj, user)
520048
function filterAttributes(object, permissions) {
		if (object) {
			var userType = req.activeUser && req.activeUser.type || 'null';
			for (var attribute in object._doc) {
				if (object._doc.hasOwnProperty(attribute)) {
					// dont return this attribute when:
					if (!permissions[attribute] || // if this attribute is not defined in permissions
						permissions[attribute][0] !== 'null' && // this attribute is not set as public
						permissions[attribute].indexOf(userType) === -1 && // this attribute is not available to this userType
						userType !== 'admin' // the user is not admin
					) {
						delete object._doc[attribute];
					}
				}
			}
		}

		return object;
	}
811328
def validate(self) :
        """"""
        self._store.validate()
        for pField in self.collection.arangoPrivates :
            self.collection.validatePrivate(pField, getattr(self, pField))
763962
private function isAggregated($field)
    {
        $cols = $this->getDataGrid()->getColModel();
        
        foreach ($cols as $col){
            if ($col['index'] === $field && isset($col['aggregated']) && $col['aggregated'] === true){
                return true;
            }
        }
        
        return false;
    }
1346157
function is_private()
    {
        $now = time();

        foreach ($this->subkeys as $subkey)
            if ($subkey->has_private)
                return true;

        return false;
    }
1264744
public boolean isSet(_Fields field) {
    if (field == null) {
      throw new IllegalArgumentException();
    }

    switch (field) {
    case ID:
      return is_set_id();
    case NAME:
      return is_set_name();
    case STATUS:
      return is_set_status();
    case UPTIME_SECS:
      return is_set_uptimeSecs();
    case NUM_TASKS:
      return is_set_numTasks();
    case NUM_WORKERS:
      return is_set_numWorkers();
    case ERROR_INFO:
      return is_set_errorInfo();
    }
    throw new IllegalStateException();
  }
382589
protected function meetsConditions()
    {
        // If profile visibility is public, it can be display
        // for everyone, so users can edit own profiles.
        if (isset($this->visibility) && $this->visibility === 'public') {
            return true;
        }

        // Profile is hidden. Can be displayed only
        // for users that can edit user profiles.
        return $this->auth->user()->can('edit_user');
    }
987161
public String checkAccess (Permission perm, Object context)
    {
        if (_permPolicy == null) {
            _permPolicy = createPermissionPolicy();
        }
        return _permPolicy.checkAccess(perm, context);
    }
15547
def has_a_matching_perm(self, perm_list, obj=None):
        
        # If there are no permissions to check, just return true
        if not perm_list:
            return True
        # Check that user has at least one of the required permissions.
        for perm in perm_list:
            if self.has_perm(perm, obj):
                return True
        return False
753229
def has_object_permission(self, request, view, obj):
        
        # Give permission if we're not protecting this method
        if self.protected_methods and request.method not in self.protected_methods:
            return True

        user = getattr(request, "user", None)

        if not user or user.is_anonymous():
            return False

        if self.require_staff and not user.is_staff:
            return False

        # if they have higher-level privileges we can return true right now
        if user.has_perms(self.permissions):
            return True

        # no? ok maybe they're the author and have appropriate author permissions.
        authors_field = getattr(obj, self.authors_field, None)

        if not authors_field:
            return False

        if self.author_permissions and not user.has_perms(self.author_permissions):
            return False

        return user in authors_field.all()
1072223
def permitted_query(self, query, group, operations):
        ''''''
        session = query.session
        models = session.router
        user = group.user
        if user.is_superuser:   # super-users have all permissions
            return query
        roles = group.roles.query()
        roles = group.roles.query()  # query on all roles for group
        # The throgh model for Role/Permission relationship
        throgh_model = models.role.permissions.model
        models[throgh_model].filter(role=roles,
                                    permission__model_type=query.model,
                                    permission__operations=operations)

        # query on all relevant permissions
        permissions = router.permission.filter(model_type=query.model,
                                               level=operations)

        owner_query = query.filter(user=user)
        # all roles for the query model with appropriate permission level
        roles = models.role.filter(model_type=query.model, level__ge=level)
        # Now we need groups which have these roles
        groups = Role.groups.throughquery(
            session).filter(role=roles).get_field('group')
        # I need to know if user is in any of these groups
        if user.groups.filter(id=groups).count():
            # it is, lets get the model with permissions less
            # or equal permission level
            permitted = models.instancerole.filter(
                role=roles).get_field('object_id')
            return owner_query.union(model.objects.filter(id=permitted))
        else:
            return owner_query
411043
def check_user(self, user_id):
        

        if self.hidden == 'N':
            return True

        for owner in self.owners:
            if int(owner.user_id) == int(user_id):
                if owner.view == 'Y':
                    return True
        return False