aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorzsloan2020-05-07 14:36:50 -0500
committerzsloan2020-05-07 14:36:50 -0500
commit67ecc774ac70c5ba528f0ac1536d8d35f7301dac (patch)
tree164138c8afc1ca6a4171d4bba976e27788eb2249 /wqflask
parent8a2f61a999e6dc653a9ca2de802137a1a4107e35 (diff)
downloadgenenetwork2-67ecc774ac70c5ba528f0ac1536d8d35f7301dac.tar.gz
Committing current progress on group manager + a minor fix in dataset.py
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/base/data_set.py2
-rw-r--r--wqflask/utility/redis_tools.py72
-rw-r--r--wqflask/wqflask/templates/admin/group_manager.html134
3 files changed, 159 insertions, 49 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py
index cab708ef..5f08c34c 100644
--- a/wqflask/base/data_set.py
+++ b/wqflask/base/data_set.py
@@ -131,7 +131,7 @@ Publish or ProbeSet. E.g.
ProbeSetFreeze.Name = "{0}"
""".format(name)
- results = g.db.execute(geno_query).fetchall()
+ results = g.db.execute(mrna_expr_query).fetchall()
if len(results):
self.datasets[name] = "ProbeSet"
Redis.set("dataset_structure", json.dumps(self.datasets))
diff --git a/wqflask/utility/redis_tools.py b/wqflask/utility/redis_tools.py
index 573f9945..16bf911a 100644
--- a/wqflask/utility/redis_tools.py
+++ b/wqflask/utility/redis_tools.py
@@ -96,3 +96,75 @@ def get_user_groups(user_id):
continue
return admin_group_ids, user_group_ids
+
+def get_group_info(group_id):
+ group_json = Redis.hget("groups", group_id)
+ group_info = None
+ if group_json:
+ group_info = json.loads(group_json)
+
+ return group_info
+
+def create_group(admin_member_ids, user_member_ids = [], group_name = ""):
+ group_id = str(uuid.uuid4())
+ new_group = {
+ "id" : group_id
+ "admins": admin_member_ids,
+ "users" : user_member_ids,
+ "name" : group_name,
+ "created_timestamp": datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p'),
+ "changed_timestamp": datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p')
+ }
+
+ Redis.hset("groups", group_id, new_group)
+
+ return new_group
+
+def delete_group(user_id, group_id):
+ #ZS: If user is an admin of a group, remove it from the groups hash
+ group_info = get_group_info(group_id)
+ if user_id in group_info["admins"]:
+ Redis.hdel("groups", group_id)
+ return get_user_groups(user_id)
+ else:
+ None
+
+def add_users_to_group(user_id, group_id, user_emails = [], admins = False): #ZS "admins" is just to indicate whether the users should be added to the groups admins or regular users set
+ group_info = get_group_info(group_id)
+ if user_id in group_info["admins"]: #ZS: Just to make sure that the user is an admin for the group, even though they shouldn't be able to reach this point unless they are
+ if admins:
+ group_users = set(group_info["admins"])
+ else:
+ group_users = set(group_info["users"])
+
+ for email in user_emails:
+ user_id = get_user_id("email_address", email)
+ group_users.add(user_id)
+
+ if admins:
+ group_info["admins"] = list(group_users)
+ else:
+ group_info["users"] = list(group_users)
+
+ group_info["changed_timestamp"] = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p')
+ Redis.hset("groups", group_id, json.dumps(group_info))
+ return group_info
+ else:
+ return None
+
+def remove_users_from_group(user_id, users_to_remove_ids, group_id, user_type = "users"): #ZS: User type is because I assume admins can remove other admins
+ group_info = get_group_info(group_id)
+ if user_id in group_info["admins"]:
+ group_users = set(group_info[user_type])
+ group_users -= set(users_to_remove_ids)
+ group_info[user_type] = list(group_users)
+ group_info["changed_timestamp"] = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p')
+ Redis.hset("groups", group_id, json.dumps(group_info))
+
+def change_group_name(user_id, group_id, new_name):
+ group_info = get_group_info(group_id)
+ if user_id in group_info["admins"]:
+ group_info["name"] = new_name
+ return group_info
+ else:
+ return None \ No newline at end of file
diff --git a/wqflask/wqflask/templates/admin/group_manager.html b/wqflask/wqflask/templates/admin/group_manager.html
index ea9026a6..50c2a42c 100644
--- a/wqflask/wqflask/templates/admin/group_manager.html
+++ b/wqflask/wqflask/templates/admin/group_manager.html
@@ -6,40 +6,71 @@
<div class="container">
<div class="page-header">
-
+ <h1>Manage Groups</h1>
</div>
- <form>
- <div class="control-group">
- <b>Group Name: </b>
- <div class="input-append">
- <input type="text" name="group_name">
- <button type="submit" class="btn btn-primary">Save</button>
- </div>
+ <form action="/manage/groups" method="POST">
+ <div class="container" style="margin-bottom: 30px;">
+ <div><h3>Admin Groups</h3></div>
+ <hr>
+ <table id="admin_groups" class="table table-hover">
+ <thead>
+ <tr>
+ <th></th>
+ <th>Index</th>
+ <th>Name</th>
+ <th># Members</th>
+ <th>Created</th>
+ <th>Last Changed</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for group in admin_groups %}
+ <tr>
+ <td><input type="checkbox" name="read" value="{{ group.id }}"></td>
+ <td>{{ loop.index }}</td>
+ <td>{{ group.name }}</td>
+ <td>{{ group.admins|length + group.users|length }}</td>
+ <td>{{ group.created_timestamp }}</td>
+ <td>{{ group.changed_timestamp }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ <hr>
+ <div class="container">
+ <div><h3>User Groups</h3></div>
+ <hr>
+ <table id="user_groups" class="table table-hover">
+ <thead>
+ <tr>
+ <th></th>
+ <th>Index</th>
+ <th>Name</th>
+ <th># Members</th>
+ <th>Created</th>
+ <th>Last Changed</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for group in user_groups %}
+ <tr>
+ <td><input type="checkbox" name="read" value="{{ group.id }}"></td>
+ <td>{{ loop.index }}</td>
+ <td>{{ group.name }}</td>
+ <td>{{ group.admins|length + group.users|length }}</td>
+ <td>{{ group.created_timestamp }}</td>
+ <td>{{ group.changed_timestamp }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
</div>
-
- <table id="dataset_list" class="table table-hover">
- <thead>
- <tr>
- <th>Read</th>
- <th>Type</th>
- <th>ID</th>
- <th>Name</th>
- <th>Full Name</th>
- </tr>
- </thead>
- {% for dataset in datasets %}
- <tr>
- <td><input type="checkbox" name="read" value="{{ dataset.type }}:{{ dataset.name }}"></td>
- <td>{{ dataset.type }}</td>
- <td>{{ dataset.id }}</td>
- <td>{{ dataset.name }}</td>
- <td>{{ dataset.fullname }}</td>
- </tr>
- {% endfor %}
- </table>
</form>
</div>
+
+
<!-- End of body -->
{% endblock %}
@@ -47,33 +78,40 @@
{% block js %}
<script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.dataTables.min.js"></script>
- <script language="javascript" type="text/javascript" src="/static/packages/DT_bootstrap/DT_bootstrap.js"></script>
<script language="javascript" type="text/javascript" src="/static/packages/TableTools/media/js/TableTools.min.js"></script>
<script language="javascript" type="text/javascript" src="/static/packages/underscore/underscore-min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready( function () {
- console.time("Creating table");
- $('#dataset_list').dataTable( {
- "sDom": "Tftipr",
- "oTableTools": {
- "aButtons": [
- "copy",
- "print",
- {
- "sExtends": "collection",
- "sButtonText": 'Save <span class="caret" />',
- "aButtons": [ "csv", "xls", "pdf" ]
- }
- ],
- "sSwfPath": "/static/packages/TableTools/media/swf/copy_csv_xls_pdf.swf"
+ $('#admin_groups, #user_groups').dataTable( {
+ "drawCallback": function( settings ) {
+ $('#admin_groups tr').click(function(event) {
+ if (event.target.type !== 'checkbox') {
+ $(':checkbox', this).trigger('click');
+ }
+ });
},
- "iDisplayLength": 50,
- "bLengthChange": true,
+ "columns": [
+ { "type": "natural" },
+ { "type": "natural" },
+ { "type": "natural" },
+ { "type": "natural" },
+ { "type": "natural" },
+ { "type": "natural" }
+ ],
+ "columnDefs": [ {
+ "targets": 0,
+ "orderable": false
+ } ],
+ "order": [[1, "asc" ]],
+ "sDom": "Ztr",
+ "iDisplayLength": -1,
+ "autoWidth": true,
"bDeferRender": true,
- "bSortClasses": false
+ "bSortClasses": false,
+ "paging": false,
+ "orderClasses": true
} );
- console.timeEnd("Creating table");
});
</script>
{% endblock %}