Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objects movements #40

Merged
merged 46 commits into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0690cd9
Merge branch 'concurrency-problem' into development
iPablo Nov 16, 2015
a404772
Added movements tests, incompletes
iPablo Nov 16, 2015
e778504
Uncomment text
iPablo Nov 16, 2015
b9d5e54
Printers movements backend
iPablo Nov 17, 2015
93657e2
Fixed movement test: 1, 2, 3
iPablo Nov 18, 2015
0faadab
Now, emitters objects can be moved (Backend)
iPablo Nov 18, 2015
b987aa5
Improved code and fixed some details
iPablo Nov 18, 2015
2c1494d
Now, we can move groups (backend)
iPablo Nov 19, 2015
1b97b11
Now, movements test 4 and 5 works correctly
iPablo Nov 19, 2015
95dc115
Now we can move OUs (backend)
iPablo Nov 20, 2015
62c15cb
Added new movements test
iPablo Nov 20, 2015
bbf1e98
Fixed little code error
iPablo Nov 20, 2015
929b384
Improved code
iPablo Nov 23, 2015
77e8bd0
Fixed error
iPablo Nov 23, 2015
e64c35d
Improved tests
iPablo Nov 23, 2015
75d4443
cut and paste repo,group,print and ou
rastydnb Nov 30, 2015
faf2b46
Merge branch 'objects-movements' of github.com:Emergya/gecoscc-ui int…
rastydnb Nov 30, 2015
3b1fc51
add maintenance modal question
rastydnb Dec 1, 2015
a1b8ce7
check user admin for crop and paste
rastydnb Dec 2, 2015
2e24cea
Added function that help us to know if a related object is assigned i…
iPablo Dec 2, 2015
6f32370
Code improved
iPablo Dec 2, 2015
e982235
Code refactored
iPablo Dec 2, 2015
0d26788
Details fixed for PEP-8
iPablo Dec 2, 2015
7e9f9f6
refactor object movement
rastydnb Dec 3, 2015
ca3d724
Code fixed
iPablo Dec 4, 2015
0a17604
fix
rastydnb Dec 4, 2015
31a5da3
fix
rastydnb Dec 6, 2015
f866691
Added translations
iPablo Dec 11, 2015
c50ceaf
change maintenance modal
rastydnb Dec 11, 2015
fa99e71
Merge branch 'objects-movements' of github.com:Emergya/gecoscc-ui int…
rastydnb Dec 11, 2015
2f6265e
Fixed some details
iPablo Dec 11, 2015
f05ef97
add mesage for non admin user
rastydnb Dec 11, 2015
00dd473
Merge branch 'objects-movements' of github.com:Emergya/gecoscc-ui int…
rastydnb Dec 11, 2015
f57e719
fixed details
iPablo Dec 11, 2015
50acdf0
fix
rastydnb Dec 11, 2015
71643b1
Fixed error moving nodes
iPablo Dec 11, 2015
6c22cf0
Merge branch 'objects-movements' of https://github.com/Emergya/gecosc…
iPablo Dec 11, 2015
4953b02
fix
rastydnb Dec 12, 2015
52ac6fe
Merge branch 'objects-movements' of github.com:Emergya/gecoscc-ui int…
rastydnb Dec 12, 2015
61b4afb
fix preventDefault
rastydnb Dec 13, 2015
152203f
add preventDefault on maintenance modal
rastydnb Dec 13, 2015
dd1113b
Fixed error moving emitter objects
iPablo Dec 13, 2015
f7d1ce8
Added translations
iPablo Dec 13, 2015
7caaecb
Fixed detail
iPablo Dec 13, 2015
c7741ec
Merge branch 'development' of github.com:gecos-team/gecoscc-ui into d…
iPablo Dec 14, 2015
7293093
Merge branch 'development' into objects-movements
iPablo Dec 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 67 additions & 24 deletions gecoscc/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
from gecoscc.tasks import object_created, object_changed, object_deleted, object_moved
from gecoscc.utils import (get_computer_of_user, get_filter_nodes_parents_ou,
oids_filter, check_unique_node_name_by_type_at_domain,
visibility_object_related, visibility_group)

