Example #1
0
 def to_json(self, user):
     ret = super(NodeSettings, self).to_json(user)
     user_settings = user.get_addon('github')
     ret.update({
         'user_has_auth': user_settings and user_settings.has_auth,
         'is_registration': self.owner.is_registration,
     })
     if self.has_auth:
         valid_credentials = False
         owner = self.user_settings.owner
         connection = GitHubClient(external_account=self.external_account)
         # TODO: Fetch repo list client-side
         # Since /user/repos excludes organization repos to which the
         # current user has push access, we have to make extra requests to
         # find them
         valid_credentials = True
         try:
             repos = itertools.chain.from_iterable(
                 (connection.repos(), connection.my_org_repos()))
             repo_names = [
                 '{0} / {1}'.format(repo.owner.login, repo.name)
                 for repo in repos
             ]
         except GitHubError:
             repo_names = []
             valid_credentials = False
         if owner == user:
             ret.update({'repo_names': repo_names})
         ret.update({
             'node_has_auth':
             True,
             'github_user':
             self.user or '',
             'github_repo':
             self.repo or '',
             'github_repo_full_name':
             '{0} / {1}'.format(self.user, self.repo) if
             (self.user and self.repo) else '',
             'auth_osf_name':
             owner.fullname,
             'auth_osf_url':
             owner.url,
             'auth_osf_id':
             owner._id,
             'github_user_name':
             self.external_account.display_name,
             'github_user_url':
             self.external_account.profile_url,
             'is_owner':
             owner == user,
             'valid_credentials':
             valid_credentials,
             'addons_url':
             web_url_for('user_addons'),
             'files_url':
             self.owner.web_url_for('collect_file_trees')
         })
     return ret
 def get_folders(self, **kwargs):
     if not self.has_auth:
         raise exceptions.InvalidAuthError()
     else:
         connection = GitHubClient(external_account=self.external_account)
         # Since /user/repos excludes organization repos to which the
         # current user has push access, we have to make extra requests to
         # find them
         try:
             repo_data = [{
                 'addon': 'github',
                 'kind': 'repo',
                 'id': repo.id,
                 'name': repo.name,
                 'path': os.path.join(repo.owner.login, repo.name)
             } for repo in connection.repos()]
         except GitHubError:
             repo_data = []
         return repo_data
Example #3
0
 def to_json(self, user):
     ret = super(NodeSettings, self).to_json(user)
     user_settings = user.get_addon('github')
     ret.update({
         'user_has_auth': user_settings and user_settings.has_auth,
         'is_registration': self.owner.is_registration,
     })
     if self.has_auth:
         valid_credentials = False
         owner = self.user_settings.owner
         connection = GitHubClient(external_account=self.external_account)
         # TODO: Fetch repo list client-side
         # Since /user/repos excludes organization repos to which the
         # current user has push access, we have to make extra requests to
         # find them
         valid_credentials = True
         try:
             repos = itertools.chain.from_iterable((connection.repos(), connection.my_org_repos()))
             repo_names = [
                 '{0} / {1}'.format(repo.owner.login, repo.name)
                 for repo in repos
             ]
         except GitHubError:
             repo_names = []
             valid_credentials = False
         if owner == user:
             ret.update({'repo_names': repo_names})
         ret.update({
             'node_has_auth': True,
             'github_user': self.user or '',
             'github_repo': self.repo or '',
             'github_repo_full_name': '{0} / {1}'.format(self.user, self.repo) if (self.user and self.repo) else '',
             'auth_osf_name': owner.fullname,
             'auth_osf_url': owner.url,
             'auth_osf_id': owner._id,
             'github_user_name': self.external_account.display_name,
             'github_user_url': self.external_account.profile_url,
             'is_owner': owner == user,
             'valid_credentials': valid_credentials,
             'addons_url': web_url_for('user_addons'),
             'files_url': self.owner.web_url_for('collect_file_trees')
         })
     return ret
Example #4
0
 def get_folders(self, **kwargs):
     if not self.has_auth:
         raise exceptions.InvalidAuthError()
     else:
         connection = GitHubClient(external_account=self.external_account)
         # Since /user/repos excludes organization repos to which the
         # current user has push access, we have to make extra requests to
         # find them
         try:
             repo_data = [
                 {
                     'addon': 'github',
                     'kind': 'repo',
                     'id': repo.id,
                     'name': repo.name,
                     'path': os.path.join(repo.owner.login, repo.name)
                 }
                 for repo in connection.repos()]
         except GitHubError:
             repo_data = []
         return repo_data