moved policy API around, fixed render/loading in UI

pull/820/merge
Justin Richer 2015-07-03 09:21:24 -04:00
parent 53922374df
commit 03b301b43b
4 changed files with 53 additions and 13 deletions

View File

@ -1109,13 +1109,15 @@ var AppRouter = Backbone.Router.extend({
this.updateSidebar('user/policy'); this.updateSidebar('user/policy');
var rs = this.resourceSetList.get(rsid); var rs = this.resourceSetList.get(rsid);
var policies = null;
if (rs == null) { if (rs == null) {
// need to load it directly // need to load it directly
var policies = new PolicyCollection([], {rsid: rsid}); policies = new PolicyCollection([], {rsid: rsid});
rs = new ResourceSetModel({id: rsid});
} else { } else {
// the resource set is loaded, preload the claims // the resource set is loaded, preload the claims
var policies = new PolicyCollection(rs.get('policies'), {rsid: rsid}); policies = new PolicyCollection(rs.get('policies'), {rsid: rsid});
policy.isFetched = true; policies.isFetched = true;
} }
var view = new PolicyListView({model: policies, rs: rs, systemScopeList: this.systemScopeList}); var view = new PolicyListView({model: policies, rs: rs, systemScopeList: this.systemScopeList});

View File

@ -16,17 +16,17 @@
*******************************************************************************/ *******************************************************************************/
var ResourceSetModel = Backbone.Model.extend({ var ResourceSetModel = Backbone.Model.extend({
urlRoot: 'api/resourceset'
}); });
var ResourceSetCollection = Backbone.Collection.extend({ var ResourceSetCollection = Backbone.Collection.extend({
model: ResourceSetModel, model: ResourceSetModel,
url: 'api/policy' url: 'api/resourceset'
}); });
var PolicyModel = Backbone.Model.extend({ var PolicyModel = Backbone.Model.extend({
urlRoot: function() { urlRoot: function() {
return 'api/policy/' + this.options.rsid + '/'; return 'api/resourceset/' + this.options.rsid + '/policy/';
}, },
initialize: function(model, options) { initialize: function(model, options) {
this.options = options; this.options = options;
@ -36,7 +36,7 @@ var PolicyModel = Backbone.Model.extend({
var PolicyCollection = Backbone.Collection.extend({ var PolicyCollection = Backbone.Collection.extend({
model: PolicyModel, model: PolicyModel,
url: function() { url: function() {
return 'api/policy/' + this.options.rsid; return 'api/resourceset/' + this.options.rsid + '/policy/';
}, },
initialize: function(models, options) { initialize: function(models, options) {
this.options = options; this.options = options;
@ -352,6 +352,11 @@ var PolicyView = Backbone.View.extend({
this.template = _.template($('#tmpl-policy').html()); this.template = _.template($('#tmpl-policy').html());
} }
if (!this.scopeTemplate) {
this.scopeTemplate = _.template($('#tmpl-scope-list').html());
}
}, },
events:{ events:{
@ -448,8 +453,9 @@ var PolicyFormView = Backbone.View.extend({
render:function (eventName) { render:function (eventName) {
var json = this.model.toJSON(); var json = this.model.toJSON();
var rs = this.options.rs.toJSON();
this.$el.html(this.template({policy: json, rs: this.options.rs})); this.$el.html(this.template({policy: json, rs: rs}));
return this; return this;
} }

View File

@ -163,6 +163,7 @@
<div class="control-group" id="scopes"> <div class="control-group" id="scopes">
<label class="control-label" data-i18n="common.scope">Scopes</label> <label class="control-label" data-i18n="common.scope">Scopes</label>
<div class="controls"> <div class="controls">
<% console.log(rs); console.log(policy); %>
<% _.each(rs.scopes, function(scope) { %> <% _.each(rs.scopes, function(scope) { %>
<div> <div>
<input type="checkbox" <input type="checkbox"

View File

@ -60,7 +60,8 @@ public class PolicyAPI {
// Logger for this class // Logger for this class
private static final Logger logger = LoggerFactory.getLogger(PolicyAPI.class); private static final Logger logger = LoggerFactory.getLogger(PolicyAPI.class);
public static final String URL = RootController.API_URL + "/policy"; public static final String URL = RootController.API_URL + "/resourceset";
public static final String POLICYURL = "/policy";
private Gson gson = new Gson(); private Gson gson = new Gson();
@ -91,6 +92,36 @@ public class PolicyAPI {
* @return * @return
*/ */
@RequestMapping(value = "/{rsid}", method = RequestMethod.GET, produces = MimeTypeUtils.APPLICATION_JSON_VALUE) @RequestMapping(value = "/{rsid}", method = RequestMethod.GET, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String getResourceSet(@PathVariable (value = "rsid") Long rsid, Model m, Authentication auth) {
ResourceSet rs = resourceSetService.getById(rsid);
if (rs == null) {
m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
return HttpCodeView.VIEWNAME;
}
if (!rs.getOwner().equals(auth.getName())) {
logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got " + auth.getName());
// authenticated user didn't match the owner of the resource set
m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
return HttpCodeView.VIEWNAME;
}
m.addAttribute(JsonEntityView.ENTITY, rs);
return JsonEntityView.VIEWNAME;
}
/**
* List all the policies for the given resource set
* @param rsid
* @param m
* @param auth
* @return
*/
@RequestMapping(value = "/{rsid}" + POLICYURL, method = RequestMethod.GET, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String getPoliciesForResourceSet(@PathVariable (value = "rsid") Long rsid, Model m, Authentication auth) { public String getPoliciesForResourceSet(@PathVariable (value = "rsid") Long rsid, Model m, Authentication auth) {
ResourceSet rs = resourceSetService.getById(rsid); ResourceSet rs = resourceSetService.getById(rsid);
@ -120,7 +151,7 @@ public class PolicyAPI {
* @param auth * @param auth
* @return * @return
*/ */
@RequestMapping(value = "/{rsid}", method = RequestMethod.POST, produces = MimeTypeUtils.APPLICATION_JSON_VALUE) @RequestMapping(value = "/{rsid}" + POLICYURL, method = RequestMethod.POST, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String createNewPolicyForResourceSet(@PathVariable (value = "rsid") Long rsid, @RequestBody String jsonString, Model m, Authentication auth) { public String createNewPolicyForResourceSet(@PathVariable (value = "rsid") Long rsid, @RequestBody String jsonString, Model m, Authentication auth) {
ResourceSet rs = resourceSetService.getById(rsid); ResourceSet rs = resourceSetService.getById(rsid);
@ -179,7 +210,7 @@ public class PolicyAPI {
* @param auth * @param auth
* @return * @return
*/ */
@RequestMapping(value = "/{rsid}/{pid}", method = RequestMethod.GET, produces = MimeTypeUtils.APPLICATION_JSON_VALUE) @RequestMapping(value = "/{rsid}" + POLICYURL + "/{pid}", method = RequestMethod.GET, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String getPolicy(@PathVariable (value = "rsid") Long rsid, @PathVariable (value = "pid") Long pid, Model m, Authentication auth) { public String getPolicy(@PathVariable (value = "rsid") Long rsid, @PathVariable (value = "pid") Long pid, Model m, Authentication auth) {
ResourceSet rs = resourceSetService.getById(rsid); ResourceSet rs = resourceSetService.getById(rsid);
@ -219,7 +250,7 @@ public class PolicyAPI {
* @param auth * @param auth
* @return * @return
*/ */
@RequestMapping(value = "/{rsid}/{pid}", method = RequestMethod.PUT, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE) @RequestMapping(value = "/{rsid}" + POLICYURL + "/{pid}", method = RequestMethod.PUT, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String setClaimsForResourceSet(@PathVariable (value = "rsid") Long rsid, @PathVariable (value = "pid") Long pid, @RequestBody String jsonString, Model m, Authentication auth) { public String setClaimsForResourceSet(@PathVariable (value = "rsid") Long rsid, @PathVariable (value = "pid") Long pid, @RequestBody String jsonString, Model m, Authentication auth) {
ResourceSet rs = resourceSetService.getById(rsid); ResourceSet rs = resourceSetService.getById(rsid);
@ -289,7 +320,7 @@ public class PolicyAPI {
* @param auth * @param auth
* @return * @return
*/ */
@RequestMapping(value = "/{rsid}/{pid}", method = RequestMethod.DELETE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE) @RequestMapping(value = "/{rsid}" + POLICYURL + "/{pid}", method = RequestMethod.DELETE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String deleteResourceSet(@PathVariable ("rsid") Long rsid, @PathVariable (value = "pid") Long pid, Model m, Authentication auth) { public String deleteResourceSet(@PathVariable ("rsid") Long rsid, @PathVariable (value = "pid") Long pid, Model m, Authentication auth) {
ResourceSet rs = resourceSetService.getById(rsid); ResourceSet rs = resourceSetService.getById(rsid);