def get_object(self, queryset=None): obj = super(UserEnvironmentSecurityMixin, self).get_object(queryset) rules_light.require(self.request.user, 'appstore.environment.update', obj.environment) return obj
def get(self, request, *args, **kwargs): rules_light.require(request.user, 'askapp.post.delete_all', None) post = get_object_or_404(models.Post, pk=kwargs['post_id']) post.get_descendants(include_self=True).update(deleted=1) return redirect( reverse_lazy('thread', args=(post.thread.id, slugify(post.thread.title))))
def dispatch(self, request, *args, **kwargs): self.environment = Environment.objects.get(pk=kwargs['env_pk']) rules_light.require(request.user, 'appstore.environment.update', self.environment) return super(UserEnvironmentCreateView, self).dispatch(request, *args, **kwargs)
def get_queryset(self): self.environment = Environment.objects.get(pk=self.kwargs['env_pk']) rules_light.require(self.request.user, 'appstore.environment.update', self.environment) return UserEnvironment.objects.filter(environment=self.environment ).select_related('user')
def get_object(self, queryset=None): obj = super(UserEnvironmentSecurityMixin, self).get_object( queryset) rules_light.require(self.request.user, 'appstore.environment.update', obj.environment) return obj
def get_queryset(self): self.environment = Environment.objects.get(pk=self.kwargs['env_pk']) rules_light.require(self.request.user, 'appstore.environment.update', self.environment) return UserEnvironment.objects.filter( environment=self.environment).select_related('user')
def get(self, request, *args, **kwargs): # no need to display the post deletion confirmation, so use GET method instead of POST post = get_object_or_404(models.Post, pk=kwargs['post_id']) rules_light.require(request.user, 'askapp.post.delete', post) post.deleted = True post.save() return redirect( reverse_lazy('thread', args=(post.thread.id, slugify(post.thread.title))))
def get(self, request, *args, **kwargs): thread = get_object_or_404(models.Thread, pk=kwargs['thread_id']) rules_light.require( request.user, 'askapp.thread.update', thread) # check user credentials to update the thread thread.closed = not thread.closed thread.save() return redirect( reverse_lazy('thread', args=(thread.id, slugify(thread.title))))
def get(self, request, *args, **kwargs): env = self.get_object() rules_light.require(request.user, 'appstore.environment.read', env) messages.success(self.request, _(u'Environment "%s" activated') % env) request.session['appstore_environment'] = env return http.HttpResponseRedirect('/')
def get_object(self): self.appform = AppForm.objects.get(app__pk=self.kwargs['app_pk']) rules_light.require(self.request.user, 'form_designer.form.update', self.appform.form) if self.appform.app.deployed: raise CannotEditDeployedApp(self.appform.app) return self.appform.form
def get(self, request, *args, **kwargs): post = get_object_or_404(models.Post, pk=kwargs['post_id']) rules_light.require(request.user, 'askapp.post.accept', post) post.accept() return redirect( request.META.get( 'HTTP_REFERER', reverse_lazy('thread', args=(post.thread.id, slugify(post.thread.title)))))
def get_form(self, form_class=None): if not hasattr(self, 'thread'): thread_id = self.kwargs.get('thread_id') self.thread = get_object_or_404(models.Thread, pk=thread_id) if self.request.method == 'POST': rules_light.require(self.request.user, 'askapp.post.create', self.thread) if hasattr(self, 'post_object'): rules_light.require(self.request.user, 'askapp.post.reply', self.post_object) return super(ReplyMixin, self).get_form(form_class)
def get_object(self): """ If the app is already deployed: edit it, and return the edit. """ obj = super(AppUpdateView, self).get_object() if obj.deployed: raise CannotEditDeployedApp(obj) rules_light.require(self.request.user, 'appstore.app.update', obj) return obj
def post(self, request, *args, **kwargs): """ Take action with an app on the current environment on POST request. Supported actions are: 'install', 'uninstall', 'copy', 'update'. This is ment to be accessed via ajax. Install/uninstall: respond with 201 on success, 400 on failure. Copy/update: respond with 301 redirect to update view, 400 on failure. """ environment = request.session['appstore_environment'] rules_light.require(request.user, 'appstore.environment.update', environment) app = self.get_object() if request.user in environment.users.all(): try: action = request.POST.get('action', None) if action == 'install': environment.install(app) msg = u'%(app)s installed into %(env)s' elif action == 'uninstall': environment.uninstall(app) msg = u'%(app)s uninstalled from %(env)s' elif action == 'copy': new_app = environment.copy(app) msg = u'%(app)s copied into %(env)s' elif action == 'update': msg = u'%(app)s copied for updateinto %(env)s' new_app = environment.copy(app, True) else: return http.HttpResponseBadRequest('Unknown action') messages.success(request, _(msg) % { 'app': app, 'env': environment }) if action in ('copy', 'update'): return http.HttpResponseRedirect( reverse('appstore_app_update', args=(new_app.pk, ))) except AppstoreException as e: return http.HttpResponseBadRequest(e.message) return http.HttpResponse(status=201) else: return http.HttpResponseForbidden('Not an admin for this env')
def post(self, request, *args, **kwargs): form = shortcuts.get_object_or_404(Form, pk=request.POST['form_pk']) rules_light.require(request.user, 'form_designer.form.update', form) tab = Tab.objects.create( verbose_name=request.POST['verbose_name'], name=slugify(request.POST['verbose_name']), form=form) return http.HttpResponse(json.dumps({'tab': { 'pk': tab.pk, 'verbose_name': tab.verbose_name}}), status=201)
def post(self, request, *args, **kwargs): """ Take action with an app on the current environment on POST request. Supported actions are: 'install', 'uninstall', 'copy', 'update'. This is ment to be accessed via ajax. Install/uninstall: respond with 201 on success, 400 on failure. Copy/update: respond with 301 redirect to update view, 400 on failure. """ environment = request.session['appstore_environment'] rules_light.require(request.user, 'appstore.environment.update', environment) app = self.get_object() if request.user in environment.users.all(): try: action = request.POST.get('action', None) if action == 'install': environment.install(app) msg = u'%(app)s installed into %(env)s' elif action == 'uninstall': environment.uninstall(app) msg = u'%(app)s uninstalled from %(env)s' elif action == 'copy': new_app = environment.copy(app) msg = u'%(app)s copied into %(env)s' elif action == 'update': msg = u'%(app)s copied for updateinto %(env)s' new_app = environment.copy(app, True) else: return http.HttpResponseBadRequest('Unknown action') messages.success(request, _(msg) % {'app': app, 'env': environment}) if action in ('copy', 'update'): return http.HttpResponseRedirect(reverse( 'appstore_app_update', args=(new_app.pk,))) except AppstoreException as e: return http.HttpResponseBadRequest(e.message) return http.HttpResponse(status=201) else: return http.HttpResponseForbidden('Not an admin for this env')
def post(self, *args, **kwargs): """ Set app.deployed=True and redirect to environment configuration url. """ self.object = self.get_object() rules_light.require(self.request.user, 'appstore.app.deploy', self.object) self.object.deployed = True self.object.save() messages.success(self.request, _(u'App %s successfully deployed.') % self.object) return http.HttpResponseRedirect(reverse('appstore_env_update', args=[self.request.session['appstore_environment'].pk]))
def post(self, *args, **kwargs): """ Set app.deployed=True and redirect to environment configuration url. """ self.object = self.get_object() rules_light.require(self.request.user, 'appstore.app.deploy', self.object) self.object.deployed = True self.object.save() messages.success(self.request, _(u'App %s successfully deployed.') % self.object) return http.HttpResponseRedirect( reverse('appstore_env_update', args=[self.request.session['appstore_environment'].pk]))
def get_form(self, form_class): pk = self.request.GET.get('pk', None) widget_class = self.request.GET.get('widget_class', None) if pk: self.object = Widget.objects.filter(pk=pk ).select_subclasses()[0] else: if widget_class not in WIDGET_CLASSES: return tab = Tab.objects.get(pk=self.request.GET['tab_id']) widget_class = import_class(widget_class) self.object = widget_class(tab=tab) rules_light.require(self.request.user, 'form_designer.form.update', self.object.tab.form) return self.object.configuration_form_instance(self.request)
def dispatch(self, request, *args, **kwargs): rules_light.require(request.user, 'appstore.environment.update', request.session['appstore_environment']) return super(AppCreateView, self).dispatch(request, *args, **kwargs)
def get_object(self): widget = super(WidgetSecurity, self).get_object() rules_light.require(self.request.user, 'form_designer.form.update', widget.tab.form) return widget
def get_context_data(self, **kwargs): rules_light.require(self.request.user, 'fusion.list.detail', self.object) self.request.session['appstore_environment'] = self.object.environment q = self.request.GET.get('q', None) if q: if '*' in q: q = q.replace('*', '') records = Record.objects.filter(text_data__icontains=q) else: records = Record.objects.search(q) else: records = Record.objects.all() records = records.filter( environment=self.request.session['appstore_environment'], form__appform__app__provides_id=self.object.feature.pk) table_data = [] for record in records: data = { '_record_': record, } data.update(record.data) for k, v in data.items(): if isinstance(v, basestring) and v.isdigit(): data[k] = int(v) table_data.append(data) columns = { '_record_': RecordColumn(), } widgets_qs = Widget.objects.filter( tab__form__appform__app__provides=self.object.feature, tab__form__appform__app__environment=self.object.environment ).distinct() widgets_qs = Widget.objects.filter( pk__in=widgets_qs.values_list('pk')).order_by('tab', 'tab__order') list_columns = ListColumn.objects.filter(list=self.object) for column in list_columns: widget = column.widget.type_cast() attrs = { 'th': { 'data-widget-pk': widget.widget_ptr_id, 'data-widget-name': widget.name, } } if isinstance(widget, RecordsWidget): columns[widget.name] = LinkedColumn(verbose_name=mark_safe( widget.verbose_name), attrs=attrs) else: columns[widget.name] = tables.Column(verbose_name=mark_safe( widget.verbose_name), attrs=attrs) widgets_qs = widgets_qs.exclude(name=widget.name) for name in columns.keys(): for data in table_data: if name not in data: data[name] = None table_class = type('RecordTable', (RecordTable, ), columns) context = super(ListDetailView, self).get_context_data(**kwargs) table = table_class(table_data) tables.RequestConfig(self.request).configure(table) context['table'] = table context['widgets'] = widgets_qs return context
def get_object(self): tab = super(TabSecurity, self).get_object() rules_light.require(self.request.user, 'form_designer.form.update', tab.form) return tab