Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 41 additions & 41 deletions addons/base/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
import pytz
#import pytz
import httplib
import os
import uuid
Expand Down Expand Up @@ -437,7 +437,7 @@ def create_waterbutler_log(payload, **kwargs):

if action in (NodeLog.FILE_ADDED, NodeLog.FILE_UPDATED):
add_result = upload_file_add_timestamptoken(payload, node)

node_addon.create_waterbutler_log(auth, action, metadata)

with transaction.atomic():
Expand Down Expand Up @@ -697,9 +697,9 @@ def addon_view_or_download_file(auth, path, provider, **kwargs):
return dict(guid=guid._id)

if action == 'addtimestamp':
add_timestamp_result = adding_timestamp(auth, node, file_node, version)
if add_timestamp_result == 0:
raise HTTPError(httplib.BAD_REQUEST, data={
add_timestamp_result = adding_timestamp(auth, node, file_node, version)
if add_timestamp_result == 0:
raise HTTPError(httplib.BAD_REQUEST, data={
'message_short': 'Add TimestampError',
'message_long': 'AddTimestamp setting error.'
})
Expand Down Expand Up @@ -730,7 +730,7 @@ def addon_view_file(auth, node, file_node, version):
error = None

ret = serialize_node(node, auth, primary=True)
verify_result = timestamptoken_verify(auth, node,
verify_result = timestamptoken_verify(auth, node,
file_node, version, ret['user']['id'])

if file_node._id + '-' + version._id not in node.file_guid_to_share_uuids:
Expand Down Expand Up @@ -784,7 +784,7 @@ def addon_view_file(auth, node, file_node, version):
'allow_comments': file_node.provider in settings.ADDONS_COMMENTABLE,
'checkout_user': file_node.checkout._id if file_node.checkout else None,
'pre_reg_checkout': is_pre_reg_checkout(node, file_node),
'timestamp_verify_result': verify_result['verify_result'],
'timestamp_verify_result': verify_result['verify_result'],
'timestamp_verify_result_title': verify_result['verify_result_title']
})

Expand Down Expand Up @@ -818,39 +818,40 @@ def upload_file_add_timestamptoken(payload, node):

verify_result = 0
tmp_dir = None
try:
try:
metadata = payload['metadata']
file_node = BaseFileNode.resolve_class(metadata['provider'], BaseFileNode.FILE).get_or_create(node, metadata['path'])
file_node.save()
auth_id = payload['auth']['id']
guid = Guid.objects.get(_id=auth_id)
user_info = OSFUser.objects.get(id=guid.object_id)
cookie = user_info.get_or_create_cookie()
cookies = {settings.COOKIE_NAME:cookie}
headers = {"content-type": "application/json"}
cookies = {settings.COOKIE_NAME: cookie}
headers = {'content-type': 'application/json'}
res_content = None
if metadata['provider'] == 'osfstorage':
res = requests.get(file_node.generate_waterbutler_url(**dict(action='download',
res = requests.get(file_node.generate_waterbutler_url(**dict(action='download',
version=metadata['extra']['version'], direct=None, _internal=False)), headers=headers, cookies=cookies)
else:
res = requests.get(file_node.generate_waterbutler_url(**dict(action='download', mode=None, _internal=False)),
res = requests.get(file_node.generate_waterbutler_url(**dict(action='download', mode=None, _internal=False)),
headers=headers, cookies=cookies)
res_content = res.content
res.close()

current_datetime = timezone.now()
current_datetime_str = current_datetime.strftime("%Y%m%d%H%M%S%f")
current_datetime_str = current_datetime.strftime('%Y%m%d%H%M%S%f')
#print(current_datetime_str)
tmp_dir='tmp_{}_{}_{}'.format(auth_id, file_node._id, current_datetime_str)
tmp_dir = 'tmp_{}_{}_{}'.format(auth_id, file_node._id, current_datetime_str)
os.mkdir(tmp_dir)
download_file_path = os.path.join(tmp_dir, metadata['name'])
with open(download_file_path, "wb") as fout:
with open(download_file_path, 'wb') as fout:
fout.write(res_content)

addTimestamp = AddTimestamp()
verify_result, verify_result_title, operator_user, operator_date, filepath = addTimestamp.add_timestamp(auth_id, metadata['path'],
node._id, metadata['provider'],
metadata['materialized'],
download_file_path, tmp_dir)
verify_result, verify_result_title, operator_user, operator_date, filepath = addTimestamp.add_timestamp(auth_id, file_node._id,
node._id, metadata['provider'],
metadata['materialized'],
download_file_path, tmp_dir)
shutil.rmtree(tmp_dir)
except Exception as err:
if tmp_dir:
Expand All @@ -866,25 +867,25 @@ def adding_timestamp(auth, node, file_node, version):
from api.timestamp.add_timestamp import AddTimestamp
import shutil

verify_result = 0
#verify_result = 0
tmp_dir = None
try:
ret = serialize_node(node, auth, primary=True)
user_info = OSFUser.objects.get(id=Guid.objects.get(_id=ret['user']['id']).object_id)
cookie = user_info.get_or_create_cookie()
cookies = {settings.COOKIE_NAME:cookie}
headers = {"content-type": "application/json"}
res = requests.get(file_node.generate_waterbutler_url(**dict(action='download',
version=version.identifier, mode=None, _internal=False)),
cookies = {settings.COOKIE_NAME: cookie}
headers = {'content-type': 'application/json'}
res = requests.get(file_node.generate_waterbutler_url(**dict(action='download',
version=version.identifier, mode=None, _internal=False)),
headers=headers, cookies=cookies)
tmp_dir='tmp_{}'.format(ret['user']['id'])
tmp_dir = 'tmp_{}'.format(ret['user']['id'])
os.mkdir(tmp_dir)
tmp_file = os.path.join(tmp_dir, file_node.name)
with open(tmp_file, "wb") as fout:
with open(tmp_file, 'wb') as fout:
fout.write(res.content)
res.close()
addTimestamp = AddTimestamp()
result = addTimestamp.add_timestamp(ret['user']['id'],
result = addTimestamp.add_timestamp(ret['user']['id'],
file_node._id,
node._id, file_node.provider,
file_node._path,
Expand All @@ -902,34 +903,33 @@ def adding_timestamp(auth, node, file_node, version):

def timestamptoken_verify(auth, node, file_node, version, guid):
from api.timestamp.timestamptoken_verify import TimeStampTokenVerifyCheck
from api.timestamp import local
import requests
from osf.models import Guid
import shutil

verify_result = 0
verify_title = None
tmp_dir='tmp_{}'.format(guid)
#verify_result = 0
#verify_title = None
tmp_dir = 'tmp_{}'.format(guid)
current_datetime = timezone.now()
current_datetime_str = current_datetime.strftime("%Y%m%d%H%M%S%f")
tmp_dir='tmp_{}_{}_{}'.format(guid, file_node._id, current_datetime_str)
current_datetime_str = current_datetime.strftime('%Y%m%d%H%M%S%f')
tmp_dir = 'tmp_{}_{}_{}'.format(guid, file_node._id, current_datetime_str)
try:
ret = serialize_node(node, auth, primary=True)
user_info = OSFUser.objects.get(id=Guid.objects.get(_id=ret['user']['id']).object_id)
cookie = user_info.get_or_create_cookie()
cookies = {settings.COOKIE_NAME:cookie}
headers = {"content-type": "application/json"}
res = requests.get(file_node.generate_waterbutler_url(**dict(action='download',
cookies = {settings.COOKIE_NAME: cookie}
headers = {'content-type': 'application/json'}
res = requests.get(file_node.generate_waterbutler_url(**dict(action='download',
version=version.identifier, mode=None, _internal=False)), headers=headers, cookies=cookies)
if not os.path.exists(tmp_dir):
os.mkdir(tmp_dir)
os.mkdir(tmp_dir)
tmp_file = os.path.join(tmp_dir, file_node.name)
with open(tmp_file, "wb") as fout:
with open(tmp_file, 'wb') as fout:
fout.write(res.content)
res.close()
verifyCheck = TimeStampTokenVerifyCheck()
result = verifyCheck.timestamp_check(ret['user']['id'],file_node._id,node._id,
file_node.provider, file_node._path,
result = verifyCheck.timestamp_check(ret['user']['id'], file_node._id, node._id,
file_node.provider, file_node._path,
tmp_file, tmp_dir)
shutil.rmtree(tmp_dir)
except Exception as err:
Expand Down
9 changes: 5 additions & 4 deletions admin/rdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
MAGIC_INSTITUTION_ID = 0

class RdmPermissionMixin(object):

@property
def is_authenticated(self):
"""ログインしているかどうかを判定する。"""
Expand All @@ -22,7 +22,7 @@ def is_super_admin(self):
if user.is_superuser:
return True
return False

@property
def is_admin(self):
"""機関管理者かどうか判定する。"""
Expand Down Expand Up @@ -64,8 +64,9 @@ def get_institution_id(user):
def get_dummy_institution():
"""ユーザがInstitutionに所属していない場合のために、
ダミーのInstitutionモデルのオブジェクトを取得するする。"""
class DummyInstitution(object): pass
class DummyInstitution(object):
pass
dummy_institution = DummyInstitution()
dummy_institution.id = MAGIC_INSTITUTION_ID
dummy_institution.name = ''
return dummy_institution
return dummy_institution
2 changes: 1 addition & 1 deletion admin/rdm_addons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def webpack_asset(path):

@register.filter
def external_account_id(account):
return account['_id']
return account['_id']
4 changes: 2 additions & 2 deletions admin/rdm_addons/api_v1/add/dataverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.core.exceptions import ValidationError

from osf.models import RdmAddonOption, ExternalAccount
from osf.models import ExternalAccount
from admin.rdm_addons.utils import get_rdm_addon_option
from addons.dataverse.models import DataverseProvider
from addons.dataverse import client
Expand Down Expand Up @@ -37,4 +37,4 @@ def add_account(json_request, institution_id, addon_name):
if not rdm_addon_option.external_accounts.filter(id=provider.account.id).exists():
rdm_addon_option.external_accounts.add(provider.account)

return {}, httplib.OK
return {}, httplib.OK
4 changes: 2 additions & 2 deletions admin/rdm_addons/api_v1/add/owncloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import requests
from django.core.exceptions import ValidationError

from osf.models import RdmAddonOption, ExternalAccount
from osf.models import ExternalAccount
from admin.rdm_addons.utils import get_rdm_addon_option

import owncloud
from addons.owncloud.models import OwnCloudProvider
from addons.owncloud.serializer import OwnCloudSerializer
#from addons.owncloud.serializer import OwnCloudSerializer
from addons.owncloud import settings


Expand Down
4 changes: 2 additions & 2 deletions admin/rdm_addons/api_v1/add/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.exceptions import ValidationError

from framework.exceptions import HTTPError
from osf.models import RdmAddonOption, ExternalAccount
from osf.models import ExternalAccount
from admin.rdm_addons.utils import get_rdm_addon_option
from addons.s3.views import SHORT_NAME, FULL_NAME
from addons.s3.utils import get_user_info, can_list
Expand Down Expand Up @@ -64,4 +64,4 @@ def add_account(json_request, institution_id, addon_name):
if not rdm_addon_option.external_accounts.filter(id=account.id).exists():
rdm_addon_option.external_accounts.add(account)

return {}, httplib.OK
return {}, httplib.OK
2 changes: 1 addition & 1 deletion admin/rdm_addons/api_v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
url(r'^oauth/accounts/(?P<external_account_id>\w+)/(?P<institution_id>-?[0-9]+)/$', views.OAuthView.as_view(), name='oauth'),
url(r'^settings/(?P<addon_name>\w+)/(?P<institution_id>-?[0-9]+)/$', views.SettingsView.as_view(), name='settings'),
url(r'^settings/(?P<addon_name>\w+)/(?P<institution_id>-?[0-9]+)/accounts/$', views.AccountsView.as_view(), name='accounts'),
]
]
9 changes: 2 additions & 7 deletions admin/rdm_addons/api_v1/views.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
# -*- coding: utf-8 -*-

import os
import json
import httplib

from django.views.generic import View
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.mixins import UserPassesTestMixin
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
from django.core.exceptions import ValidationError
from django.http import HttpResponse, Http404, HttpResponseForbidden, HttpResponseServerError
from django.http import HttpResponse, Http404
from django.http.response import JsonResponse
from django.utils.decorators import method_decorator
import flask

from osf.models import Institution, RdmAddonOption, ExternalAccount
from osf.models import ExternalAccount
from admin.rdm.utils import RdmPermissionMixin
from admin.rdm_addons.utils import get_rdm_addon_option
from framework.auth import Auth
import addons
import admin


class OAuthView(RdmPermissionMixin, UserPassesTestMixin, View):
Expand Down
2 changes: 1 addition & 1 deletion admin/rdm_addons/oauth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# OSF側からOSFAdminにアクセスする際に利用する
# 秘密のアクセストークン
CALLBACK_SECRET_TOKEN='7440b3be-831b-4abf-b8c9-7319ed534809'
CALLBACK_SECRET_TOKEN = '7440b3be-831b-4abf-b8c9-7319ed534809'
2 changes: 1 addition & 1 deletion admin/rdm_addons/oauth/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
url(r'^callback/(?P<addon_name>\w+)/$', views.CallbackView.as_view(), name='callback'),
url(r'^complete/(?P<addon_name>\w+)/$', views.CompleteView.as_view(), name='complete'),
url(r'^accounts/(?P<external_account_id>\w+)/(?P<institution_id>-?[0-9]+)/$', views.AccountsView.as_view(), name='disconnect'),
]
]
21 changes: 10 additions & 11 deletions admin/rdm_addons/oauth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@

import uuid
from collections import defaultdict
from urlparse import parse_qsl
import requests
from requests.compat import urlparse, urlunparse, urlencode, urljoin
#from urlparse import parse_qsl
#import requests
from requests.compat import urljoin
from django.views.generic import View, TemplateView
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.mixins import UserPassesTestMixin
from django.core.urlresolvers import reverse
#from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from django.http import HttpResponse, Http404, HttpResponseForbidden
from django.http.response import JsonResponse
from django.http import HttpResponse
#from django.http.response import JsonResponse
from django.utils.decorators import method_decorator
import flask
from werkzeug.datastructures import ImmutableMultiDict

import osf
import addons
from osf.models import RdmAddonOption, ExternalAccount
#from osf.models import RdmAddonOption, ExternalAccount
from admin.rdm.utils import RdmPermissionMixin
from admin.rdm_addons.utils import get_rdm_addon_option
from admin.rdm_addons.api_v1.views import disconnect
from website.oauth.utils import get_service
from website.routes import make_url_map
from website import settings as website_settings
from admin.base import settings as admin_settings
from . import CALLBACK_SECRET_TOKEN
#from admin.base import settings as admin_settings
#from . import CALLBACK_SECRET_TOKEN

class RdmAddonRequestContextMixin(object):
app = flask.Flask(__name__)
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_func(self):
def get(self, request, *args, **kwargs):
addon_name = kwargs['addon_name']
institution_id = int(kwargs['institution_id'])

# Session
if not request.session.session_key:
request.session.create()
Expand Down Expand Up @@ -157,4 +157,3 @@ def delete(self, request, *args, **kwargs):
institution_id = int(kwargs['institution_id'])
user = self.request.user
return disconnect(external_account_id, institution_id, user)

2 changes: 1 addition & 1 deletion admin/rdm_addons/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
url(r'^icon/(?P<addon_name>\w+)/(?P<icon_filename>\w+\.\w+)$', views.IconView.as_view(), name='icon'),
url(r'^api/v1/', include('admin.rdm_addons.api_v1.urls', namespace='api_v1')),
url(r'^oauth/', include('admin.rdm_addons.oauth.urls', namespace='oauth')),
]
]
2 changes: 1 addition & 1 deletion admin/rdm_addons/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import os
import glob
#import glob

from django.urls import reverse

Expand Down
Loading