forked from shaba/openuds
Finished Groups, and authenticators (hopefully.... :P)
This commit is contained in:
parent
de68a0cada
commit
49dc0eb0c2
@ -135,9 +135,9 @@ class Users(DetailHandler):
|
||||
|
||||
def deleteItem(self, parent, item):
|
||||
try:
|
||||
service = parent.users.get(pk=item)
|
||||
user = parent.users.get(pk=item)
|
||||
|
||||
service.delete()
|
||||
user.delete()
|
||||
except:
|
||||
self.invalidItemException()
|
||||
|
||||
@ -212,10 +212,12 @@ class Groups(DetailHandler):
|
||||
fields = self.readFieldsFromParams(valid_fields)
|
||||
auth = parent.getInstance()
|
||||
if item is None: # Create new
|
||||
auth.createGroup(fields) # this throws an exception if there is an error (for example, this auth can't create users)
|
||||
if not is_meta:
|
||||
auth.createGroup(fields) # this throws an exception if there is an error (for example, this auth can't create users)
|
||||
toSave = {}
|
||||
for k in valid_fields:
|
||||
toSave[k] = fields[k]
|
||||
toSave['is_meta'] = is_meta
|
||||
group = parent.groups.create(**toSave)
|
||||
else:
|
||||
if not is_meta:
|
||||
@ -242,3 +244,13 @@ class Groups(DetailHandler):
|
||||
self.invalidRequestException()
|
||||
|
||||
return self.getItems(parent, group.id)
|
||||
|
||||
def deleteItem(self, parent, item):
|
||||
try:
|
||||
group = parent.groups.get(pk=item)
|
||||
|
||||
group.delete()
|
||||
except:
|
||||
self.invalidItemException()
|
||||
|
||||
return 'deleted'
|
||||
|
@ -48,8 +48,9 @@ gui.authenticators.link = function(event) {
|
||||
|
||||
|
||||
// Search button event generator for user/group
|
||||
var searchForm = function(parentModalId, type, id, title, searchLabel, resultsLabel, srcSelector) {
|
||||
var searchForm = function(parentModalId, type, id, title, searchLabel, resultsLabel) {
|
||||
var errorModal = gui.failRequestModalFnc(gettext('Search error'));
|
||||
var srcSelector = parentModalId + ' input[name="name"]';
|
||||
|
||||
$(parentModalId + ' .button-search').on('click', function() {
|
||||
api.templates.get('search', function(tmpl) { // Get form template
|
||||
@ -134,6 +135,8 @@ gui.authenticators.link = function(event) {
|
||||
|
||||
var user = new GuiElement(api.authenticators.detail(id, 'users'), 'users');
|
||||
var group = new GuiElement(api.authenticators.detail(id, 'groups'), 'groups');
|
||||
|
||||
|
||||
var grpTable = group.table({
|
||||
container : 'groups-placeholder',
|
||||
rowSelect : 'single',
|
||||
@ -142,8 +145,8 @@ gui.authenticators.link = function(event) {
|
||||
gui.tools.unblockUI();
|
||||
},
|
||||
onEdit: function(value, event, table, refreshFnc) {
|
||||
gui.tools.blockUI();
|
||||
var exec = function(groups_all) {
|
||||
gui.tools.blockUI();
|
||||
api.templates.get('group', function(tmpl) { // Get form template
|
||||
group.rest.item(value.id, function(item){ // Get item to edit
|
||||
// Creates modal
|
||||
@ -185,10 +188,48 @@ gui.authenticators.link = function(event) {
|
||||
}
|
||||
|
||||
},
|
||||
onNew : function(type, table, refreshFnc) {
|
||||
alert(type);
|
||||
refreshFnc();
|
||||
}
|
||||
onNew : function(t, table, refreshFnc) {
|
||||
var exec = function(groups_all) {
|
||||
gui.tools.blockUI();
|
||||
api.templates.get('group', function(tmpl) { // Get form template
|
||||
// Creates modal
|
||||
var modalId = gui.launchModal(gettext('New group'), api.templates.evaluate(tmpl, {
|
||||
type: t,
|
||||
groupname_label: type.groupNameLabel,
|
||||
external: type.isExternal,
|
||||
canSearchGroups: type.canSearchGroups,
|
||||
groups: [],
|
||||
groups_all: groups_all
|
||||
}));
|
||||
gui.tools.unblockUI();
|
||||
|
||||
gui.tools.applyCustoms(modalId);
|
||||
|
||||
searchForm(modalId, 'group', id, gettext('Search groups'), gettext('Group'), gettext('Groups found')); // Enable search button click, if it exist ofc
|
||||
|
||||
$(modalId + ' .button-accept').click(function(){
|
||||
var fields = gui.forms.read(modalId);
|
||||
gui.doLog('Fields', fields);
|
||||
group.rest.create(fields, function(data) { // Success on put
|
||||
$(modalId).modal('hide');
|
||||
refreshFnc();
|
||||
gui.notify(gettext('Group saved'), 'success');
|
||||
}, gui.failRequestModalFnc("Error saving group", true));
|
||||
});
|
||||
});
|
||||
};
|
||||
if( t == 'meta' ) {
|
||||
// Meta will get all groups
|
||||
group.rest.overview(function(groups) {
|
||||
exec(groups);
|
||||
});
|
||||
} else {
|
||||
exec();
|
||||
}
|
||||
|
||||
},
|
||||
onDelete: gui.methods.del(group, gettext('Delete group'), gettext('Error deleting group')),
|
||||
|
||||
});
|
||||
var tmpLogTable;
|
||||
|
||||
@ -294,7 +335,7 @@ gui.authenticators.link = function(event) {
|
||||
|
||||
gui.tools.unblockUI();
|
||||
|
||||
searchForm(modalId, 'user', id, gettext('Search users'), gettext('User'), gettext('Users found'), modalId + ' input[name="name"]'); // Enable search button click, if it exist ofc
|
||||
searchForm(modalId, 'user', id, gettext('Search users'), gettext('User'), gettext('Users found')); // Enable search button click, if it exist ofc
|
||||
|
||||
$(modalId + ' .button-accept').click(function(){
|
||||
var fields = gui.forms.read(modalId);
|
||||
|
@ -7,16 +7,19 @@
|
||||
<div class="form-group">
|
||||
<label for="id_username" class="col-sm-2 control-label">{{ groupname_label }}</label>
|
||||
<div class="col-sm-10">
|
||||
{{# ifequals type 'group' }}
|
||||
{{# if canSearchGroups }}
|
||||
{{# if groupname }}
|
||||
{{# if id }}
|
||||
{{ else }}
|
||||
<div class="input-group">
|
||||
{{/ if }}
|
||||
{{/ if }}
|
||||
{{/ ifequals }}
|
||||
<input name="name" value="{{ groupname }}" type="text" id="id_username" class="form-control modal_field_data"
|
||||
placeholder="{% endverbatim %}{% trans 'Group name' %}{% verbatim %}"{{# if groupname }}readonly{{/ if }}>
|
||||
{{# ifequals type 'group' }}
|
||||
{{# if canSearchGroups }}
|
||||
{{# if groupname }}
|
||||
{{# if id }}
|
||||
{{ else }}
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-info button-search" type="button"><i class="fa fa-search"></i> {% endverbatim %}{% trans 'Search' %}{% verbatim %}</button>
|
||||
@ -24,6 +27,7 @@
|
||||
</div>
|
||||
{{/ if }}
|
||||
{{/ if }}
|
||||
{{/ ifequals }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@ -44,7 +48,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{# if groups }}
|
||||
{{# if groups_all }}
|
||||
<div class="form-group">
|
||||
<label for="id_state" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Groups' %}{% verbatim %}</label>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<label for="id_username" class="col-sm-2 control-label">{{ username_label }}</label>
|
||||
<div class="col-sm-10">
|
||||
{{# if canSearchUsers }}
|
||||
{{# if username }}
|
||||
{{# if id }}
|
||||
{{ else }}
|
||||
<div class="input-group">
|
||||
{{/ if }}
|
||||
@ -15,7 +15,7 @@
|
||||
<input name="name" value="{{ username }}" type="text" id="id_username" class="form-control modal_field_data"
|
||||
placeholder="{% endverbatim %}{% trans 'Username' %}{% verbatim %}"{{# if username }}readonly{{/ if }}>
|
||||
{{# if canSearchUsers }}
|
||||
{{# if username }}
|
||||
{{# if id }}
|
||||
{{ else }}
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-info button-search" type="button"><i class="fa fa-search"></i> {% endverbatim %}{% trans 'Search' %}{% verbatim %}</button>
|
||||
@ -79,7 +79,8 @@
|
||||
</div>
|
||||
</div>
|
||||
{{/ if }}
|
||||
|
||||
|
||||
{{# if id }}
|
||||
<div class="form-group">
|
||||
<label for="id_password" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Groups' %}{% verbatim %}</label>
|
||||
<div class="col-sm-10">
|
||||
@ -91,5 +92,21 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{{ else }}
|
||||
{{# if external }}
|
||||
{{ else }}
|
||||
<div class="form-group">
|
||||
<label for="id_password" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Groups' %}{% verbatim %}</label>
|
||||
<div class="col-sm-10">
|
||||
<select class="selectpicker show-menu-arrow modal_field_data" multiple data-style="btn-default" countSelectedText="{% endverbatim %}{% trans '{0} of {1} selected' %}{% verbatim %}"
|
||||
data-selected-text-format="count>3" data-width="100%" name="groups" id="id_groups">
|
||||
{{#each groups_all }}
|
||||
<option value="{{ id }}"{{# ifbelongs id ../groups }}selected{{/ ifbelongs }}>{{ name }}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{{/ if }}
|
||||
{{/ if }}
|
||||
</form>
|
||||
{% endverbatim %}
|
Loading…
Reference in New Issue
Block a user