Project.with_feature_available_for_user does not include disabled project features
Summary
From Project.with_feature_available_for_user:
def self.with_feature_available_for_user(feature, user)
visible = [nil, ProjectFeature::ENABLED]
# (...)
with_project_feature
.where("#{column} IN (?) OR (#{column} = ? AND EXISTS (?))",
visible,
ProjectFeature::PRIVATE,
authorized)
# (...)
end
Presumably, the intention is to select all project features with their corresponding column set to null or ProjectFeature::ENABLED.
The current behavior translates to column IN (NULL, 20). This never includes rows with a NULL value for column because NULL IN (NULL) is false.
To fix this we can make the clause more explicit like so:
#{column} IS NULL OR #{column} = #{ProjectFeature::ENABLED} OR ...
On the other hand, we might consider replacing NULL values with 0 to avoid this pitfall at all. This also helps when creating indexes for those columns.