Example #1
0
    def update(self, request, workspace_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'workspace')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("workspace JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            ts = eval(received_json)
            workspace = WorkSpace.objects.get(user=user, pk=workspace_id)

            if ts.has_key('active'):
                active = ts.get('active')
                if (active == 'true'):
                    #Only one active workspace
                    setActiveWorkspace(user, workspace)
                else:
                    workspace.active = False

            if ts.has_key('name'):
                workspace.name = ts.get('name')

            workspace.save()

            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = _("workspace cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Example #2
0
    def update(self, request, workspace_id, tab_id, igadget_id, var_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'value')

        # Gets value parameter from request
        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("iGadget JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        new_value = received_json

        tab = Tab.objects.get(workspace__users__id=user.id,
                              workspace__pk=workspace_id,
                              pk=tab_id)
        variable = get_object_or_404(Variable,
                                     igadget__tab=tab,
                                     igadget__pk=igadget_id,
                                     vardef__pk=var_id)
        try:
            variable.value = new_value
            variable.save()
        except Exception, e:
            transaction.rollback()
            log(e, request)
            return HttpResponseServerError(
                get_xml_error(e), mimetype='application/xml; charset=UTF-8')
Example #3
0
    def update(self, request, workspace_id, tab_id, igadget_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'igadget')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("iGadget JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            igadget = simplejson.loads(received_json)
            tab = Tab.objects.get(workspace__users__id=user.id,
                                  workspace__pk=workspace_id,
                                  pk=tab_id)
            UpdateIGadget(igadget, user, tab)
            return HttpResponse('ok')
        except Tab.DoesNotExist:
            msg = _('referred tab %(tab_id)s does not exist.')
            log(msg, request)
            return HttpResponseBadRequest(get_xml_error(msg))
        except Exception, e:
            transaction.rollback()
            msg = _("iGadget cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Example #4
0
    def update(self, request, workspace_id, tab_id, igadget_id):
        user = get_user_authentication(request)

        workspace = WorkSpace.objects.get(id=workspace_id)
        if workspace.creator != user:
            raise Http403()

        content_type = request.META.get('CONTENT_TYPE', '')
        if content_type == None:
            content_type = ''

        if content_type.startswith('application/json'):
            received_json = request.raw_post_data
        else:
            received_json = PUT_parameter(request, 'igadget')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("iGadget JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            data = simplejson.loads(received_json)
            igadget_pk = data.get('id')

            # get the iGadget object
            igadget = get_object_or_404(IGadget, pk=igadget_pk)

            new_version = data.get('newVersion')
            if workspace.is_shared():
                users = UserWorkSpace.objects.filter(
                    workspace=workspace).values_list('user', flat=True)
            else:
                users = [user]

            if not 'source' in data or data.get('source') == 'catalogue':
                gadget = get_or_create_gadget_from_catalogue(
                    igadget.gadget.vendor, igadget.gadget.name, new_version,
                    user, users, request)
            elif data.get('source') == 'showcase':
                gadget = get_and_add_gadget(igadget.gadget.vendor,
                                            igadget.gadget.name, new_version,
                                            users)

            UpgradeIGadget(igadget, user, gadget)

            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = unicode(e)

            raise TracedServerError(e, {
                'workspace': workspace_id,
                'tab': tab_id
            }, request, msg)
Example #5
0
 def update(self, request, workspace_id, share_boolean):
     user = get_user_authentication(request)
     
     try:
         workspace = WorkSpace.objects.get(id=workspace_id)
     except WorkSpace.DoesNotExist:
         msg = 'The workspace does not exist!'
         result = {'result': 'error', 'description': msg}
         HttpResponseServerError(json_encode(result), mimetype='application/json; charset=UTF-8')
     
     owner = workspace.get_creator()
     
     if (owner != user):
         msg = 'You are not the owner of the workspace, so you can not share it!'
         result = {'result': 'error', 'description': msg}
         return HttpResponseServerError(json_encode(result), mimetype='application/json; charset=UTF-8')
     
     #Everything right!
     if not request.REQUEST.has_key('groups'):
         #Share with everybody
         #Linking with public user!
         public_user = get_public_user(request)
         
         linkWorkspaceObject(public_user, workspace, owner, link_variable_values=True)
         
         url = request.META['HTTP_REFERER'] + 'viewer/workspace/' + workspace_id
         
         result = {"result": "ok", "url": url}
         return HttpResponse(json_encode(result), mimetype='application/json; charset=UTF-8')        
     else:
         #Share only with the scpecified groups
         try:
             groups = simplejson.loads(PUT_parameter(request, 'groups'))
             queryGroups = Group.objects.filter(id__in=groups)
             for g in queryGroups:
                 workspace.targetOrganizations.add(g)
             
             users = User.objects.filter(groups__in=groups).distinct()
             for user in users:
                 #link the workspace with each user
                 linkWorkspaceObject(user, workspace, owner, link_variable_values=True)
            
         except Exception, e:
             transaction.rollback()
             msg = _("workspace cannot be shared: ") + unicode(e)
         
             raise TracedServerError(e, groups, request, msg)                 
         result = {"result": "ok"}
         return HttpResponse(json_encode(result), mimetype='application/json; charset=UTF-8')
Example #6
0
    def update(self, request, user_name):
        user = get_user_authentication(request)
        received_json = PUT_parameter(request, 'preferences')

        if not received_json:
            return HttpResponseBadRequest(get_xml_error(_("Platform Preferences JSON expected")), mimetype='application/xml; charset=UTF-8')

        try:
            preferences_json = simplejson.loads(received_json)
            update_preferences(user, preferences_json)
            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = _("Platform Preferences cannot be updated: ") + unicode(e)

            raise TracedServerError(e, {}, request, msg)
Example #7
0
    def update(self, request, user_name, vendor, name, version):
        user = user_authentication(request, user_name)

        # Get the gadget data from the request
        preferred = PUT_parameter(request, 'preferred')

        if preferred != None:
            # Set all version of this gadget as no preferred
            old_preferred_versions = UserRelatedToGadgetResource.objects.filter(
                gadget__vendor=vendor,
                gadget__short_name=name,
                user=user,
                preferred_by=True)
            for old_version in old_preferred_versions:
                old_version.preferred_by = False
                old_version.save()

            new_preferred_versions = UserRelatedToGadgetResource.objects.filter(
                gadget__vendor=vendor,
                gadget__short_name=name,
                gadget__version=version,
                user=user)

            userRelated = None
            if len(new_preferred_versions) == 0:
                resource = get_object_or_404(GadgetResource,
                                             short_name=name,
                                             vendor=vendor,
                                             version=version)
                userRelated = UserRelatedToGadgetResource()
                userRelated.gadget = resource
                userRelated.user = user
                userRelated.added_by = False
            else:
                userRelated = new_preferred_versions[0]

            userRelated.preferred_by = True
            userRelated.save()

            resource = get_object_or_404(GadgetResource,
                                         short_name=name,
                                         vendor=vendor,
                                         version=version)

            return get_resource_response([resource], 'json', 1, user)
Example #8
0
    def update(self, request, workspace_id, tab_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'tab')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("tab JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            t = simplejson.loads(received_json)
            tab = Tab.objects.get(workspace__users__id=user.id,
                                  workspace__pk=workspace_id,
                                  pk=tab_id)

            if t.has_key('visible'):
                visible = t.get('visible')
                if (visible == 'true'):
                    #Only one visible tab
                    setVisibleTab(user, workspace_id, tab)
                else:
                    tab.visible = False

            if t.has_key('name'):
                tab.name = t.get('name')

            if t.has_key('locked'):
                if t.get('locked') == 'true':
                    tab.locked = True
                else:
                    tab.locked = False

            tab.save()

            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = _("tab cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Example #9
0
    def update(self, request, workspace_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'order')
        try:
            order = simplejson.loads(received_json)
            
            tabs = Tab.objects.filter(id__in=order)
            
            for tab in tabs:
                tab.position = order.index(tab.id)
                tab.save()
        
            return HttpResponse('ok')
    
        except Exception, e:
            transaction.rollback()
            msg = _("tab order cannot be updated: ") + unicode(e)
            
            raise TracedServerError(e, t, request, msg)
Example #10
0
    def update(self, request, user_name, workspace_id, tab_id):
        user = get_user_authentication(request)
        received_json = PUT_parameter(request, 'preferences')

        if not received_json:
            return HttpResponseBadRequest(get_xml_error(_("Platform Preferences JSON expected")), mimetype='application/xml; charset=UTF-8')

        try:
            preferences_json = simplejson.loads(received_json)

            # Check Tab existance and owned by this user
            tab = get_object_or_404(Tab, workspace__users__id=user.id, workspace__pk=workspace_id, pk=tab_id)

            update_tab_preferences(tab, preferences_json)
            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = _("Tab Preferences could not be updated: ") + unicode(e)

            raise TracedServerError(e, {}, request, msg)
Example #11
0
    def update(self, request, workspace_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'variables')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("variables JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            variables = simplejson.loads(received_json)

            igadgetVariables = variables['igadgetVars']
            workSpaceVariables = variables['workspaceVars']

            for wsVar in workSpaceVariables:
                wsVarDAO = WorkSpaceVariable.objects.get(pk=wsVar['id'])

                variable_value = VariableValue.objects.get(
                    user=user, abstract_variable=wsVarDAO.abstract_variable)

                variable_value.value = wsVar['value']
                variable_value.save()

            for igVar in igadgetVariables:
                igVarDAO = Variable.objects.get(pk=igVar['id'])

                variable_value = VariableValue.objects.get(
                    user=user, abstract_variable=igVarDAO.abstract_variable)

                variable_value.value = igVar['value']
                variable_value.save()

            return HttpResponse(str('OK'))
        except Exception, e:
            transaction.rollback()
            msg = _("cannot update variables: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Example #12
0
    def update(self, request, workspace_id, tab_id, igadget_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'variables')

        # Gets JSON parameter from request
        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("iGadget variables JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            received_variables = simplejson.loads(received_json)

            tab = Tab.objects.get(workspace__users__id=user.id,
                                  workspace__pk=workspace_id,
                                  pk=tab_id)
            server_variables = Variable.objects.filter(igadget__tab=tab)

            # Gadget variables collection update
            for varServer in server_variables:
                for varJSON in received_variables:
                    if (varServer.vardef.pk == varJSON['pk']
                            and varServer.igadget.pk == varJSON['iGadget']):
                        varServer.value = varJSON['value']
                        varServer.save()

            transaction.commit()
        except Tab.DoesNotExist:
            msg = _('referred tab %(tab_id)s does not exist.')
            log(msg, request)
            return HttpResponseBadRequest(get_xml_error(msg))
        except Exception, e:
            transaction.rollback()
            log(e, request)
            return HttpResponseServerError(
                get_xml_error(unicode(e)),
                mimetype='application/xml; charset=UTF-8')
Example #13
0
    def update(self, request, workspace_id, last_user=''):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'workspace')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("workspace JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            ts = simplejson.loads(received_json)
            workspace = WorkSpace.objects.get(users__id=user.id,
                                              pk=workspace_id)

            if 'active' in ts:
                active = ts['active']
                if (active == 'true'):
                    #Only one active workspace
                    setActiveWorkspace(user, workspace)
                else:
                    currentUserWorkspace = UserWorkSpace.objects.get(
                        workspace=workspace, user=user)
                    currentUserWorkspace.active = True
                    currentUserWorkspace.save()

            if 'name' in ts:
                workspace.name = ts['name']

            workspace.save()

            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = _("workspace cannot be updated: ") + unicode(e)

            raise TracedServerError(e, ts, request, msg)
Example #14
0
    def update(self, request, workspace_id):
        user = get_user_authentication(request)

        content_type = request.META.get('CONTENT_TYPE', '')
        if content_type == None:
            content_type = ''

        if content_type.startswith('application/json'):
            received_json = request.raw_post_data
        else:
            received_json = PUT_parameter(request, 'variables')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("variables JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            variables = simplejson.loads(received_json)

            igadgetVariables = variables['igadgetVars']
            workSpaceVariables = variables['workspaceVars']

            for wsVar in workSpaceVariables:
                wsVarDAO = WorkSpaceVariable.objects.get(pk=wsVar['id'])

                variable_value = VariableValue.objects.get(
                    user=user, abstract_variable=wsVarDAO.abstract_variable)

                variable_value.value = unicode(wsVar['value'])
                variable_value.save()

            variables_to_notify = []
            for igVar in igadgetVariables:
                igVarDAO = Variable.objects.get(pk=igVar['id'])
                variable_value = VariableValue.objects.get(
                    user=user, abstract_variable=igVarDAO.abstract_variable)

                if 'shared' in igVar:
                    if not igVar['shared']:
                        #do not share the value: remove the relationship
                        variable_value.shared_var_value = None
                    else:
                        shared_variable_def = igVarDAO.vardef.shared_var_def
                        variable_value.shared_var_value = SharedVariableValue.objects.get(
                            user=user, shared_var_def=shared_variable_def)
                        #share the specified value
                        variable_value.shared_var_value.value = unicode(
                            igVar['value'])
                        variable_value.shared_var_value.save()

                        #notify the rest of variables that are sharing the value
                        #VariableValues whose value is shared (they have a relationship with a SharedVariableValue)
                        variable_values = VariableValue.objects.filter(
                            shared_var_value=variable_value.shared_var_value
                        ).exclude(id=variable_value.id)
                        #Variables that correspond with these values
                        for value in variable_values:
                            try:
                                variable = Variable.objects.get(
                                    abstract_variable=value.abstract_variable,
                                    igadget__tab__workspace__id=workspace_id)
                                exists = False
                                for var in variables_to_notify:
                                    if var['id'] == variable.id:
                                        var['value'] = value.shared_var_value.value
                                        exists = True
                                        break
                                if not exists:
                                    variables_to_notify.append({
                                        'id':
                                        variable.id,
                                        'value':
                                        value.shared_var_value.value
                                    })
                            except Variable.DoesNotExist:
                                #it's not from the same workspace. Do nothing
                                pass

                variable_value.value = unicode(igVar['value'])
                variable_value.save()

            data = {'igadgetVars': variables_to_notify}
            return HttpResponse(json_encode(data),
                                mimetype='application/json; charset=UTF-8')

        except Exception, e:
            transaction.rollback()
            msg = _("cannot update variables: ") + unicode(e)

            raise TracedServerError(e, received_json, request, msg)