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

Implement Parent API #61

Open
niicojs opened this issue Sep 8, 2024 · 7 comments
Open

Implement Parent API #61

niicojs opened this issue Sep 8, 2024 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@niicojs
Copy link

niicojs commented Sep 8, 2024

It would be nice to implement parent api.
From the very limited tests I've done, it seems to be the student api with an additionnal field in signature to tell which resource to impersonate.

Adding those few lines in request-function.ts did the trick in my little test:

    if (this.session?.user && this.data?._Signature_) {
      if (this.session.information.accountKind === AccountKind.PARENT) {
        this.data._Signature_.membre = {
          N: this.session.user.resources.at(0)?.id,
          G: 4,
        };
      }
    }

I don't know what the 4 is for :)

@Vexcited
Copy link
Member

Vexcited commented Sep 8, 2024

In the request you showed, membre corresponds to the kid you want to get the values from.
N is the ID of resource and G: 4 is the kind of the resource. 4 means Student, you can see it in ~/models/entity-kind -> EntityKind.Student.

@Vexcited Vexcited self-assigned this Sep 8, 2024
@Vexcited Vexcited added the enhancement New feature or request label Sep 8, 2024
@Vexcited Vexcited pinned this issue Sep 8, 2024
@niicojs
Copy link
Author

niicojs commented Sep 8, 2024

Ok so more like:

    if (this.session?.user && this.data?._Signature_) {
      if (this.session.information.accountKind === AccountKind.PARENT) {
        const kid = this.session.user.resources.at(0);
        this.data._Signature_.membre = {
          N: kid?.id,
          G: kid?.kind,
        };
      }
    }

@Vexcited
Copy link
Member

Vexcited commented Sep 8, 2024

Yes it would work, I wonder which requests requires this.

Also I wonder where I should let the developer switch to/use another resource (kid for example)...

@Vexcited
Copy link
Member

Vexcited commented Sep 8, 2024

I'm thinking of a state in SessionHandle that holds the index of the resource the developer wants to use and it should default to 0.

You could switch by doing pronote.use(index: number): void or session.resourceUsed = index.

API requests will then use that value from session to do requests depending on the account kind.

Vexcited added a commit that referenced this issue Sep 8, 2024
can be mutated using the `pronote.use(session, value)` helper method
@Vexcited
Copy link
Member

Vexcited commented Sep 8, 2024

Decided to go on this use helper : f05fa81#diff-bfc1c859dba30aea6586432084f6d67dce2d09659a66accbbd764a3fa773f88c

That mutates the new userResource property on SessionHandle : f05fa81#diff-21f9f474e3b5519d91463808fdacc417f872fab6926b43f5447d1cb23bc5937c

That allows for simpler retrieving of the current selected user, that's very cool since it cleans up a lot of the code !

Now, I have to write the differences in requests for parents only.

@niicojs
Copy link
Author

niicojs commented Sep 8, 2024

looks good

@niicojs
Copy link
Author

niicojs commented Sep 8, 2024

From what I can see navigating through the pronote web site, the membre field is present each time there is a _Signature_ present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants