Skip to content

add missing fields#566

Merged
dbarzin merged 4 commits intomainfrom
dev
Feb 2, 2026
Merged

add missing fields#566
dbarzin merged 4 commits intomainfrom
dev

Conversation

@dbarzin
Copy link
Copy Markdown
Owner

@dbarzin dbarzin commented Feb 2, 2026

Summary by CodeRabbit

  • New Features

    • Measures now support indicator, action_plan and domain_id fields.
  • Refactor

    • Streamlined measure creation flow for consistency across endpoints.
    • Strengthened API access authorization checks on measure endpoints.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 2, 2026

Warning

Rate limit exceeded

@dbarzin has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 46 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Walkthrough

Refactors authorization checks from role-based to Auth::user()->isAPI(), switches measure creation to mass-assignment, and updates Measure::$fillable to add domain_id, indicator, and action_plan (with reordering).

Changes

Cohort / File(s) Summary
API & Web Controllers
app/Http/Controllers/API/MeasureController.php, app/Http/Controllers/MeasureController.php
Replaced role check Auth::User()->role !== 4 with Auth::User()->isAPI() across CRUD methods. Store flows now use mass assignment (Measure::query()->create($request->all())). MeasureController store also normalizes attributes to a space-joined string and added import for Mercator\Core\Models\Task.
Model: Measure
app/Models/Measure.php
Updated public $fillable ordering and entries: added domain_id at front, repositioned name, and added indicator and action_plan to the fillable list.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 The code hops neat from old to new,

