Skip to content

Commit

Permalink
add basic code for making a narrative share request
Browse files Browse the repository at this point in the history
  • Loading branch information
briehl committed Jan 18, 2019
1 parent 4a70358 commit 309f814
Show file tree
Hide file tree
Showing 17 changed files with 584 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
test_local
sdk.cfg
.DS_Store
.vscode
28 changes: 28 additions & 0 deletions NarrativeService.spec
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,32 @@ module NarrativeService {
associated object UPA in the return value.
*/
funcdef find_object_report(FindObjectReportParams params) returns (FindObjectReportOutput) authentication required;

/*
ws_id: The workspace id containing the narrative to share
share_level: The level of sharing requested - one of "r" (read), "w" (write), "a" (admin)
user: The user to be shared with
*/
typedef structure {
int ws_id;
string share_level;
string user;
} RequestNarrativeShareInput;

/*
ok: 0 if the request failed, 1 if the request succeeded.
error (optional): if a failure happened during the request, this has a reason why. Not present if it succeeded.
*/
typedef structure {
boolean ok;
string error;
} RequestNarrativeShareOutput;

/*
This sends a notification to the admins of a workspace (or anyone with share privileges) that a
user would like access to it.

If a request has already been made, this will fail and return with the string "a request has already been made"
*/
funcdef request_narrative_share(RequestNarrativeShareInput params) returns (RequestNarrativeShareOutput) authentication required;
};
5 changes: 5 additions & 0 deletions dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[ {
"module_name" : "KBaseReport",
"type" : "sdk",
"version_tag" : "release"
} ]
5 changes: 5 additions & 0 deletions deploy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ auth-service-url = {{ auth_service_url }}
auth-service-url-allow-insecure = {{ auth_service_url_allow_insecure }}
{% endif %}
narrative-method-store = {{ kbase_endpoint }}/narrative_method_store/rpc
{% if feeds_url %}
feeds-url = {{ feeds_url }}
{% else %}
feeds-url = {{ kbase_endpoint }}/feeds
{% endif %}
setapi-version = release
datapaletteservice-version = dev
scratch = /kb/module/work/tmp
Expand Down
186 changes: 183 additions & 3 deletions lib/NarrativeService/NarrativeServiceClient.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,107 @@ associated object UPA in the return value.
}
}



=head2 request_narrative_share
$return = $obj->request_narrative_share($params)
=over 4
=item Parameter and return types
=begin html
<pre>
$params is a NarrativeService.RequestNarrativeShareInput
$return is a NarrativeService.RequestNarrativeShareOutput
RequestNarrativeShareInput is a reference to a hash where the following keys are defined:
ws_id has a value which is an int
share_level has a value which is a string
user has a value which is a string
RequestNarrativeShareOutput is a reference to a hash where the following keys are defined:
ok has a value which is a NarrativeService.boolean
error has a value which is a string
boolean is an int
</pre>
=end html
=begin text
$params is a NarrativeService.RequestNarrativeShareInput
$return is a NarrativeService.RequestNarrativeShareOutput
RequestNarrativeShareInput is a reference to a hash where the following keys are defined:
ws_id has a value which is an int
share_level has a value which is a string
user has a value which is a string
RequestNarrativeShareOutput is a reference to a hash where the following keys are defined:
ok has a value which is a NarrativeService.boolean
error has a value which is a string
boolean is an int
=end text
=item Description
This sends a notification to the admins of a workspace (or anyone with share privileges) that a
user would like access to it.
If a request has already been made, this will fail and return with the string "a request has already been made"
=back
=cut

sub request_narrative_share
{
my($self, @args) = @_;

# Authentication: required

if ((my $n = @args) != 1)
{
Bio::KBase::Exceptions::ArgumentValidationError->throw(error =>
"Invalid argument count for function request_narrative_share (received $n, expecting 1)");
}
{
my($params) = @args;

my @_bad_arguments;
(ref($params) eq 'HASH') or push(@_bad_arguments, "Invalid type for argument 1 \"params\" (value was \"$params\")");
if (@_bad_arguments) {
my $msg = "Invalid arguments passed to request_narrative_share:\n" . join("", map { "\t$_\n" } @_bad_arguments);
Bio::KBase::Exceptions::ArgumentValidationError->throw(error => $msg,
method_name => 'request_narrative_share');
}
}

my $url = $self->{url};
my $result = $self->{client}->call($url, $self->{headers}, {
method => "NarrativeService.request_narrative_share",
params => \@args,
});
if ($result) {
if ($result->is_error) {
Bio::KBase::Exceptions::JSONRPC->throw(error => $result->error_message,
code => $result->content->{error}->{code},
method_name => 'request_narrative_share',
data => $result->content->{error}->{error} # JSON::RPC::ReturnObject only supports JSONRPC 1.1 or 1.O
);
} else {
return wantarray ? @{$result->result} : $result->result->[0];
}
} else {
Bio::KBase::Exceptions::HTTP->throw(error => "Error invoking method request_narrative_share",
status_line => $self->{client}->status_line,
method_name => 'request_narrative_share',
);
}
}


sub status
{
Expand Down Expand Up @@ -1366,16 +1467,16 @@ sub version {
Bio::KBase::Exceptions::JSONRPC->throw(
error => $result->error_message,
code => $result->content->{code},
method_name => 'find_object_report',
method_name => 'request_narrative_share',
);
} else {
return wantarray ? @{$result->result} : $result->result->[0];
}
} else {
Bio::KBase::Exceptions::HTTP->throw(
error => "Error invoking method find_object_report",
error => "Error invoking method request_narrative_share",
status_line => $self->{client}->status_line,
method_name => 'find_object_report',
method_name => 'request_narrative_share',
);
}
}
Expand Down Expand Up @@ -2772,6 +2873,85 @@ error has a value which is a string
=head2 RequestNarrativeShareInput
=over 4
=item Description
ws_id: The workspace id containing the narrative to share
share_level: The level of sharing requested - one of "r" (read), "w" (write), "a" (admin)
user: The user to be shared with
=item Definition
=begin html
<pre>
a reference to a hash where the following keys are defined:
ws_id has a value which is an int
share_level has a value which is a string
user has a value which is a string
</pre>
=end html
=begin text
a reference to a hash where the following keys are defined:
ws_id has a value which is an int
share_level has a value which is a string
user has a value which is a string
=end text
=back
=head2 RequestNarrativeShareOutput
=over 4
=item Description
ok: 0 if the request failed, 1 if the request succeeded.
error (optional): if a failure happened during the request, this has a reason why. Not present if it succeeded.
=item Definition
=begin html
<pre>
a reference to a hash where the following keys are defined:
ok has a value which is a NarrativeService.boolean
error has a value which is a string
</pre>
=end html
=begin text
a reference to a hash where the following keys are defined:
ok has a value which is a NarrativeService.boolean
error has a value which is a string
=end text
=back
=cut

package NarrativeService::NarrativeServiceClient::RpcClient;
Expand Down
21 changes: 21 additions & 0 deletions lib/NarrativeService/NarrativeServiceClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,27 @@ def find_object_report(self, params, context=None):
'NarrativeService.find_object_report',
[params], self._service_ver, context)

def request_narrative_share(self, params, context=None):
"""
This sends a notification to the admins of a workspace (or anyone with share privileges) that a
user would like access to it.
If a request has already been made, this will fail and return with the string "a request has already been made"
:param params: instance of type "RequestNarrativeShareInput" (ws_id:
The workspace id containing the narrative to share share_level:
The level of sharing requested - one of "r" (read), "w" (write),
"a" (admin) user: The user to be shared with) -> structure:
parameter "ws_id" of Long, parameter "share_level" of String,
parameter "user" of String
:returns: instance of type "RequestNarrativeShareOutput" (ok: 0 if
the request failed, 1 if the request succeeded. error (optional):
if a failure happened during the request, this has a reason why.
Not present if it succeeded.) -> structure: parameter "ok" of type
"boolean" (@range [0,1]), parameter "error" of String
"""
return self._client.call_method(
'NarrativeService.request_narrative_share',
[params], self._service_ver, context)

