Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Security] improve VoteObject adding extraData for give more possibilities to AccessDecicsionStrategy#60085

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
eltharin wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromeltharin:improveVoteObject

Conversation

eltharin
Copy link
Contributor

@eltharineltharin commentedMar 30, 2025
edited
Loading

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
LicenseMIT

In continuation of#58107 and#59771, add ExtraData in VoteObject and pass it to AccessDecicsionStrategy Object to allow the decision to be refined.

ExtraData can be an array or an object, and AccessDecicsionStrategy can get it to get the final decision.

In 7.2, voter can only respond abstain / allow or deny, but what if we want more choices, per example a ponderable vote ?

With this PR, it allow to put somme data in the new VoteObject as :

/** ScoreData.php */class ScoreData{public$score =0;}/** MyVoter.php */publicfunctionvote(TokenInterface$token,mixed$subject,array$attributes, ?Vote$vote =null) :int    {$vote->result =1;$vote->reasons[] ='is Admin';$vote->extraData =newScoreData();$vote->extraData->score =10;return$vote->result;    }

we need also a custom strategy to take this score into account :

/** MyStrategy.php */publicfunctiondecide(\Traversable$results,$accessDecision =null):bool    {$score =0;foreach ($resultsas$key =>$result) {$vote =$accessDecision->votes[$key];// <==if($vote->extraDatainstanceof ScoreData) {$score +=$vote->extraData->score;            }else {$score +=$vote->result;            }        }$accessDecision->result =$score;if ($score >0) {returntrue;        }if ($score<0) {returnfalse;        }return$this->allowIfAllAbstainDecisions;    }

AccessDecision contains Vote objects and we can read our score from it.

@carsonbotcarsonbot added this to the7.3 milestoneMar 30, 2025
@carsonbotcarsonbot changed the titleimprove VoteObject adding extraData for give more possibilities to AccessDecicsionStrategy[Security] improve VoteObject adding extraData for give more possibilities to AccessDecicsionStrategyMar 30, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

4 participants
@eltharin@fabpot@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp