Commit graph

259 commits

Author SHA1 Message Date
Philip How
33fd9836be
Add CSS as pages template option (#20512)
* add css as pages option

* don't forget schema

* fix test

* add api support
2024-01-12 15:35:38 +00:00
Ben Halpern
e376e2b887
Add cookie requirement option for billboards (#20486)
* Add cookie requirement for billboards

* Clean up tests

* Fix up tests

* Adjust tests

* Adjust tests
2024-01-03 16:33:08 +00:00
Anna Buianova
473594f192
Match spam role with existing suspended actions (#20477)
* Started matching spam and suspended roles

* Match spam and suspended roles in most cases

* Fixed check_suspended for unauthenticated users
2023-12-27 20:12:50 +00:00
Ben Halpern
f0673648c2
Add preferred_article_ids to billboards (#20437)
* Add preferred_article_ids to billboards

* Adjust query

* Refactor method

* Refactor method

* Fix input type

* Add feature flag
2023-12-18 19:20:56 +00:00
Philip How
78b42c5efd
Add trusted role via API (#20455)
* rubocop

* use has_trusted_role? in tests, not trusted? due to pesky caching issues

* swagger
2023-12-18 18:38:05 +00:00
Anna Buianova
81b042ee25
Give admins the ability to add spam role to users via the API (#20445) 2023-12-12 14:35:55 +00:00
Anna Buianova
4815661bad
Api search users by email (#20423) 2023-12-04 23:18:36 +00:00
Anna Buianova
78c6d5d9a0
Create/update pages via api with body_html (#20390) 2023-11-29 18:43:55 +00:00
Ben Halpern
347fd6d112
Recommended articles list (#20383)
* Add recommended articles list

* Adjust tests

* Adjust tests
2023-11-24 17:57:55 +00:00
Ben Halpern
eccd5fd9e3
Add custom_display_label to billboards and update API (#20355)
* Add a/b test for which comments to show in feed

* Adjust figure

* Started at

* Add custom_display_label to billboards and update API

* Add custom_display_label to billboards and update API
2023-11-15 09:57:39 -05:00
Joshua Wehner
2c138d86ef
Add or remove limited role via API (#20136)
* Refactor API user suspend, make room for more roles

* Handle adding limited

* Handle remove limited

* And swagger docs

* Update & refactor roles spec

* Remove old route

* Remove old specs
2023-09-26 09:57:14 -04:00
Ben Halpern
22f836edc2
Add priority weight to billboards (#20019)
* Add priority weight to billboards

* Rewrite query as activerecord

* Change naming from priority_weight to just weight
2023-09-05 16:04:18 -04:00
Anna Buianova
2d6b740940
Renamed DisplayAd model to Billboard (#19993)
* Renamed Resource Admin: DisplayAd to Billboard

* Renamed DisplayAd to Billboard

* Added a data update script for roles
2023-08-28 08:09:36 -04:00
PJ
9725160709
Update billboard API to support target geolocations (#19857)
* update params to permit target_geolocations

* API docs

* fix param and JSON schema issues

* update docs again
2023-08-10 19:11:30 +01:00
Anna Buianova
058fd17b58
Renamed display_ad variables to billboard (#19851)
* Renamed display ad variables and constants

* Renamed display_ads associations

* Fixed variable name in display ads

* Renamed display_ads variables in views

* Fixed admin billboard view spec

* Fixed variable name in FilteredAdsQuery
2023-07-31 17:19:02 +03:00
Duke Greene
9a6f04bd37
api v1 endpoint for creating an organization (#19778)
* api v1 endpoint for creating an organization

* address failing specs, regenerate swagger docs

* remove old comment in destroy now that woreker call takes third argument

* refactor our services for profile images into images folder
2023-07-21 07:43:56 -04:00
Duke Greene
dd7e34ac53
define api v1 routes for organizations (#19681)
* define api routes and create controllers, sketch out index and create actions

* add api v1 organizations CRUD spec and docs spec, need to run swagger

* swagger dry run on admin organizations routes, typo fix in api.rb

* flesh out specs and sketch out admin actions

* move actions out of concerns/include pattern and into v1 inline

* remove private constant call

* add v1 accept header to doc spec, fix syntax in a before block

* update controllers to address failing specs

* simplify controller and clarify route config

* flesh out tests for errors

* fix long line

* add missing commas

* return username show route to v0 concern controller

* create separate show route and action name, remove nesting from create/update params requirement

* clean up syntax in controller params and update show path in specs; move routes

* fix up syntax in params permit

* create organization in index spec

* one more syntax tweak for org params

* refactoring to one show route that handles username or id

* tweak spec syntax to expect the right array

* tweak controller and specs, simplify routing to show

* remove create route, action, and specs from this branch

* add clarifying comment in show controller action

* add explicit not found return to show route

* fix controller formatting causing 404 errors

* remove comment, update specs

* remove commment and fix id show response and specs

* fix show route and request spec for username param

* update unauthorized user specs to use put for now instead of post, regenerate swagger docs

* adjust update 422 spec to break org validity

* fix admin update spec, rerun swagger

* reorganiza controller actions, update specs, ensure authorized update and delete

* improve spec, handle finding one org more gracefully, delete via worker

* copy routes into api namespace instead of moving them from general namespace

* update param in v0 show route to fit more general naming

* regenerate v1 swagger docs

* use profile image url getter in update controller response

* update swagger docs and remove unneeded comment from org' model

* configure organizations destroy action for super admins only (for now)
2023-07-19 09:51:05 -04:00
Anna Buianova
ef5d126a0f
Rename display_ads API to billboards (#19749) 2023-07-14 14:22:52 -04:00
Ben Halpern
5d6dc64245
Add ability to mark billboard (display_ad) as "priority" (boolean) (#19599)
* Add ability to mark billboard (display_ad) as "priority" (boolean)

* Fix invocation

* Update spec/models/display_ad_spec.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update spec/models/display_ad_spec.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update spec/models/display_ad_spec.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update spec/models/display_ad_spec.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-06-12 16:28:15 -04:00
Joshua Wehner
abcd4ac3c8
Add ability to assign arbitrary segment ID to /display_ads API (#19529)
* DisplayAd audience_segment_id in API

* Rubocop

* Manual not valid if missing id

* manual-type requires an id

* Better audience_segment_type reader

* Use inclusion validation

* Swagger update

* Remove unnecessary
2023-05-31 18:11:35 +02:00
PJ
453c2eeccb
Manual Audience Segments API read endpoints (#19542)
* getting and listing segments

* get list of users in segment

* docs???
2023-05-26 15:10:26 +01:00
PJ
795cfc3da0
Manual Audience Segments API write endpoints (#19476)
* add composite index to segmented_users table

* bulk queries for segmented users

* create segment endpoint

* adding and removing users

* deleting segments 😪

* fix time precision in specs

* api docs 🎉

* pluck improvements that couldn't be cherry-picked

* better service objects; also introduce batch upserting

* docs???
2023-05-25 20:37:18 +01:00
Joshua Wehner
dc1ab81401
Allow DisplayAd to target users via audience segmentation (#19284)
* Trying some models for audience segmentation

* AudienceSegment basics

* Attach AudienceSegment to DisplayAd

* Possibly use a DUS to populate AudienceSegments

* Add to display ad form UI

* Add to display ad API

* Refresh strategy for audience segments

* Add user_id to async ads query

* Maybe :testing -> :manual, for no-refresh segment

* Test & tweak segment refresh

* Testing audience_segment#refresh logic

* Coverage: testing human_readable

* Scope segment refresh to recently active users

* Tweak logic for when to refresh

* Tweak experience levels to match SettingsHelper

* Test for front-end logic

* Fix test, hope this helps coverage?

* Better test names

* One worker for all, many workers for each, perform_bulk

* Fix audience segment UI, needs to use id, not enum

* cron/schedule should RefreshAll

* Singular id in RefreshWorker
2023-04-25 08:41:10 -04:00
Joshua Wehner
d3f8e127fa
Add an article exclusion list to Billboards (#19280)
* Add exclude_article_ids int array

* Add specs, normalize inputs better

* Add to form & controller

* Add exclude_article_ids to DisplayAd API

* Use exclude_article_ids in query

* Rubocop

* Comment typo

* Tweak rspec example length config

* Arguments all the way down

* Typo

* Update spec/requests/api/v1/docs/display_ads_spec.rb

Co-authored-by: Ben Halpern <bendhalpern@gmail.com>

* Update spec/requests/api/v1/docs/display_ads_spec.rb

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

* Swagger schema for Display Ad

---------

Co-authored-by: Ben Halpern <bendhalpern@gmail.com>
Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
2023-04-05 09:10:22 -04:00
Joshua Wehner
c251f4000d
Add creator to DisplayAd (#19126) 2023-02-22 14:17:22 -05:00
Anna Buianova
efe540dfce
Billboards type_of: added field to the API and small admin form changes (#19125)
Co-authored-by: Joshua Wehner <joshua.wehner@gmail.com>
Co-authored-by: Mac Siri <mac@forem.com>
2023-02-21 14:17:40 -05:00
Joshua Wehner
fd7021b001
Pages API: create, update, and delete (#19009)
* Pages API pt 1 (read/get/index+show)

* Update spec/requests/api/v1/docs/pages_spec.rb

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

* Update spec/requests/api/v1/docs/pages_spec.rb

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

* API Key not required for index & show

* API Feature flag has long since been removed

* Page schema

* Fix spec broken by merge

* Temporary bugfix: slug uniqueness not working for Page

* Pages API endpoints for create, update, and destroy

* Fix swagger error

---------

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
2023-02-02 17:24:11 +01:00
Joshua Wehner
7f41dae631
Pages API: Read (get index+show) (#18970)
* Pages API pt 1 (read/get/index+show)

* Update spec/requests/api/v1/docs/pages_spec.rb

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

* Update spec/requests/api/v1/docs/pages_spec.rb

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

* API Key not required for index & show

* API Feature flag has long since been removed

* Page schema

* Fix spec broken by merge

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
2023-01-25 17:15:27 +01:00
Joshua Wehner
0e25b1413e
Update DisplayAd API to allow setting tag_list (#18891) 2023-01-04 13:59:20 +01:00
Joshua Wehner
a06ab31416
DisplayAd API: Write endpoints (#18736)
* Try a create endpoint

* Try an update endpoint for display_ads

* Try a delete endpoint for display_ads (unpublish)

* Unpublish

* Permit tags as well

* Update docs for DisplayAd tags via API/swagger
2022-12-05 11:12:24 +01:00
Joshua Wehner
7c82d128ff
DisplayAd API: Read endpoints (#18726)
* DisplayAd API: Read endpoints

* Updated swagger docs for display_ads read endpoints

* Update swagger with type_of

* Remove extraneous comment

* Restrict authentication to strictly api_key
2022-11-21 09:31:01 +01:00
Joshua Wehner
892ad01264
Restrict Reactions API to admins (#18424)
* Restrict Reactions API to admins

* Also update API docs spec

* Removed unneeded pundit_user
2022-09-08 17:56:42 +02:00
Joshua Wehner
2ff67bda24
Try an idempotentish reaction create API (#18377)
* Try an idempotentish reaction create API

* Add tests for create API endpoint

* Try -> ReactionHandler

* Fix existing tests first

* Tests for .toggle; fix broken handle_existing

* Use the Handler

* Tweak http status for reaction create

* Use the category reader

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
2022-08-30 16:43:18 +02:00
Joshua Wehner
b6efce21fe
API for Reactions: Create endpoint (#18355)
* Extract reaction create from controller to service

* Success is having no errors

* Confirm http status successful

* V1 API endpoint for Create Reaction

* Actually reset cache count

* Tweak JSON response

* Reaction create -> toggle

* Try rswagger docs for reaction toggle
2022-08-24 17:02:34 +02:00
Fernando Valverde
808149a424
Remove api_v1 feature flag (#18213) 2022-08-23 16:00:08 -04:00
Fernando Valverde
2ad02cf31c
API v1 without api key restriction (#18340)
* Remove :api_v1 feature flag

* Reworking the auth configs throughout V1 + specs

* Fix remaining v1 specs

* Enhanced inline docs

* deprecation warning update

* Use headers variable for most v1 specs

* Cherry pick spec changes

* Fix specs

* group let! statements - rubocop

* Bring back ||= on api v1 authentication methods

* Bump swagger/v1/api_v1.json
2022-08-19 14:04:41 -06:00
Fernando Valverde
0d942e6161
API V1 skip authenticity token validation (#18142)
* Skip authenticity token on API V1

* Test execution experiment - should fail

* Fix specs test

* Remove listings v1 controller before_action hook
2022-07-20 07:51:33 -06:00
Josh Puetz
6f135a46b1
Add 299 warning messages for V0 api requests when v1 is enabled (#18092) 2022-07-14 14:28:52 -05:00
Fernando Valverde
b8abbda72e
Unpublish post service class + V1 API endpoint (#18031)
* Unpublish post service + API

* Apply PR feedback

* Use module_function on service class
2022-07-08 09:08:55 -06:00
Fernando Valverde
8c836430ca
API V1 transition (#17835)
* API Articles v0-v1 restructure

* Remove unused helper

* Bulk move API controllers into concerns + add V1 controllers

* Extract API routes + some fixes

* Fix v1 api_controller authenticate! + add more article_controller specs

* Completed spec/requests/api/v1/articles_spec.rb

* specs up to listings

* All v1 specs except for 9 skips

* mime_types cleanup + authenticate! relocation

Co-authored-by: Fernando Valverde <fernando@visualcosita.com>
2022-06-23 14:26:00 -06:00
Mac Siri
678dda8cf4
Routine Rubopcop lint fixes (#17844)
* Routine Rubopcop lint fixes

* Undo app_secrets_spec changes

* Fix broken spec
2022-06-07 10:17:16 -04:00
Jeremy Friesen
faaf2ec028
Favoring explicit declaration over inferrence (#17089)
This commit does three things:

1. Documents a method
3. Implies the question: "Do we want to use class_attribute in Forem's codebase?"
2. Switches from an inferrence to an explicit (and configurable)

In my experience, I want to favor "explicit" declarations instead of
inferring what they should be.  In this case, the inferrence is perhaps
adequate.  But as I look to `ApplicationController::PUBLIC_CONTROLLERS`,
I think that is a prime case for a `class_attribute`.  (The `api_action`
happened to be the lowest hanging fruit to begin the conversation.)

We still need some clarity into the `verify_private_forem` method as it
looks like it's doing a few different things.

There is precedence for using `class_attribute` found in
[`UniqueCrossModelSlugValidator.model_and_attribute_name_for_uniqueness_test`][1] (also
introduced by me).

[1]:https://github.com/forem/forem/blob/main/app/validators/unique_cross_model_slug_validator.rb
2022-04-06 10:42:08 -04:00
Jeremy Friesen
378aebce65
Removing yard doc generation warnings (#17090) 2022-04-04 15:03:22 -04:00
Daniel Uber
6c319b8eb7
Prefer "listing" to "classified_listing" in the api (#17021)
This aligns our behavior with some of the documentation examples,
while permitting the original name (don't break the api).

Fixes #16927
2022-03-28 13:40:00 -05:00
Jeremy Friesen
4509e81dd5
Ensuring the same policies for analytics (#16997)
Prior to this commit the following situation existed:

> The path /dashboard/analytics/org/:id requires user
> authentication (e.g. signed in). However, it does not enforce
> authorization. Anyone can see this page. The page, however, uses
> javascript to populate the data. So no information, aside from the org
> name associated with the :id leaks out. The javascript API end point
> enforces organization membership.
>
> I would expect that the authorization in the HTML rendering would be
> the same as the javascript API end point.

This commit ensures that the dashboards#analytics end point uses the
same policy logic as the API analytics end points.  Further, it keeps
folks who aren't org members out of the base HTML page for other orgs.

Closes forem/forem/#16985
2022-03-25 14:57:01 -04:00
Jeremy Friesen
e6b26c7ed4
Favoring re-use of authorization error (#16992)
We only have one reference to the UnauthorizedError, which is shadows
the ApplicationPolicy::NotAuthorizedError.  This commit removes the
exception.

Related to forem/forem#16985 but only barely
2022-03-24 08:16:28 -04:00
Jeremy Friesen
acd5b175ed
Ensuring POST api/v0/articles authorizes by policy (#16685)
As part of the [Authorization System Use Case
1:1](https://github.com/orgs/forem/projects/46) project, we are driving
towards the feature of: "Only admin's may post articles in this Forem."

This commit ensures that the API's "create an article" end-point
delivers on that feature.

Along the way, I've added reading notes and comments, to help us further
flex in the future (namely move all authorization checks into a policy
object).

Closes forem/forem#16488
2022-02-28 08:50:33 -05:00
Dwight Scott
ab224d34b2
Add ability to bulk search tags by name or id (#16671)
* Trigger Build

* Remove cache header before_action and add ability to search by tag name

* Remove cache header before_action and add ability to search by tag name

* Add internal bulk tag endpoint to get tags by array of  names or ids

* Restore V0 tags controller
2022-02-24 12:34:50 -05:00
Jeremy Friesen
e0e4003671
Removing somewhat duplicated logic (#16684)
In conversations with citizen428, this method looked to be a holdover
from a past approach.  Reviewing the code, we can get the same behavior
with other methods.

Further, I added some comments for future considerations, and refactored
for more readily scannable guard clauses.

Related to forem/forem#16488, forem/forem#16681, and forem/forem#6255
2022-02-24 12:16:48 -05:00
Jeremy Friesen
8ec81e80e9
Removing duplicate logic and adding docs (#16681)
As I was investigating an approach for #16488, I stumbled upon two
methods partially doing the same thing.  This helps consolidate the
logic and provides some guiding documentation.
2022-02-23 15:22:35 -05:00