Auth checks changed and fields in view,
Creation now in one swift line,
New attributes join the vine,
I nibble bugs and call it fine! 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'add missing fields' is vague and generic, failing to clearly specify which fields are being added or to which component. Revise the title to be more specific and descriptive, such as 'Add domain_id, indicator, and action_plan to Measure model' to clearly communicate the primary change.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@app/Http/Controllers/API/MeasureController.php`:
- Line 26: In MeasureController's store() and update() flows, don't pass
$request->all() directly to Measure::query()->create(...) or ->update(...);
instead normalize the "attributes" field first: if $request->input('attributes')
is an array, convert it to a space-separated string via implode(' ',
$attributes) and put it back into the payload before calling
Measure::query()->create(...) or $measure->update(...). Ensure both the store()
and update() paths perform this normalization so the DB always receives a string
for attributes.

In `@app/Http/Controllers/MeasureController.php`:
- Line 199: The current line in MeasureController that sets
$request['attributes'] uses implode on an empty array which produces an empty
string instead of preserving NULL; change the assignment so that if
$request->get('attributes') is null you leave $request['attributes'] as null,
otherwise implode the array into a string (i.e. check
$request->get('attributes') === null and only call implode when it is not null)
so filters expecting NULL continue to work; locate this logic in
MeasureController (the assignment to $request['attributes']) and replace the
unconditional implode with a conditional/ternary that preserves null.
🧹 Nitpick comments (2)
app/Http/Controllers/MeasureController.php (2)

201-201: Prefer an explicit/validated payload over $request->all().

Mass‑assigning raw request data can persist unexpected fields and complicates validation reuse. Prefer an explicit allow‑list (or validated array) for creation.

🔧 Example with explicit allow‑list
-        $measure = Measure::query()->create($request->all());
+        $payload = $request->only([
+            'domain_id', 'clause', 'name', 'objective',
+            'attributes', 'input', 'model', 'indicator', 'action_plan',
+        ]);
+        $measure = Measure::query()->create($payload);

202-212: Remove the commented legacy block.

The commented‑out assignments add noise and can drift from the active logic. Remove once the new path is confirmed.

🧹 Suggested cleanup
-        // $measure = new Measure();
-        // $measure->domain_id = request('domain_id');
-        // $measure->clause = request('clause');
-        // $measure->name = request('name');
-        // $measure->attributes = request('attributes') !== null ? implode(' ', request('attributes')) : null;
-        // $measure->objective = request('objective');
-        // $measure->input = request('input');
-        // $measure->model = request('model');
-        // $measure->indicator = request('indicator');
-        // $measure->action_plan = request('action_plan');
-        // $measure->save();

abort_if(Auth::User()->isAPI(), Response::HTTP_FORBIDDEN, '403 Forbidden');

$measure = Measure::create($request->all());
$measure = Measure::query()->create($request->all());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

find . -type f -name "MeasureController.php" | head -5

Repository: dbarzin/deming

Length of output: 151


🏁 Script executed:

find . -type f -name "Measure.php" | grep -E "(Models|model)" | head -5

Repository: dbarzin/deming

Length of output: 82


🏁 Script executed:

cat -n app/Http/Controllers/API/MeasureController.php | sed -n '1,50p'

Repository: dbarzin/deming

Length of output: 1779


🏁 Script executed:

cat -n app/Models/Measure.php

Repository: dbarzin/deming

Length of output: 2427


🏁 Script executed:

cat -n app/Http/Controllers/MeasureController.php | sed -n '1,100p'

Repository: dbarzin/deming

Length of output: 4806


🏁 Script executed:

cat -n app/Http/Controllers/MeasureController.php | sed -n '50,150p'

Repository: dbarzin/deming

Length of output: 5414


🏁 Script executed:

grep -n "setAttribute\|Attribute\|mutate" app/Models/Measure.php

Repository: dbarzin/deming

Length of output: 40


🏁 Script executed:

fd -t f "migration.*measure" --exec grep -l "attributes" {} \; 2>/dev/null | head -3

Repository: dbarzin/deming

Length of output: 40


🏁 Script executed:

cat -n app/Http/Controllers/MeasureController.php | sed -n '150,250p'

Repository: dbarzin/deming

Length of output: 4052


🏁 Script executed:

find . -path "./database/migrations/*" -name "*.php" | xargs grep -l "measures\|Measure" | head -3

Repository: dbarzin/deming

Length of output: 242


🏁 Script executed:

cat -n app/Http/Controllers/MeasureController.php | sed -n '260,320p'

Repository: dbarzin/deming

Length of output: 2112


🏁 Script executed:

cat -n ./database/migrations/2019_08_09_084322_create_measures_table.php

Repository: dbarzin/deming

Length of output: 1591


🏁 Script executed:

cat -n app/Http/Controllers/MeasureController.php | sed -n '350,410p'

Repository: dbarzin/deming

Length of output: 2282


Normalize attributes before mass create and update in the API controller.

Both store() (line 26) and update() (line 45) pass $request->all() directly to create/update without normalizing the attributes field. The web controller explicitly converts attributes array to space-separated string using implode(' ', ...) before saving (see store at line 199 and update at line 393). The database stores this as TEXT, and the parsing logic uses explode(' ') expecting a string. If API clients send attributes as an array, an array object gets stored instead, breaking the parsing logic.

🔧 Suggested normalization
-        $measure = Measure::query()->create($request->all());
+        $payload = $request->all();
+        if ($request->has('attributes')) {
+            $attributes = $request->input('attributes');
+            $payload['attributes'] = is_array($attributes)
+                ? implode(' ', $attributes)
+                : $attributes;
+        }
+        $measure = Measure::query()->create($payload);

Apply the same normalization to the update() method at line 45.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$measure = Measure::query()->create($request->all());
$payload = $request->all();
if ($request->has('attributes')) {
$attributes = $request->input('attributes');
$payload['attributes'] = is_array($attributes)
? implode(' ', $attributes)
: $attributes;
}
$measure = Measure::query()->create($payload);
🤖 Prompt for AI Agents
In `@app/Http/Controllers/API/MeasureController.php` at line 26, In
MeasureController's store() and update() flows, don't pass $request->all()
directly to Measure::query()->create(...) or ->update(...); instead normalize
the "attributes" field first: if $request->input('attributes') is an array,
convert it to a space-separated string via implode(' ', $attributes) and put it
back into the payload before calling Measure::query()->create(...) or
$measure->update(...). Ensure both the store() and update() paths perform this
normalization so the DB always receives a string for attributes.

Comment thread app/Http/Controllers/MeasureController.php Outdated
dbarzin and others added 3 commits February 2, 2026 08:24
@dbarzin dbarzin merged commit f9ee022 into main Feb 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant