Commit graph

242 commits

Author SHA1 Message Date
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
Michael Kohl
b07ea0a87e
More listings refactoring (#16343) 2022-02-23 13:44:30 +07:00
Suzanne Aitchison
b358c3810c
Revert "Only make one network call to fetch all existing tags in editor (#16610)" (#16641)
This reverts commit c76909a428.
2022-02-18 11:54:38 +00:00
Suzanne Aitchison
c76909a428
Only make one network call to fetch all existing tags in editor (#16610)
* use bulk get of tags in editor

* prefer tag_ids if both tag_ids and tag_names are present
2022-02-17 14:57:40 +00:00
Jeremy Friesen
663a712a10
Removing deprecation warning (#16572)
Prior to this commit, I saw the following in the Rails test log:

```
DEPRECATION WARNING: 'include Pundit' is deprecated. Please use 'include Pundit::Authorization' instead.
 (called from include at ./app/controllers/application_controller.rb:12)
 ```
2022-02-15 05:02:47 -05:00
Michael Kohl
d5ecf61ee4
Admin API use case 1: endpoint to create users (#16520) 2022-02-15 09:30:00 +07:00
Dwight Scott
509e7d0e78
Modify tags api index to allow for bulk GET of tags (#16417) 2022-02-09 15:30:15 -05:00
Alex
f071903176
Remove counts from instance API (#16479) 2022-02-09 11:07:44 -05:00
Michael Kohl
a1eb6358db
Easier feature flag handling for Cypress (#16379)
* Add RailsEnvConstraint for routes

* Add feature flags API

* Add Cypress commands

* Add show action, update commands, add e2e test

* Update cypress/integration/seededFlows/toggleFeatureFlags.spec.js

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Move helper from command to test file

* Update documentation

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
2022-02-03 10:42:13 -05:00
yheuhtozr
b120f3a241
app/controllers/api i18n (#16002) 2022-01-11 10:05:54 +07:00
Michael Kohl
06d6b68d9d
Remove webhooks and related code (#15827) 2021-12-28 10:56:37 +07:00
Jeremy Friesen
a40efc6bbd
Refactoring questions asked of user (#15762)
* Refactoring questions asked of user

In this pull request, I'm extracting and normalizing role-based
questions asked of the user.

Prior to this commit, our codebase has asked two very similar questions
of our user model:

- `user.has_role?(:admin)`
- `user.admin?`

In asking `has_role?(:admin)` we are relying on implementation details
of the rolify gem.  In addition, the `has_role?` question asked
throughout controllers or views means that it's harder to create
hieararchies of permissions.

In favoring `user.admin?` as our question, we can use that indirection
as an opportunity to discuss and decide "Should someone with the
`:super_admin` role be `user.admin? == true`?"

The details of this commit is to do three primary things:

1. Ask the `has_role?` questions in "one place" in the code (e.g. the
   `Authorizer` module)
2. Extract the role based questions that are on the `User` model and
   provde backwards compatable delegation.
3. Structure the code so that it's harder to accidentally call
   `user.has_role?` (e.g., make `User#has_role?` and `User#has_any_role?`
   private).

This is related to #15624 and the updates are informed by discussion in
PR #15691.  This commit supplants #15691.

* Refactoring the liquid tag policy tests

* Fixing typo

* Bump for travis
2021-12-21 12:45:12 -05:00
Alex
51f2bf7aab
Add article and comment count to instance API (#15794) 2021-12-16 13:05:49 -05:00
Michael Kohl
b22ad4c976
Remove Doorkeeper from API (#15750)
Co-authored-by: Dan Uber <dan@forem.com>
2021-12-16 09:57:26 -06:00
Alex
eed3c12f4d
Auto register Forems on Discover (#14962) 2021-10-06 10:51:15 -04:00
Jamie Gaskins
3801789e8f
Add real release version into the running code (#14870)
* Add real release version into the running code

* Fix warnings
2021-10-04 09:35:20 -04:00
Alex
a024efcc45
Add display_in_directory setting (#14733)
* Add display_in_directory setting

* Remove setting from constants

* Update spec to use change
2021-09-15 13:34:31 -04:00
Alex
d6a1b16a45
Add context to Instance API (#14731) 2021-09-14 13:09:20 -04:00