def status(self, context=None):
return self._client.call_method('NarrativeService.status',
[], self._service_ver, context)
36 changes: 34 additions & 2 deletions lib/NarrativeService/NarrativeServiceImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from NarrativeService.DynamicServiceCache import DynamicServiceCache
from NarrativeService.NarrativeListUtils import NarrativeListUtils, NarratorialUtils
from NarrativeService.ReportFetcher import ReportFetcher
from NarrativeService.sharing.sharemanager import ShareRequester
#END_HEADER


Expand All @@ -23,9 +24,9 @@ class NarrativeService:
# state. A method could easily clobber the state set by another while
# the latter method is running.
######################################### noqa
VERSION = "0.0.8"
VERSION = "0.0.9"
GIT_URL = "https://github.com/briehl/NarrativeService"
GIT_COMMIT_HASH = "54bdae6c8eb4219b4af1a711c0749ada96d36c1d"
GIT_COMMIT_HASH = "4a703588c98d2f013d483efca81b10194bfb0a8e"

#BEGIN_CLASS_HEADER
def _nm(self, ctx):
Expand Down Expand Up @@ -558,6 +559,37 @@ def find_object_report(self, ctx, params):
'returnVal is not type dict as required.')
# return the results
return [returnVal]

def request_narrative_share(self, ctx, params):
"""
This sends a notification to the admins of a workspace (or anyone with share privileges) that a
user would like access to it.
If a request has already been made, this will fail and return with the string "a request has already been made"
:param params: instance of type "RequestNarrativeShareInput" (ws_id:
The workspace id containing the narrative to share share_level:
The level of sharing requested - one of "r" (read), "w" (write),
"a" (admin) user: The user to be shared with) -> structure:
parameter "ws_id" of Long, parameter "share_level" of String,
parameter "user" of String
:returns: instance of type "RequestNarrativeShareOutput" (ok: 0 if
the request failed, 1 if the request succeeded. error (optional):
if a failure happened during the request, this has a reason why.
Not present if it succeeded.) -> structure: parameter "ok" of type
"boolean" (@range [0,1]), parameter "error" of String
"""
# ctx is the context object
# return variables are: returnVal
#BEGIN request_narrative_share
sm = ShareRequester(params)
returnVal = sm.request_share()
#END request_narrative_share

# At some point might do deeper type checking...
if not isinstance(returnVal, dict):
raise ValueError('Method request_narrative_share return value ' +
'returnVal is not type dict as required.')
# return the results
return [returnVal]
def status(self, ctx):
#BEGIN_STATUS
returnVal = {'state': "OK",
Expand Down
4 changes: 4 additions & 0 deletions lib/NarrativeService/NarrativeServiceServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ def __init__(self):
name='NarrativeService.find_object_report',
types=[dict])
self.method_authentication['NarrativeService.find_object_report'] = 'required' # noqa
self.rpc_service.add(impl_NarrativeService.request_narrative_share,
name='NarrativeService.request_narrative_share',
types=[dict])
self.method_authentication['NarrativeService.request_narrative_share'] = 'required' # noqa
self.rpc_service.add(impl_NarrativeService.status,
name='NarrativeService.status',
types=[dict])
Expand Down
11 changes: 11 additions & 0 deletions lib/NarrativeService/feeds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import requests

def make_notification(note, feeds_url, auth_token):
# calls the feeds service
try:
headers = {"Authorization": auth_token}
r = requests.post("feeds_url" + "/api/V1/notification", json=note, headers=headers)
r.raise_for_status()
return r.json()["id"]
except requests.HTTPError as e:
raise RuntimeError("Unable to create notification: {}".format(str(e)))
Empty file.
Loading

0 comments on commit 309f814

Please sign in to comment.