No description
Find a file
Daniel Uber 1a07ad8d9e
Profile attribute names should be unique and non-empty (#16396)
* transliterate when generating attribute names to avoid emptiness

If you enter a non-ascii (non `\w` matching) string as the profile
field label, the attribute name is the empty string.

This causes problems outlined in #16391

To avoid losing user provided data, transliterate (Sterile is the same
tool we're using for Article#title_to_slug) before matching against
the word regex.

If we persist an empty string, or persist a non-`\w` name, the
coordinating regex in Profile::ATTRIBUTE_NAME_REGEX will leave a nil
match and raise NoMethodError (the method missing is for
match[:attribute_name] when match was nil, not Profile - that's the
next commit.

* Guard against nil matches

If an attribute name doesn't match the regex, the match is nil, and
trying to access (nil)[:attribute_name] raises a NoMethodError.

If there was no match, assume profile does not respond to the
selector, and don't handle it in method missing.

* Ensure generated attribute name is valid before saving

This raises a validation error if the generated name (from the label)
would be empty.

It's not an optimal error message (since the user can't see the
internal attribute name) but it prevents persisting broken/empty data

* actually raise error when validating

validate/valid? only return true or false (and set errors on the
object). In order to reject the creation, we need to raise a
validation error, not only call validate. I think this is because the
execution of before_create hooks happens after validation (which is
why the validation was only checked on update, not create).

* Generate an attribute name completely independent of the field label

This prevents mistakenly labeling a field "Class" or "Association" or
one of the other hundred public methods an AR model like Profile
exposes. Since attribute_name will be passed to `profile.public_send`
we really shouldn't build selectors from user supplied inputs.

* Use the admin supplied label in the sidebar

The profile decorator is used in the Users#show page to populate the
sidebar fields. Don't use the attribute name (which we mangled during
creation, and now generate randomly) as the label, use the label.

* Make the label lookup null safe, and filter attributes more

* Update data update script to not expect predictable labels

This is low impact since it ran in july, but we no longer know what
attribute name a label will create.

* Fix moderator spec

"Test Field" label no longer predictably generates :test_field as an
attribute name. Ask the field what it's name is before asking profile
about it.

* Fix profile preview card request spec

Remove the assumption that profile responds to a method name based on
the label for Work and Education fields.

* Update old DUS and its test

This can probably be archived

* Update profile spec to use fields generated attribute names

We used to "know" how attributes were generated from labels. Now we don't.

* update e2e seeds for profile field change

* Don't expect attribute name to be based on the label

* expect created profile fields respond to their attribute name

* Update system test

The label, not the attribute name, is shown on the profile form (the
field has an id related to the attribute name, but the view shows the
mutable/human-readable label).

* Keep the field title lowercase when sending the json preview card

The userMetadata component expects "work" and "education" to be
attributes of the metadata, but the ui_attributes_for() method was
titlizing these (for display).

Ideally we wouldn't have "special purposed" these two field names, but
they're there.

* update profile field by attribute name, not based on label

* Update profile field removal assumptions

We don't know what the method selectors will be, we have to ask.

* remove old test

* Update translations for Education and Work

Since the ui_attributes_for(area:) now gives the label, not the
attribute, we need to match the label of the profile field.

Note to self: this exposes an issue in localizing the custom profile
fields (probably a bigger problem for large, international communities
like DEV than some others, but trying to match static translation
files against user-modifiable database records seems like a problem
we'll see again).

* Empty commit to retrigger buildkite

* Remove profile field migration update scripts

Cloned the specs from the other "remove unused scripts" script.

* Remove unused scripts

The data update script removes the entry from the table (recording
that these have run) - we also want to remove the files (preventing
them from running again).

* remove unneeded spec for removed file

* when translation for header area field not found, use the title

Only Work and Education already have keys in the yml translation file,
and there's not a great (or easy?) way to make multiple translations
on these fields right now.

Since an admin can create a new field, and assign it to the header
area, we can't assume the code has a configured translation key for
this field.

Fallback to the title (we do this in another context already) if
there's no translation.

* PR feedback: Avoid n+1 query for labels

the original implementation of "label_for_attribute" had an n+1 query
looping over each matched key.

Follow suggested improvement and pull labels and attributes at once
from the db and modify the returned hash.

* Downcase title before looking for translation key

This avoids putting "odd" capitalized keys into the yml translation
file

Revert addition of "Work" and "Education" to the users files.

* use a let binding for duplicated test data

* Update app/models/profile_field.rb

prefer SecureRandom.hex for a dashless uuid (instead of removing the dashes).

Co-authored-by: Jamie Gaskins <jgaskins@hey.com>

Co-authored-by: Jamie Gaskins <jgaskins@hey.com>
2022-04-04 12:14:02 -05:00
.buildkite Removes this dupe container block since we are going to run this pipeline (#11506) 2020-11-19 15:05:49 -06:00
.gems Bugfix for #7663 and refactor of container setup (#7747) 2020-05-28 12:11:51 -05:00
.github Updates the github-actions bot feature request link and team tag (#17044) 2022-03-29 08:38:58 -06:00
.husky [15 min fix] Updated husky package and configuration/pre-commit hook (#14346) 2021-07-27 15:39:00 -04:00
.vscode Added the MDX extension for VS Code. (#12816) 2021-02-25 10:22:18 +01:00
.yarn/releases Update yarn from 1.22.5 to 1.22.18 (#16938) 2022-03-21 10:53:24 -04:00
app Profile attribute names should be unique and non-empty (#16396) 2022-04-04 12:14:02 -05:00
bin Bump to Rails 7.0.2.2 MVP (#15908) 2022-03-30 15:00:33 -04:00
config Ensuring confirmation and flash message for spaces (#17072) 2022-04-04 11:49:15 -04:00
cypress Revert "Added a way to sort comments on an article (#16686)" (#17093) 2022-04-04 08:36:34 -04:00
datadog Declare DD_VERSION in prerun.sh 2nd try (#13258) 2021-04-05 17:10:46 -04:00
db Bump to Rails 7.0.2.2 MVP (#15908) 2022-03-30 15:00:33 -04:00
lib Profile attribute names should be unique and non-empty (#16396) 2022-04-04 12:14:02 -05:00
log Initial commit 2018-02-28 16:11:08 -05:00
public Allow users to pause gifs in a post (#16314) 2022-02-02 13:45:55 +00:00
scripts Don't write a \n at the end of the release version (#15659) 2021-12-03 13:08:27 -05:00
spec Profile attribute names should be unique and non-empty (#16396) 2022-04-04 12:14:02 -05:00
vendor Bump omniauth-google-oauth2 from 1.0.0 to 1.0.1 (#17067) 2022-03-31 16:57:44 -04:00
.codeclimate.yml Upgrade to Ruby 3.0.2 (#12103) 2021-08-25 14:26:33 -04:00
.dockerignore Remove docs from repo ✂✂✂ (#14579) 2021-08-23 17:23:42 -04:00
.editorconfig Export articles/posts (#576) 2018-11-21 11:13:36 -05:00
.env.test symlink .env_sample as .env.test (#16939) 2022-03-22 09:32:50 -05:00
.env_sample Add a safe default value for cloudinary secure (#16989) 2022-03-24 09:29:07 -05:00
.erb-lint.yml Upgrade Rails to 6.1.3.1 (#11333) 2021-04-05 10:39:48 -04:00
.eslintignore Remove non application files from frontend code coverage (#11752) 2020-12-04 20:00:20 -05:00
.eslintrc.js Bump eslint from 7.32.0 to 8.6.0 (#15926) 2022-01-05 13:47:40 -05:00
.gitattributes Configured the repository to handle line endings (#16234) 2022-01-21 08:57:05 -05:00
.gitignore Update .gitignore (#17057) 2022-03-30 13:44:56 -05:00
.gitpod.dockerfile Update to node version 16 (#15522) 2022-01-03 10:23:07 -06:00
.gitpod.yml Add DISABLE_SPRING environment variable to gitpod forem server task (#15807) 2021-12-16 15:24:22 -06:00
.lintstagedrc.js Create .lintstagedrc.js (#15209) 2021-10-27 12:40:59 -04:00
.nvmrc Update to node version 16 (#15522) 2022-01-03 10:23:07 -06:00
.postcssrc.yml Initial commit 2018-02-28 16:11:08 -05:00
.prettierignore Use yarn 1.21.1 (#5786) 2020-02-05 17:04:06 -05:00
.prettierrc.json Extracting prettier config (#10847) 2020-10-14 22:28:31 -04:00
.rspec [deploy] Spec Speedup: Use Knapsack to Run Parallel Builds (#8390) 2020-06-11 10:27:11 -05:00
.rubocop.yml Proposing a new feed experiment (#15789) 2022-01-03 14:38:14 -05:00
.rubocop_todo.yml ✂✂✂ Remove Connect (#14734) 2021-11-18 08:21:00 -06:00
.ruby-version Upgrade to Ruby 3.0.2 (#12103) 2021-08-25 14:26:33 -04:00
.simplecov Move BlackBox to app/lib (#16183) 2022-01-20 09:37:53 +07:00
.slugignore Remove docs from repo ✂✂✂ (#14579) 2021-08-23 17:23:42 -04:00
.solargraph.yml Improving Solargraph options (#16899) 2022-03-17 16:47:55 -04:00
.travis.yml symlink .env_sample as .env.test (#16939) 2022-03-22 09:32:50 -05:00
.yardopts Adds Ruby source code documentation to docs.dev.to (#2656) 2019-05-02 13:50:58 -04:00
.yarnclean Remove assets folder from .yarnclean (#13869) 2021-05-27 10:39:59 -04:00
.yarnrc Update yarn from 1.22.5 to 1.22.18 (#16938) 2022-03-21 10:53:24 -04:00
babel.config.js Now <viewbox /> is preserved in SVGs when using the inline-react-svg plugin (#16287) 2022-01-24 16:25:14 -05:00
CHANGELOG.md Add support for versioned releases (#13750) 2021-07-28 10:10:33 -04:00
CODE_OF_CONDUCT.md Replace ban/banned with suspend/suspended in user facing text (#5816) [deploy] 2020-02-10 10:12:53 -05:00
config.ru Upgrade Rails to 6.1.3.1 (#11333) 2021-04-05 10:39:48 -04:00
container-compose.yml Remove Elasticsearch ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ (#13606) 2021-05-03 11:09:45 -04:00
Containerfile Bump to Rails 7.0.2.2 MVP (#15908) 2022-03-30 15:00:33 -04:00
CONTRIBUTING.md Fix broken links (#14588) 2021-08-24 16:59:56 -04:00
customJsDomEnvironment.js Bump jsdom from 16.7.0 to 18.0.0 (#15047) 2021-10-12 14:32:30 -06:00
cypress.dev.json Cleaning Test Runs for End to End (E2E) Tests (#12143) 2021-01-29 13:34:01 +01:00
cypress.json add retries for cypress ci tests (#14241) 2021-07-15 12:34:30 +01:00
docker-compose.yml Add a minimal test database setup to the docker-compose file (#16305) 2022-01-31 09:22:38 -06:00
Dockerfile Bugfix for #7663 and refactor of container setup (#7747) 2020-05-28 12:11:51 -05:00
empty-module.js Initial commit 2018-02-28 16:11:08 -05:00
Gemfile Bump i18n-js from 3.9.1 to 3.9.2 (#17073) 2022-03-31 13:46:21 -06:00
Gemfile.lock Bump omniauth-google-oauth2 from 1.0.0 to 1.0.1 (#17067) 2022-03-31 16:57:44 -04:00
gitpod-init.sh Made GitHub CLI install permanent in Gitpod (#14787) 2021-09-21 15:27:39 -04:00
Guardfile Remove Spring and spring-commands-rspec gem (#16848) 2022-03-10 10:12:51 -05:00
jest.config.js chore: Increased jest test coverage thresholds (#16871) 2022-03-15 10:22:46 -04:00
jsconfig.json Reworked some webpack aliases as prework for #16174. (#16412) 2022-02-04 06:34:37 -05:00
LICENSE.md Ran all markdown files through prettier to fix a handful. (#4599) 2019-10-28 08:20:53 -04:00
package.json conditionally render create post button for admins #16490 (#16606) 2022-03-29 13:04:57 -04:00
postcss.config.js Suppress Postcss warnings & Re-enable Benhalpern deploy (#11521) 2020-11-20 11:27:49 -05:00
Procfile remove rake jobs:work references from code (#6082) [deploy] 2020-02-14 15:18:08 -05:00
Procfile.dev Adapt dev env to run on a remote box (#8232) 2020-06-18 13:01:49 +02:00
Procfile.dev-hot Initial commit 2018-02-28 16:11:08 -05:00
Rakefile Remove fix-db-schema-conflicts gem (#12432) 2021-01-26 10:52:38 -05:00
README.md Remove myself from the core team (#16967) 2022-03-22 10:49:39 -04:00
release-tasks.sh Remove Elasticsearch ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ (#13606) 2021-05-03 11:09:45 -04:00
SECURITY.md [deploy] 🚀 Feature: Chat channel membership manager component (#8945) 2020-07-20 08:08:31 -04:00
svgo.config.js svgo: update configuration for 2.4 syntax (#14524) 2021-08-17 18:54:10 +02:00
testSetup.js workaround getComputedStyle issues in all jest tests (#14737) 2021-09-21 10:52:54 +01:00
yarn.lock conditionally render create post button for admins #16490 (#16606) 2022-03-29 13:04:57 -04:00


Forem 🌱

For Empowering Community

Build Status GitHub commit activity GitHub issues ready for dev Gitpod badge

Welcome to the Forem codebase, the platform that powers dev.to. We are so excited to have you. With your help, we can build out Forems usability, scalability, and stability to better serve our communities.

What is Forem?

Forem is open source software for building communities. Communities for your peers, customers, fanbases, families, friends, and any other time and space where people need to come together to be part of a collective. See our announcement post for a high-level overview of what Forem is.

dev.to (or just DEV) is hosted by Forem. It is a community of software developers who write articles, take part in discussions, and build their professional profiles. We value supportive and constructive dialogue in the pursuit of great code and career growth for all members. The ecosystem spans from beginner to advanced developers, and all are welcome to find their place within our community. ❤️

Table of Contents

Community

For a place to have open discussions on features, voice your ideas, or get help with general questions please visit our community at forem.dev.

Contributing

We encourage you to contribute to Forem! Please check out the Contributing to Forem guide for guidelines about how to proceed.

Getting Started

This section provides a high-level quick start guide. If you're looking for a more thorough installation guide (for example with macOS, you'll want to refer to our complete Developer Documentation.

We run on a Rails backend, and we are currently transitioning to a Preact-first frontend.

A more complete overview of our stack is available in our docs.

Prerequisites

Local

Containers

Linux

OS X

Installation Documentation

Please see our installation guides, such as the one for macOS.

Developer Documentation

Check out our dedicated docs page for more technical documentation.

Core team

Vulnerability disclosure

Forem is the open source software which powers DEV.

We welcome security research on DEV under the terms of our vulnerability disclosure policy.

Acknowledgments

Thank you to the Twemoji project for the usage of their emojis.

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Please see the LICENSE file in our repository for the full text.

Like many open source projects, we require that contributors provide us with a Contributor License Agreement (CLA). By submitting code to the Forem project, you are granting us a right to use that code under the terms of the CLA.

Our version of the CLA was adapted from the Microsoft Contributor License Agreement, which they generously made available to the public domain under Creative Commons CC0 1.0 Universal.

Any questions, please refer to our license FAQ doc or email yo@dev.to.


Sloan, the sloth mascot
Happy Coding ❤️

⬆ Back to Top