owner could be an org or and user
423412
def get_repositores(owner_url, token, nrepos):
    
    all_repos = []

    url = owner_url

    while True:
        logging.debug("Getting repos from: %s" % (url))
        try:
            r = requests.get(url,
                             params=get_payload(),
                             headers=get_headers(token))

            r.raise_for_status()
            all_repos += r.json()

            logging.debug("Rate limit: %s" % (r.headers['X-RateLimit-Remaining']))

            if 'next' not in r.links:
                break

            url = r.links['next']['url']  # Loving requests :)
        except requests.exceptions.ConnectionError:
            logging.error("Can not connect to GitHub")
            break

    # Remove forks
    nrepos_recent = [repo for repo in all_repos if not repo['fork']]
    # Sort by updated_at and limit to nrepos
    nrepos_sorted = sorted(nrepos_recent, key=lambda repo: parser.parse(repo['updated_at']), reverse=True)
    nrepos_sorted = nrepos_sorted[0:nrepos]
    # First the small repositories to feedback the user quickly
    nrepos_sorted = sorted(nrepos_sorted, key=lambda repo: repo['size'])
    for repo in nrepos_sorted:
        logging.debug("%s %i %s" % (repo['updated_at'], repo['size'], repo['name']))
    return nrepos_sorted
979212
def has_permission(self, request, *args, **kwargs):
        
        self.kwargs = kwargs
        self.args = args
        self.request = request
        self.org = self.derive_org()

        if self.get_user().is_superuser:
            return True

        if self.get_user().has_perm(self.permission):
            return True

        return self.has_org_perm(self.permission)
148180
def change_owner(self, new_owner):
        
        old_owner = self.owner.organization_user
        self.owner.organization_user = new_owner
        self.owner.save()

        # Owner changed signal
        owner_changed.send(sender=self, old=old_owner, new=new_owner)
172126
def can_access(self, user):
        
        return self.class_.is_admin(user) or \
            self.is_ready and self.class_ in user.classes
922515
def add_user(self, user, is_admin=False):
        
        users_count = self.users.all().count()
        if users_count == 0:
            is_admin = True
        # TODO get specific org user?
        org_user = self._org_user_model.objects.create(
            user=user, organization=self, is_admin=is_admin
        )
        if users_count == 0:
            # TODO get specific org user?
            self._org_owner_model.objects.create(
                organization=self, organization_user=org_user
            )

        # User added signal
        user_added.send(sender=self, user=user)
        return org_user
889675
def get_owner_ids_value(self, obj):
        """"""
        return [
            user.pk
            for user in get_users_with_permission(obj, get_full_perm('owner', obj))
        ]
499654
def owned_pre_save(sender, document, **kwargs):
    '''
    
    '''
    if not isinstance(document, Owned):
        return
    changed_fields = getattr(document, '_changed_fields', [])
    if 'organization' in changed_fields:
        if document.owner:
            # Change from owner to organization
            document._previous_owner = document.owner
            document.owner = None
        else:
            # Change from org to another
            # Need to fetch previous value in base
            original = sender.objects.only('organization').get(pk=document.pk)
            document._previous_owner = original.organization
    elif 'owner' in changed_fields:
        if document.organization:
            # Change from organization to owner
            document._previous_owner = document.organization
            document.organization = None
        else:
            # Change from owner to another
            # Need to fetch previous value in base
            original = sender.objects.only('owner').get(pk=document.pk)
            document._previous_owner = original.owner
898526
def is_product_owner(self, team_id):
        """"""

        if self.is_super_admin():
            return True
        team_id = uuid.UUID(str(team_id))
        return team_id in self.child_teams_ids
217745
def _set_ownership(self):
        
        if self.owner or self.group:
            args = (
                self.path,
                self.owner if self.owner else -1,
                self.group if self.group else -1,
            )
            logger.debug("changing ownership bits of %s to %s", self.path, args)
            os.chown(*args)
709516
def owner(self):
        
        if self._owner:
            return self._owner
        elif not self.abstract:
            return self.read_meta()._owner

        raise EmptyDocumentException()
847899
def set_owner(self):
        """"""
        owner = self.soup.find('itunes:owner')
        try:
            self.owner_name = owner.find('itunes:name').string
        except AttributeError:
            self.owner_name = None
        try:
            self.owner_email = owner.find('itunes:email').string
        except AttributeError:
            self.owner_email = None
223082
def load_owner
      unless params[:owner_id].nil?
        if current_owner.present?

          # we need to try and look this owner up via the find method so that we're
          # taking advantage of any override of the find method that would be provided
          # by older versions of friendly_id. (support for newer versions default behavior
          # below.)
          searched_owner = current_owner.class.find(params[:owner_id]) rescue nil

          # if we couldn't find them that way, check whether there is a new version of
          # friendly_id in place that we can use to look them up by their slug.
          # in christoph's words, "why?!" in my words, "warum?!!!"
          # (we debugged this together on skype.)
          if searched_owner.nil? && current_owner.class.respond_to?(:friendly)
            searched_owner = current_owner.class.friendly.find(params[:owner_id]) rescue nil
          end

          if current_owner.try(:id) == searched_owner.try(:id)
            @owner = current_owner
          else
            customer = Subscription.find_customer(searched_owner)
            customer_2 = Subscription.find_customer(current_owner)
            # susbscription we are looking for belongs to the same user but to a different
            # subscription owner
            # e.g. user -> account -> subscription
            # same user but different accounts for example

            if customer_2.try(:id) == customer.try(:id)
              @owner = searched_owner
            else
              return unauthorized
            end
          end
        else
          return unauthorized
        end
      end
    end
489894
private void completeOwners(Symbol o) {
        if (o.kind != PCK) completeOwners(o.owner);
        o.complete();
    }
1083112
def _linked_attribute(self, owner):
        
        return self.via or (utils.inflection.underscore(owner.__name__) + '_id')
985775
private void addOwner(UNode ownerNode) {
        String ownerName = ownerNode.getName();
        SortedMap<String, RESTCommand> ownerMap = new TreeMap<>();
        m_cmdsByOwnerMap.put(ownerName, ownerMap);
        for (UNode cmdNode : ownerNode.getMemberList()) {
            RESTCommand cmd = RESTCommand.fromUNode(cmdNode);
            ownerMap.put(cmd.getName(), cmd);
        }
    }
291958
def owner? obj, relation=nil
      if relation     
        return true if user_relation?(obj, relation)
      end                                
      [:user, :owner, :author].each do |relation|        
        return true if user_relation?(obj, relation)
      end
      false
    end
806570
def owner(self):
        
        obj = javabridge.call(self.jobject, "getOwner", "()Lweka/core/CapabilitiesHandler;")
        if obj is None:
            return None
        else:
            return JavaObject(jobject=obj)