visibility_object_related, visibility_group,
RESOURCES_EMITTERS_TYPES, get_object_related_list)
from gecoscc.i18n import gettext as _

import logging
logger = logging.getLogger(__name__)

SAFE_METHODS = ('GET', 'OPTIONS', 'HEAD',)
UNSAFE_METHODS = ('POST', 'PUT', 'PATCH', 'DELETE', )
SCHEMA_METHODS = ('POST', 'PUT', )
Expand Down Expand Up @@ -179,8 +179,15 @@ def get(self):
node = self.collection.find_one(collection_filter)
if not node:
raise HTTPNotFound()
node = self.parse_item(node)
if node.get('type', None) in RESOURCES_EMITTERS_TYPES:
node['is_assigned'] = self.is_assigned(node)
return node
return node

return self.parse_item(node)
def is_assigned(self, related_object):
node_with_related_object = get_object_related_list(self.request.db, related_object)
return bool(node_with_related_object.count())


class ResourcePaginated(ResourcePaginatedReadOnly):
Expand All @@ -202,17 +209,17 @@ def integrity_validation(self, obj, real_obj=None):
def pre_save(self, obj, old_obj=None):
if old_obj and 'name' in old_obj:
obj['name'] = old_obj['name']

# Check he policies "object_related_list" attribute
if 'policies' in obj:
policies = obj['policies']
for policy in policies:
# Get the policy
policyobj = self.request.db.policies.find_one({"_id": ObjectId(str(policy))})
if policyobj is None:
logger.warning("Unknown policy: %s"%(str(policy)))
logger.warning("Unknown policy: %s" % (str(policy)))
else:
# Get the related object collection
# Get the related object collection
ro_collection = None
if policyobj['slug'] == 'printer_can_view':
ro_collection = self.request.db.nodes
Expand All @@ -225,22 +232,21 @@ def pre_save(self, obj, old_obj=None):
elif policyobj['slug'] == 'package_profile_res':
ro_collection = self.request.db.software_profiles
else:
logger.warning("Unrecognized slug: %s"%(str(policyobj['slug'])))
logger.warning("Unrecognized slug: %s" % (str(policyobj['slug'])))

# Check the related objects
if ro_collection is not None:
ro_list = policies[str(policy)]['object_related_list']
for ro_id in ro_list:
ro_obj = ro_collection.find_one({"_id": ObjectId(str(ro_id))})
if ro_obj is None:
logger.error("Can't find related object: %s:%s"%(str(policyobj['slug']), str(ro_id)))
self.request.errors.add('body', 'object', "Can't find related object: %s:%s"%(str(policyobj['slug']), str(ro_id)))
logger.error("Can't find related object: %s:%s" % (str(policyobj['slug']), str(ro_id)))
self.request.errors.add('body', 'object', "Can't find related object: %s:%s" % (str(policyobj['slug']), str(ro_id)))
return None



else:
logger.debug("No policies in this object")

return obj

def post_save(self, obj, old_obj=None):
Expand Down Expand Up @@ -386,9 +392,8 @@ class TreeResourcePaginated(ResourcePaginated):
def check_unique_node_name_by_type_at_domain(self, obj):
unique = check_unique_node_name_by_type_at_domain(self.request.db.nodes, obj)
if not unique:
self.request.errors.add(
'body', 'name',
"Name must be unique in domain.")
self.request.errors.add('body', 'name',
"Name must be unique in domain.")
return unique

def integrity_validation(self, obj, real_obj=None):
Expand Down Expand Up @@ -446,24 +451,28 @@ def check_memberof_integrity(self, obj):
return False
return True

