Giter Club home page Giter Club logo

Comments (6)

logston avatar logston commented on August 22, 2024

Nice. Is there any way we can generalize this so that it can apply to all the views? If not, is there a way to generalize it for mutating views?

from django-scim2.

truonghoangnguyen avatar truonghoangnguyen commented on August 22, 2024

Sorry for my terrible english
In PostView base class we check if inheristance had implemented post_post , so in gereral not things change.

Below is my code in real project

# scim\views.py
class PostView(object):
    def post(self, request, **kwargs):
        obj = self.model_cls()
        scim_obj = self.scim_adapter(obj, request=request)
        body = json.loads(request.body.decode(constants.ENCODING))
        scim_obj.from_dict(body)
        try:
            scim_obj.save(force_insert=True)
            if hasattr(self, 'post_post'):
                self.post_post(scim_obj, body)

In inheristance View, implement post_post method

class IdmUserView(UsersView):
    """ Override ScimUser view for addtion query parameter
    """
    def post_post(self, scim_obj, body):
        user = User.objects.get(id=str(scim_obj.obj.id))
        UserCredenticalHistory.add(user=user, action="NEWUSER", data=scim_obj.to_dict())
        # save to group if request
        groupid = body.get("group")
        if groupid:
            try:
                group = get_group_model().objects.get(id=groupid)
                group.user_set.add(user)
            except Exception as e:
                return {"error": str(e)}
        return None

    scim_adapter = IdmSCIMUserAdapter
    model_cls = User
    get_extra_filter_kwargs = user_get_extra_model_filter_kwargs_getter(model_cls)
    get_extra_exclude_kwargs = empty_get_extra_model_exclude_kwargs_getter(model_cls)

from django-scim2.

logston avatar logston commented on August 22, 2024

Sorry for the delay. Got time now from work to look into this.

The way we do it is we inherit from the django_scim.adapters.SCIMUser model and override it.

For example,

from django_scim.adapters import SCIMUser


class CustomSCIMUser(SCIMUser):
    ...
    def from_dict(self, d):
        ...
    	if self.obj.is_active = d.get('is_active'):
        ...

    def save(self):
        ...
        logger.info('User saved')

Then in your settings file...

SCIM_SERVICE_PROVIDER = {
    ...
    'USER_ADAPTER': 'scim.adapters.CustomSCIMUser',
    ...
}

from django-scim2.

logston avatar logston commented on August 22, 2024

Would this work for you?

from django-scim2.

truonghoangnguyen avatar truonghoangnguyen commented on August 22, 2024

work perfect, thanks

from django-scim2.

logston avatar logston commented on August 22, 2024

Great. Thanks for the input @truonghoangnguyen !

from django-scim2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.