Commit 507fb116 authored by Rachana's avatar Rachana Committed by GitHub

Merge pull request #1606 from kedar2a/master

updated PR#1595 - group create, delete with restore feature
parents 37c5e080 a1d16b6a
...@@ -4,20 +4,22 @@ ...@@ -4,20 +4,22 @@
{% block error_body_text %} {% block error_body_text %}
<br/> <br/>
<h2>Sorry, the group you are trying to access is Private!</h2> <!-- <h2>Sorry, the group you are trying to access is Private!</h2> -->
<h2>Permission Denied!</h2>
<br/> <br/>
<h4> <h4>
<small> <small>
{% if site.SITE_NAME == "NROER" %} {% if site.SITE_NAME == "NROER" %}
Double check the URL or navigate back to: Please check the URL or navigate back to:
<blockquote> <blockquote>
<a href="{% url 'repository' 'home' %}"> Repository </a> | <a href="{% url 'repository' 'home' %}"> Repository </a> |
<a href="{% url 'nroer_groups' 'home' 'Partners' %}"> Partners </a> | <a href="{% url 'nroer_groups' 'home' 'Partners' %}"> Partners </a> |
<a href="{% url 'nroer_groups' 'home' 'Groups' %}"> Groups </a> <a href="{% url 'nroer_groups' 'home' 'Groups' %}"> Groups </a>
</blockquote> </blockquote>
{% else %} {% else %}
Double check the URL or head to the &nbsp; <a href="/home/"> <i class="fi-home"> </i> homepage</a>. You do not have permission to retrieve the URL or link you requested.<br/>
Please check the URL or head to the
<a href="/home/"> <i class="fi-home"> </i> homepage</a>.
{% endif %} {% endif %}
</small> </small>
</h4> </h4>
......
...@@ -331,13 +331,22 @@ ...@@ -331,13 +331,22 @@
{% if is_gstaff %} {% if is_gstaff %}
<!-- Prevent creating New group from context of top mod group --> <!-- Prevent creating New group from context of top mod group -->
{% if group_object.edit_policy != "EDITABLE_MODERATED" and is_gstaff %} {% if group_object.edit_policy != "EDITABLE_MODERATED" and is_gstaff %}
<a href="{% url create_url group_object.name %}" class="tiny button radius expand mod-btn" title="{% trans 'Create New' %}"> <a href="{% url create_url group_object.name %}" class="tiny button radius left-btn" title="{% trans 'Create New' %}">
{% if group_object.agency_type == 'Partner' %} {% if group_object.agency_type == 'Partner' %}
{% trans 'New Partner' %} {% trans 'New Partner' %}
{% else %} {% else %}
{% trans 'New Group' %} {% trans 'New Group' %}
{% endif %} {% endif %}
</a> </a>
{% if node %}
<a class="tiny button radius delete-btn grp_delete right-btn" title="{% trans 'Delete' %}">
{% if group_object.agency_type == 'Partner' %}
{% trans 'Delete Partner' %}
{% else %}
{% trans 'Delete Group' %}
{% endif %}
</a>
{% endif %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% else %} {% else %}
...@@ -532,9 +541,13 @@ ...@@ -532,9 +541,13 @@
} }
}); });
// alert("term_delete") {% elif "Group" in node.member_of_names_list %}
$(".grp_delete").attr('href', "{% url 'delete_group' group_object.pk %}")
$(".grp_delete")[0].click()
{% endif %} {% endif %}
}); });
$(document).on("click", "#btnConfirmNo", function() { $(document).on("click", "#btnConfirmNo", function() {
......
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
urlpatterns = patterns('gnowsys_ndf.ndf.views.trash', urlpatterns = patterns('gnowsys_ndf.ndf.views.trash',
url(r'^/delete/(?P<node_id>[\w-]+)$', 'trash_resource',name='trash_resource'), url(r'^/delete/(?P<node_id>[\w-]+)$', 'trash_resource',name='trash_resource'),
url(r'^/delete_group$', 'delete_group',name='delete_group'),
url(r'^/delete$', 'delete_resource',name='delete_resource'), url(r'^/delete$', 'delete_resource',name='delete_resource'),
url(r'^/restore$', 'restore_resource',name='restore_resource'), url(r'^/restore$', 'restore_resource',name='restore_resource'),
url(r'^/delete_multiple_resources', 'delete_multiple_resources', name='delete_multiple_resources'), url(r'^/delete_multiple_resources', 'delete_multiple_resources', name='delete_multiple_resources'),
......
...@@ -47,6 +47,7 @@ pandora_video_st = node_collection.one({'$and': [{'_type': 'GSystemType'}, {'nam ...@@ -47,6 +47,7 @@ pandora_video_st = node_collection.one({'$and': [{'_type': 'GSystemType'}, {'nam
file_id = node_collection.find_one({'_type': "GSystemType", "name": "File"}, {"_id": 1}) file_id = node_collection.find_one({'_type': "GSystemType", "name": "File"}, {"_id": 1})
page_id = node_collection.find_one({'_type': "GSystemType", "name": "Page"}, {"_id": 1}) page_id = node_collection.find_one({'_type': "GSystemType", "name": "Page"}, {"_id": 1})
theme_gst_id = node_collection.find_one({'_type': "GSystemType", "name": "Theme"}, {"_id": 1}) theme_gst_id = node_collection.find_one({'_type': "GSystemType", "name": "Theme"}, {"_id": 1})
group_gst_id = node_collection.find_one({'_type': "GSystemType", "name": "Group"}, {"_id": 1})
# data review in File app # data review in File app
...@@ -72,7 +73,8 @@ def data_review(request, group_id, page_no=1, **kwargs): ...@@ -72,7 +73,8 @@ def data_review(request, group_id, page_no=1, **kwargs):
'member_of': {'$in': [ 'member_of': {'$in': [
ObjectId(file_id._id), ObjectId(file_id._id),
ObjectId(page_id._id), ObjectId(page_id._id),
ObjectId(theme_gst_id._id) ObjectId(theme_gst_id._id),
ObjectId(group_gst_id._id)
]}, ]},
# '_type': 'File', 'fs_file_ids': {'$ne': []}, # '_type': 'File', 'fs_file_ids': {'$ne': []},
'group_set': {'$in': [ObjectId(group_id)]}, 'group_set': {'$in': [ObjectId(group_id)]},
......
...@@ -451,4 +451,6 @@ def edit_comment(request, group_id, node_id=None,call_from_discussion=None): ...@@ -451,4 +451,6 @@ def edit_comment(request, group_id, node_id=None,call_from_discussion=None):
@get_execution_time @get_execution_time
def get_thread_comments_count(request, group_id, thread_node_id): def get_thread_comments_count(request, group_id, thread_node_id):
return HttpResponse(node_collection.find({'member_of': reply_st._id, 'origin.thread_id':ObjectId(thread_node_id)}).count()) return HttpResponse(node_collection.find({'group_set': group_id,
'member_of': reply_st._id,
'origin.thread_id':ObjectId(thread_node_id)}).count())
...@@ -83,9 +83,11 @@ def explore_groups(request,page_no=1): ...@@ -83,9 +83,11 @@ def explore_groups(request,page_no=1):
title = 'groups' title = 'groups'
gstaff_access = check_is_gstaff(group_id,request.user) gstaff_access = check_is_gstaff(group_id,request.user)
if gstaff_access: if gstaff_access:
group_cur = node_collection.find({'_type': 'Group', 'member_of': gst_group._id}).sort('last_update', -1) group_cur = node_collection.find({'_type': 'Group',
'member_of': gst_group._id, 'status': u'PUBLISHED'}).sort('last_update', -1)
else: else:
group_cur = node_collection.find({'_type': 'Group', 'member_of': gst_group._id,'name':{'$nin':GSTUDIO_DEFAULT_GROUPS }}).sort('last_update', -1) group_cur = node_collection.find({'_type': 'Group', 'member_of': gst_group._id,
'status': u'PUBLISHED', 'name':{'$nin':GSTUDIO_DEFAULT_GROUPS }}).sort('last_update', -1)
ce_page_cur = paginator.Paginator(group_cur, page_no, GSTUDIO_NO_OF_OBJS_PP) ce_page_cur = paginator.Paginator(group_cur, page_no, GSTUDIO_NO_OF_OBJS_PP)
context_variable = {'title': title, 'doc_cur': group_cur, 'card': 'ndf/simple_card.html', context_variable = {'title': title, 'doc_cur': group_cur, 'card': 'ndf/simple_card.html',
......
...@@ -1310,7 +1310,9 @@ class GroupCreateEditHandler(View): ...@@ -1310,7 +1310,9 @@ class GroupCreateEditHandler(View):
-- CourseEvent Group -- CourseEvent Group
-- ProgramEvent Group -- ProgramEvent Group
""" """
@method_decorator(login_required) @method_decorator(login_required)
@method_decorator(staff_required)
@method_decorator(get_execution_time) @method_decorator(get_execution_time)
def get(self, request, group_id, action): def get(self, request, group_id, action):
""" """
...@@ -1396,6 +1398,7 @@ class GroupCreateEditHandler(View): ...@@ -1396,6 +1398,7 @@ class GroupCreateEditHandler(View):
# --- END of get() --- # --- END of get() ---
@method_decorator(login_required) @method_decorator(login_required)
@method_decorator(staff_required)
@method_decorator(get_execution_time) @method_decorator(get_execution_time)
def post(self, request, group_id, action): def post(self, request, group_id, action):
''' '''
...@@ -1492,6 +1495,7 @@ class EventGroupCreateEditHandler(View): ...@@ -1492,6 +1495,7 @@ class EventGroupCreateEditHandler(View):
- ProgramEvent Group - ProgramEvent Group
""" """
@method_decorator(login_required) @method_decorator(login_required)
@method_decorator(staff_required)
@method_decorator(get_execution_time) @method_decorator(get_execution_time)
def get(self, request, group_id, action, sg_type): def get(self, request, group_id, action, sg_type):
""" """
...@@ -1555,6 +1559,7 @@ class EventGroupCreateEditHandler(View): ...@@ -1555,6 +1559,7 @@ class EventGroupCreateEditHandler(View):
# --- END of get() --- # --- END of get() ---
@method_decorator(login_required) @method_decorator(login_required)
@method_decorator(staff_required)
@method_decorator(get_execution_time) @method_decorator(get_execution_time)
def post(self, request, group_id, action, sg_type): def post(self, request, group_id, action, sg_type):
''' '''
......
...@@ -38,6 +38,7 @@ from django.template.loader import render_to_string ...@@ -38,6 +38,7 @@ from django.template.loader import render_to_string
# to display error template if non existent pub is given in settings.py # to display error template if non existent pub is given in settings.py
from django.shortcuts import render from django.shortcuts import render
from django.core.handlers.wsgi import WSGIRequest from django.core.handlers.wsgi import WSGIRequest
from django.core.exceptions import PermissionDenied
''' -- imports from application folders/files -- ''' ''' -- imports from application folders/files -- '''
from gnowsys_ndf.settings import META_TYPE, GSTUDIO_NROER_GAPPS from gnowsys_ndf.settings import META_TYPE, GSTUDIO_NROER_GAPPS
...@@ -62,10 +63,24 @@ topic_GST = node_collection.one({'_type': 'GSystemType', 'name': 'Topic'}) ...@@ -62,10 +63,24 @@ topic_GST = node_collection.one({'_type': 'GSystemType', 'name': 'Topic'})
grp_st = node_collection.one({'$and': [{'_type': 'GSystemType'}, {'name': 'Group'}]}) grp_st = node_collection.one({'$and': [{'_type': 'GSystemType'}, {'name': 'Group'}]})
ins_objectid = ObjectId() ins_objectid = ObjectId()
# C O M M O N M E T H O D S D E F I N E D F O R V I E W S # C O M M O N M E T H O D S D E F I N E D F O R V I E W S
def get_execution_time(f): def staff_required(func):
"""
Decorator for CRUD views of Group and Event to check whether a user
is allowed and is active.
Currently, ONLY SuperUsers will be allowed.
"""
def wrapper(*args, **kwargs):
for arg in args:
if arg.user.is_superuser and arg.user.is_active:
return func(*args, **kwargs)
raise PermissionDenied
return wrapper
def get_execution_time(f):
def wrap(*args,**kwargs): def wrap(*args,**kwargs):
time1 = time.time() time1 = time.time()
......
...@@ -9,6 +9,8 @@ from gnowsys_ndf.ndf.views.methods import * ...@@ -9,6 +9,8 @@ from gnowsys_ndf.ndf.views.methods import *
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from gnowsys_ndf.settings import GSTUDIO_SITE_NAME from gnowsys_ndf.settings import GSTUDIO_SITE_NAME
trash_group = node_collection.one({'_type': 'Group', "name": u"Trash"});
@get_execution_time @get_execution_time
def trash_resource(request,group_id,node_id): def trash_resource(request,group_id,node_id):
''' '''
...@@ -65,6 +67,19 @@ def trash_resource(request,group_id,node_id): ...@@ -65,6 +67,19 @@ def trash_resource(request,group_id,node_id):
return HttpResponseRedirect(reverse('group_dashboard', kwargs={'group_id': group_id})) return HttpResponseRedirect(reverse('group_dashboard', kwargs={'group_id': group_id}))
# return(eval('group_dashboard')(request, group_id)) # return(eval('group_dashboard')(request, group_id))
@get_execution_time
# @staff_required
def delete_group(request,group_id):
response_dict = {'success': False}
group_obj = get_group_name_id(group_id, get_obj=True)
del_s,del_msg = delete_node(group_obj._id, deletion_type=0)
if trash_group._id not in group_obj.group_set:
group_obj.group_set.append(trash_group._id)
group_obj.save(groupid=group_obj._id)
if del_s:
return HttpResponseRedirect(reverse('groupchange', kwargs={'group_id': 'home'}))
@get_execution_time @get_execution_time
def delete_resource(request,group_id): def delete_resource(request,group_id):
# NOTE: purge of themes need to be handled differently. # NOTE: purge of themes need to be handled differently.
...@@ -92,6 +107,7 @@ def restore_resource(request, group_id): ...@@ -92,6 +107,7 @@ def restore_resource(request, group_id):
if node_to_be_restore.snapshot.keys(): if node_to_be_restore.snapshot.keys():
node_to_be_restore.group_set = [ObjectId(i) for i in node_to_be_restore.snapshot.keys()] node_to_be_restore.group_set = [ObjectId(i) for i in node_to_be_restore.snapshot.keys()]
node_to_be_restore.status = u'PUBLISHED'
node_to_be_restore.save(group_id) node_to_be_restore.save(group_id)
# print "--- ", node_to_be_restore.group_set # print "--- ", node_to_be_restore.group_set
response_dict['success'] = True response_dict['success'] = True
...@@ -125,4 +141,4 @@ def delete_multiple_resources(request,group_id): ...@@ -125,4 +141,4 @@ def delete_multiple_resources(request,group_id):
node_obj.status = u"DELETED" node_obj.status = u"DELETED"
node_obj.save() node_obj.save()
return HttpResponse(json.dumps(files_list)) return HttpResponse(json.dumps(files_list))
\ No newline at end of file
...@@ -715,7 +715,7 @@ def my_groups(request, group_id,page_no=1): ...@@ -715,7 +715,7 @@ def my_groups(request, group_id,page_no=1):
exclued_from_public = ObjectId(task_gst._id) exclued_from_public = ObjectId(task_gst._id)
group_cur = node_collection.find( group_cur = node_collection.find(
{'_type': "Group", 'name': {'$nin': ["home", auth.name]},"access_policy":{"$in":Access_policy}, {'_type': "Group", 'name': {'$nin': ["home", auth.name]},"access_policy":{"$in":Access_policy}, 'status': u'PUBLISHED',
'$or': [{'group_admin': int(usrid)}, {'author_set': int(usrid)}]}).sort('last_update', -1) '$or': [{'group_admin': int(usrid)}, {'author_set': int(usrid)}]}).sort('last_update', -1)
group_page_cur = paginator.Paginator(group_cur, page_no, GSTUDIO_NO_OF_OBJS_PP) group_page_cur = paginator.Paginator(group_cur, page_no, GSTUDIO_NO_OF_OBJS_PP)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment