Skip to content

Commit

Permalink
make bitbucket configurable via api v2
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Nov 20, 2023
1 parent 3141057 commit 72905e3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
36 changes: 35 additions & 1 deletion addons/bitbucket/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
from framework.auth import Auth
from osf.models.external import ExternalProvider
from osf.models.files import File, Folder, BaseFileNode
from rest_framework import exceptions as drf_exceptions
from website import settings
from website.util import web_url_for
from website.util import web_url_for, api_v2_url

hook_domain = bitbucket_settings.HOOK_DOMAIN or settings.DOMAIN

Expand Down Expand Up @@ -454,3 +455,36 @@ def before_make_public(self, node):

def after_delete(self, user):
self.deauthorize(Auth(user=user), log=True)

def get_folders(self, path, folder_id):
return [{
'id': repo['full_name'],
'path': '/',
'addon': 'bitbucket',
'kind': 'folder',
'name': repo['full_name'],
'urls': {
'folders': api_v2_url(f'nodes/{self.owner._id}/addons/bitbucket/folders/'),
}
} for repo in BitbucketClient(access_token=self.external_account.oauth_key).repos()]

def set_folder(self, folder_id, auth):
connection = BitbucketClient(access_token=self.external_account.oauth_key)
if not connection.repo(self.user, folder_id):
raise drf_exceptions.PermissionDenied(f'The credentials provided are incorrect.')

if folder_id != self.repo:
self.repo = folder_id
self.owner.add_log(
action='bitbucket_repo_linked',
params={
'project': self.owner.parent_id,
'node': self.owner._id,
'bitbucket': {
'user': self.external_account.display_name,
'repo': folder_id
}
},
auth=auth
)
self.save()
4 changes: 2 additions & 2 deletions api/base/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@
VARNISH_SERVERS = osf_settings.VARNISH_SERVERS
ESI_MEDIA_TYPES = osf_settings.ESI_MEDIA_TYPES

ADDONS_FOLDER_CONFIGURABLE = ['box', 'dropbox', 's3', 'googledrive', 'figshare', 'owncloud', 'onedrive']
ADDONS_OAUTH = ADDONS_FOLDER_CONFIGURABLE + ['dataverse', 'github', 'bitbucket', 'gitlab', 'mendeley', 'zotero', 'forward', 'boa']
ADDONS_FOLDER_CONFIGURABLE = ['box', 'dropbox', 's3', 'googledrive', 'figshare', 'owncloud', 'onedrive', 'bitbucket']
ADDONS_OAUTH = ADDONS_FOLDER_CONFIGURABLE + ['dataverse', 'github', 'gitlab', 'mendeley', 'zotero', 'forward', 'boa']

BYPASS_THROTTLE_TOKEN = 'test-token'

Expand Down
2 changes: 1 addition & 1 deletion api_tests/nodes/views/test_node_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ class TestNodeWikiAddon(NodeUnmanageableAddonTestSuiteMixin, ApiAddonTestCase):

# OAUTH

class TestNodeBitbucketAddon(NodeOAuthAddonTestSuiteMixin, ApiAddonTestCase):
class TestNodeBitbucketAddon(NodeConfigurableAddonTestSuiteMixin, ApiAddonTestCase):
short_name = 'bitbucket'
AccountFactory = BitbucketAccountFactory
NodeSettingsFactory = BitbucketNodeSettingsFactory
Expand Down

0 comments on commit 72905e3

Please sign in to comment.