def check_policies_integrity(self, obj):
def check_policies_integrity(self, obj, is_moved=False):
"""
Check if the policie is out of scope
"""
obj_original = deepcopy(obj)
visibility_object_related(self.request.db, obj)
if obj != obj_original:
self.request.errors.add(unicode(obj[self.key]), 'policies',
"The related object is out of scope")
return False
if not is_moved:
if obj != obj_original:
self.request.errors.add(unicode(obj[self.key]), 'policies',
"The related object is out of scope")
return False
return True

def integrity_validation(self, obj, real_obj=None):
result = super(TreeLeafResourcePaginated, self).integrity_validation(
obj, real_obj)
result = result and self.check_memberof_integrity(obj)
result = result and self.check_policies_integrity(obj)
result = result and self.check_unique_node_name_by_type_at_domain(obj)
if real_obj is not None and real_obj['path'] == obj['path']:
result = result and self.check_policies_integrity(obj)
else:
result = result and self.check_policies_integrity(obj, is_moved=True)
return result

def computers_to_group(self, obj):
Expand Down Expand Up @@ -527,3 +536,37 @@ def get_objects_filter(self):
filters.append({'path': get_filter_nodes_parents_ou(self.request.db,
ou_id, item_id)})
return filters

def check_obj_is_related(self, obj):
'''
Check if the emitter object is related with any object
'''
if obj.get('_id'):
if obj['type'] == 'printer':
slug = 'printer_can_view'
elif obj['type'] == 'repository':
slug = 'repository_can_view'
elif obj['type'] == 'storage':
slug = 'storage_can_view'
elif obj['type'] == 'group':
members_group = obj['members']
if not members_group:
return True
return False

policy_id = self.request.db.policies.find_one({'slug': slug}).get('_id')
nodes_related_with_obj = self.request.db.nodes.find({"policies.%s.object_related_list"
% unicode(policy_id): {'$in': [unicode(obj['_id'])]}})

if nodes_related_with_obj.count() == 0:
return True

return False
return True

def integrity_validation(self, obj, real_obj=None):
result = super(PassiveResourcePaginated, self).integrity_validation(
obj, real_obj)
result = result and (self.request.user.get('is_superuser', False) or self.check_obj_is_related(obj))

return result
24 changes: 15 additions & 9 deletions gecoscc/api/organisationalunits.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,23 @@ class OrganisationalUnitResource(TreeResourcePaginated):
def integrity_validation(self, obj, real_obj=None):
status = super(OrganisationalUnitResource,
self).integrity_validation(obj, real_obj)
if (real_obj is not None and obj['path'] != real_obj['path']):
# Check if the ou is moving to self depth, that is not correct.
if obj['path'] in real_obj['path']:
self.request.errors.add(
obj[self.key], 'path',
"the ou is moving to self depth position, "
"that is not allowed")
return False
status = status and self.check_unique_node_name_by_type_at_domain(obj)

if real_obj is not None and obj['path'] != real_obj['path']:
status_user = self.request.user.get('is_superuser', False) or self.is_ou_empty(obj)
status = status and status_user
return status

def is_ou_empty(self, obj):
'''
Check if the Ou contains any object
'''
ou_children = self.collection.find({'path': {'$regex': '.*' + unicode(obj['_id']) + '.*'}}).count()

if ou_children == 0:
return True
else:
return False

def post_save(self, obj, old_obj=None):
""" Check if path has changed to refresh children nodes """
if (self.request.method == 'PUT' and old_obj and
Expand Down
2 changes: 1 addition & 1 deletion gecoscc/api/printer_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_distinct_filter(self, objects):
if self.request.GET.get('manufacturers_list'):
objects = objects.distinct('manufacturer')
objects.sort()
objects = [{'manufacturer':m, 'model':''} for m in objects]
objects = [{'manufacturer': m, 'model': ''} for m in objects]
return objects

def set_name_filter(self, query, key_name='manufacturer'):
Expand Down
Binary file modified gecoscc/locale/en/LC_MESSAGES/gecoscc.mo
Binary file not shown.
Loading