Skip to content

Commit

Permalink
Add usertype to wopiopen
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Mar 10, 2023
1 parent 7a47a6c commit 33e9215
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tools/wopiopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@
import configparser
import requests
sys.path.append('src') # for tests out of the git repo
from core.wopiutils import ViewMode # noqa: E402
from core.wopiutils import ViewMode, UserType # noqa: E402


# usage function
def usage(exitcode):
'''Prints usage'''
print('Usage : ' + sys.argv[0] + ' -a|--appname <app_name> -u|--appurl <app_url> [-i|--appinturl <app_url>] '
'-k|--apikey <api_key> [-s|--storage <storage_endpoint>] [-v|--viewmode VIEW_ONLY|READ_ONLY|READ_WRITE|PREVIEW] '
'[-x|--x-access-token <reva_token>] <filename>')
'[-t|--user-type REGULAR|FEDERATED|ANONYMOUS] [-x|--x-access-token <reva_token>] <filename>')
sys.exit(exitcode)


# first parse the options
try:
options, args = getopt.getopt(sys.argv[1:], 'hv:s:a:i:u:x:k:',
['help', 'viewmode', 'storage', 'appname', 'appinturl', 'appurl', 'x-access-token', 'apikey'])
options, args = getopt.getopt(sys.argv[1:], 'hv:t:s:a:i:u:x:k:',
['help', 'viewmode', 'usertype', 'storage', 'appname', 'appinturl', 'appurl',
'x-access-token', 'apikey'])
except getopt.GetoptError as e:
print(e)
usage(1)
viewmode = ViewMode.READ_WRITE
usertype = UserType.REGULAR
endpoint = ''
appname = ''
appurl = ''
Expand All @@ -49,6 +51,12 @@ def usage(exitcode):
except ValueError:
print("Invalid argument for viewmode: " + v)
usage(1)
elif f == '-t' or f == '--usertype':
try:
usertype = UserType(v)
except ValueError:
print("Invalid argument for usertype: " + v)
usage(1)
elif f == '-s' or f == '--storage':
endpoint = v
elif f == '-i' or f == '--appinturl':
Expand Down Expand Up @@ -111,8 +119,8 @@ def usage(exitcode):

# open the file and get WOPI token
wopiheaders = {'Authorization': 'Bearer ' + iopsecret}
wopiparams = {'fileid': filename, 'endpoint': endpoint,
'viewmode': viewmode.value, 'username': 'Operator', 'userid': userid, 'folderurl': '/',
wopiparams = {'fileid': filename, 'endpoint': endpoint, 'viewmode': viewmode.value, 'usertype': usertype.value,
'username': 'Operator', 'userid': userid, 'folderurl': '/',
'appurl': appurl, 'appinturl': appinturl, 'appname': appname}
wopiheaders['TokenHeader'] = revatoken
# for bridged apps, also set the API key
Expand Down

0 comments on commit 33e9215

Please sign in to comment.