Exemple #1
0
    def postprocess(self, obj):
        rolemap = ( ("tosca.relationships.AdminPrivilege", "admin"), ("tosca.relationships.AccessPrivilege", "access"),
                    ("tosca.relationships.PIPrivilege", "pi"), ("tosca.relationships.TechPrivilege", "tech") )
        for (rel, role) in rolemap:
            for obj_name in self.get_requirements(rel):
                dest = self.engine.name_to_xos_model(self.user, obj_name)
                if dest.__class__.__name__ == "Slice":
                    role_obj = self.get_xos_object(SliceRole, role=role)
                    if not SlicePrivilege.objects.filter(user=user, role=role_obj, slice=dest):
                        sp = SlicePrivilege(user=obj, role=role_obj, slice=dest)
                        sp.save()
                        self.info("Added slice privilege on %s role %s for %s" % (str(dest), str(role), str(obj)))
                elif dest.__class__.__name__ == "Site":
                    role_obj = self.get_xos_object(SiteRole, role=role)
                    if not SitePrivilege.objects.filter(user=obj, role=role_obj, site=dest):
                        sp = SitePrivilege(user=obj, role=role_obj, site=dest)
                        sp.save()
                        self.info("Added site privilege on %s role %s for %s" % (str(dest), str(role), str(obj)))

        dashboard_order = 10
        for reqs in self.nodetemplate.requirements:
            for (k,v) in reqs.items():
                if (v["relationship"] == "tosca.relationships.UsesDashboard"):
                    dashboard_name = v["node"]
                    dashboard = self.get_xos_object(DashboardView, name=dashboard_name)

                    udvs = UserDashboardView.objects.filter(user=obj, dashboardView=dashboard)
                    if not udvs:
                        self.info("Adding UserDashboardView from %s to %s" % (obj, dashboard))

                        udv = UserDashboardView(user=obj, dashboardView=dashboard, order=dashboard_order)
                        dashboard_order += 10
                        udv.save()
Exemple #2
0
    def add_dashboard_to_user(self, user_id, dashboard_id, order):
        try:
            existing = UserDashboardView.objects.get(user_id=user_id, dashboardView_id=dashboard_id)
        except:
            # if the dashboard does not exist create a new entry
            new_dashboard = UserDashboardView()
            new_dashboard.user_id = user_id
            new_dashboard.dashboardView_id = dashboard_id
            new_dashboard.order = order
            new_dashboard.save()
            return new_dashboard

        # else update this one, and update order for the others
        if(existing.order is not order):
            # update all changed models
            updateList = UserDashboardView.objects.filter(user_id=user_id).filter(order__lt=existing.order).filter(order__gte=order).exclude(id=existing.id)

            for d in updateList:
                d.order = d.order + 1
                d.save()

            # update current model
            existing.order = order
            existing.save()
        return existing
Exemple #3
0
    def add_dashboard_to_user(self, user_id, dashboard_id, order):
        try:
            existing = UserDashboardView.objects.get(user_id=user_id, dashboardView_id=dashboard_id)
        except:
            # if the dashboard does not exist create a new entry
            new_dashboard = UserDashboardView()
            new_dashboard.user_id = user_id
            new_dashboard.dashboardView_id = dashboard_id
            new_dashboard.order = order
            new_dashboard.save()
            return new_dashboard

        # else update this one, and update order for the others
        if(existing.order is not order):
            # update all changed models
            updateList = UserDashboardView.objects.filter(user_id=user_id).filter(order__lt=existing.order).filter(order__gte=order).exclude(id=existing.id)

            for d in updateList:
                d.order = d.order + 1
                d.save()

            # update current model
            existing.order = order
            existing.save()
        return existing