Skip to content
Snippets Groups Projects
Commit 6f757c67 authored by Andreas Valder's avatar Andreas Valder
Browse files

added acl editor, nearly closed #20. deleting is still bugged

parent 4eb01dda
No related branches found
No related tags found
No related merge requests found
...@@ -105,14 +105,18 @@ CREATE TABLE IF NOT EXISTS `places` ( ...@@ -105,14 +105,18 @@ CREATE TABLE IF NOT EXISTS `places` (
`campus_room` varchar(20) NOT NULL, `campus_room` varchar(20) NOT NULL,
`campus_name` varchar(30) NOT NULL `campus_name` varchar(30) NOT NULL
); );
CREATE TABLE IF NOT EXISTS `auth` ( CREATE TABLE IF NOT EXISTS `auth_data` (
`auth_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `auth_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`deleted` INTEGER NOT NULL DEFAULT '0',
`course_id` INTEGER, `course_id` INTEGER,
`lecture_id` INTEGER, `lecture_id` INTEGER,
`video_id` INTEGER, `video_id` INTEGER,
`auth_type` varchar(10), `auth_type` varchar(10),
`auth_user` varchar(127), `auth_user` varchar(127),
`auth_passwd` varchar(127) `auth_passwd` varchar(127),
`time_created` datetime NOT NULL,
`time_updated` datetime NOT NULL,
`created_by` INTEGER DEFAULT NULL
); );
CREATE TABLE IF NOT EXISTS `site_texts` ( CREATE TABLE IF NOT EXISTS `site_texts` (
`key` varchar(64) NOT NULL PRIMARY KEY, `key` varchar(64) NOT NULL PRIMARY KEY,
...@@ -218,4 +222,5 @@ CREATE TABLE IF NOT EXISTS `sortlog` ( ...@@ -218,4 +222,5 @@ CREATE TABLE IF NOT EXISTS `sortlog` (
CREATE VIEW IF NOT EXISTS `courses` AS select * from `courses_data` where (not(`courses_data`.`deleted`)); CREATE VIEW IF NOT EXISTS `courses` AS select * from `courses_data` where (not(`courses_data`.`deleted`));
CREATE VIEW IF NOT EXISTS `lectures` AS select * from `lectures_data` where (not(`lectures_data`.`deleted`)); CREATE VIEW IF NOT EXISTS `lectures` AS select * from `lectures_data` where (not(`lectures_data`.`deleted`));
CREATE VIEW IF NOT EXISTS `videos` AS select * from `videos_data` where (not(`videos_data`.`deleted`)); CREATE VIEW IF NOT EXISTS `videos` AS select * from `videos_data` where (not(`videos_data`.`deleted`));
CREATE VIEW IF NOT EXISTS `auth` AS select * from `auth_data` where (not(`auth_data`.`deleted`));
COMMIT; COMMIT;
...@@ -70,6 +70,7 @@ def mod_required(func): ...@@ -70,6 +70,7 @@ def mod_required(func):
return decorator return decorator
app.jinja_env.globals['navbar'] = [] app.jinja_env.globals['navbar'] = []
app.jinja_env.globals['acls'] = []
# iconlib can be 'bootstrap' # iconlib can be 'bootstrap'
# ( see: http://getbootstrap.com/components/#glyphicons ) # ( see: http://getbootstrap.com/components/#glyphicons )
# or 'fa' # or 'fa'
...@@ -284,8 +285,8 @@ tabs = { ...@@ -284,8 +285,8 @@ tabs = {
['created_by', 'time_created', 'time_updated']), ['created_by', 'time_created', 'time_updated']),
'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted'], 'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted'],
['created_by', 'time_created', 'time_updated']), ['created_by', 'time_created', 'time_updated']),
'auth': ('auth', 'auth_id', ['auth_type', 'auth_user', 'auth_passwd'], 'auth': ('auth_data', 'auth_id', ['auth_type', 'auth_user', 'auth_passwd', 'deleted'],
['course_id', 'lecture_id', 'video_id']) ['course_id', 'lecture_id', 'video_id', 'created_by', 'time_created', 'time_updated'])
} }
@app.route('/edit', methods=['GET', 'POST']) @app.route('/edit', methods=['GET', 'POST'])
......
...@@ -24,8 +24,76 @@ var moderatorinterface = { ...@@ -24,8 +24,76 @@ var moderatorinterface = {
} }
); );
} }
$('.modeditacl').popover(
{
title: "acls",
html: true,
placement: "left",
trigger: 'click',
container: 'body',
content: function () {
var html = '';
var id = $(this).data('id');
var type = $(this).data('type');
html += '<div width="300px" class="row" data-id="'+id+'" data-type="'+type+'">';
html += '<select onchange="moderatorinterface.selectacl(this)" size="6" class="col-xs-12 acllist">';
var idlist = [];
for (i in moderatorinterface.acls) {
if ((moderatorinterface.acls[i][type+'_id'] == id)) {
var auth = {};
auth.type = moderatorinterface.acls[i]['auth_type'];
auth.user = moderatorinterface.acls[i]['auth_user'];
auth.password = moderatorinterface.acls[i]['auth_passwd'];
auth.id = moderatorinterface.acls[i]['auth_id'];
idlist[idlist.length] = auth.id;
html += '<option data-auth_id="'+auth.id+'">#'+auth.id+' '+auth.type+' '+ ( auth.type == "password" ? ' ("'+auth.user+'":"'+auth.password+'")' : '' ) +'</option>';
}
console.log(moderatorinterface.acls[i]['deleted']);
}
html += '</select>';
html += '<select class="col-xs-12 authtype" onchange="moderatorinterface.acltypechange(this)"><option value="public">public</option><option selected value="password">password</option></select>';
html += '<input class="col-xs-12 passwordinput authuser" type="text" placeholder="username">';
html += '<input class="col-xs-12 passwordinput authpassword" type="text" placeholder="password">';
html += '<button class="col-xs-6" onclick="moderatorinterface.addacl(this)">Add</button>';
//html += '<button class="col-xs-4" onclick="moderatorinterface.delacl(this)">Update</button>';
html += '<button class="col-xs-6" onclick="moderatorinterface.delacl(this)">Delete</button>';
html += '</div>';
return html;
}
}
);
}) })
}, },
selectacl: function (element) {
},
delacl: function (element) {
moderatorinterface.set("auth."+$(".acllist option:selected", element.parentElement).data('auth_id')+".deleted",1,true);
},
addacl: function (element) {
var auth = {};
auth.type = $(".authtype", element.parentElement).val();
if (auth.type == "password") {
auth.user = $(".authuser", element.parentElement).val();
auth.password = $(".authpassword", element.parentElement).val();
}
moderatorinterface.set('')
dict = {}
dict['auth_type'] = auth.type;
dict['auth_user'] = auth.user;
dict['auth_passwd'] = auth.password;
dict[$(element.parentElement).data('type')+'_id'] = $(element.parentElement).data('id');
moderatorinterface.add_new(dict,'auth',true);
var option = $('<option>', {
"text": auth.type+' '+( auth.type == "password" ? ' ("'+auth.user+'":"'+auth.password+'")' : '' ) ,
"data-auth": JSON.stringify(auth)
});
$(".acllist",element.parentElement).append(option);
},
acltypechange: function (element) {
$(".passwordinput",element.parentElement).toggle();
},
edit: function (src) { edit: function (src) {
var path = $($(src)[0]).data('path'); var path = $($(src)[0]).data('path');
var value = $(".editorvalue")[0].value; var value = $(".editorvalue")[0].value;
...@@ -49,12 +117,29 @@ var moderatorinterface = { ...@@ -49,12 +117,29 @@ var moderatorinterface = {
set: function(path,value,reload=false) { set: function(path,value,reload=false) {
var req = {}; var req = {};
req[path] = value; req[path] = value;
moderatorinterface.set_multi(req,reload)
},
set_multi: function(dict,reload=false) {
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: "/edit", url: "/edit",
dataType: "text", dataType: "text",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(req), data: JSON.stringify(dict),
success: function () {
if (reload) {
window.location.reload();
}
}
})
},
add_new: function(dict,table,reload=false) {
$.ajax({
method: "POST",
url: "/new/"+table,
dataType: "text",
contentType: "application/json",
data: JSON.stringify(dict),
success: function () { success: function () {
if (reload) { if (reload) {
window.location.reload(); window.location.reload();
...@@ -73,6 +158,18 @@ var moderatorinterface = { ...@@ -73,6 +158,18 @@ var moderatorinterface = {
url: url, url: url,
dataType: "text", dataType: "text",
}) })
},
acls: [],
setacls: function(value) {
var idlist = [];
for (i in value) {
for (j in value[i]) {
if (idlist.indexOf(value[i][j]['auth_id']) == -1) {
idlist[idlist.length] = value[i][j]['auth_id'];
moderatorinterface.acls[moderatorinterface.acls.length] = value[i][j];
}
}
}
} }
}; };
......
...@@ -139,4 +139,9 @@ ...@@ -139,4 +139,9 @@
</div> </div>
</footer> </footer>
</body> </body>
{% if ismod() %}
<script>
moderatorinterface.setacls({{acls|tojson|safe}})
</script>
{% endif %}
</html> </html>
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<h1 class="panel-title">{{ valueeditor(['courses',course.id,'title'], course.title)}} <h1 class="panel-title">{{ valueeditor(['courses',course.id,'title'], course.title)}}
<ul class="pull-right list-inline"> <ul class="pull-right list-inline">
<li>{{ valuedeletebtn(['courses',course.id,'deleted']) }}</li> <li>{{ valuedeletebtn(['courses',course.id,'deleted']) }}</li>
<li>{{ editacl([]) }}</li> <li>{{ editacl('course',course.id,course.auth) }}</li>
</ul> </ul>
</h1> </h1>
</div> </div>
......
...@@ -152,7 +152,7 @@ $('#embedcodebtn').popover( ...@@ -152,7 +152,7 @@ $('#embedcodebtn').popover(
{{ valuedeletebtn(['lectures',lecture.id,'deleted']) }} {{ valuedeletebtn(['lectures',lecture.id,'deleted']) }}
</li> </li>
<li> <li>
{{ editacl([]) }} {{ editacl('lecture', lecture.id, lecture.auth) }}
</li> </li>
</ul> </ul>
</div> </div>
...@@ -182,16 +182,17 @@ $('#embedcodebtn').popover( ...@@ -182,16 +182,17 @@ $('#embedcodebtn').popover(
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
{% macro editacl(acl) %} {% macro editacl(type,id,acl) %}
{% if not acl %} {{ acls.append(acl) }}
{% if (not acl) %}
{% if ismod() %} {% if ismod() %}
<button class="btn btn-default" onclick=""> <button class="btn btn-default modeditacl" data-type="{{ type }}" data-id="{{ id }}">
<span class="fa fa-unlock" aria-hidden="true" style="color: green;"></span> <span class="fa fa-unlock" aria-hidden="true" style="color: green;"></span>
</button> </button>
{% endif %} {% endif %}
{% else %} {% else %}
{% if ismod() %} {% if ismod() %}
<button class="btn btn-default" onclick=""> <button class="btn btn-default modeditacl" data-type="{{ type }}" data-id="{{ id }}" onclick="">
{% else %} {% else %}
<a> <a>
{% endif %} {% endif %}
...@@ -201,7 +202,6 @@ $('#embedcodebtn').popover( ...@@ -201,7 +202,6 @@ $('#embedcodebtn').popover(
{% else %} {% else %}
</a> </a>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment