Skip to content

Commit

Permalink
Merge branch 'main' into google-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
jywarren authored Jul 13, 2021
2 parents cfb3c4d + 19184a6 commit 098e6e3
Show file tree
Hide file tree
Showing 60 changed files with 755 additions and 324 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ jobs:
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
bundle exec rails test:system
- name: Archive system test screenshots
uses: actions/upload-artifact@v2
with:
name: system-test-screenshots
path: tmp/screenshots/*

remove-labels:
runs-on: ubuntu-latest
Expand All @@ -136,10 +141,10 @@ jobs:
- uses: buildsville/add-remove-label@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
label: Work In Progress
label: work-in-progress
type: remove
- uses: buildsville/add-remove-label@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
label: ready-for-review
type: add
type: add
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ yarn-error.log
/yarn-error.log
yarn-debug.log*
.yarn-integrity
.rake_tasks~
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ gem "i18n-js", ">= 3.0.0.rc11"
gem 'impressionist'
gem 'jbuilder', '~> 2.11'
gem 'jquery-rails'
gem 'mocha', '~> 1.12'
gem 'mocha', '~> 1.13'
gem 'mimemagic', '~> 0.3.10'
gem 'mustermann' , '1.1.1'
gem 'omniauth', '~> 1.9'
Expand All @@ -53,7 +53,7 @@ gem 'rdiscount', '~> 2.2'
gem 'react-rails'
gem "recaptcha", require: "recaptcha/rails"
gem 'responders', '~> 3.0'
gem 'rubocop', '~> 1.17.0', require: false
gem 'rubocop', '~> 1.18.3', require: false
gem "ruby-openid", :require => "openid"
gem 'sanitize'
gem 'sentry-raven'
Expand Down
39 changes: 21 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ansi (1.5.0)
arel (9.0.0)
Expand Down Expand Up @@ -133,19 +133,23 @@ GEM
erubi (1.10.0)
excon (0.83.0)
execjs (2.7.0)
faraday (1.4.2)
faraday (1.5.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0.1)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
faraday-patron (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.1.0)
faraday-patron (1.0.0)
ffi (1.15.0)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
Expand Down Expand Up @@ -190,33 +194,32 @@ GEM
retriable (>= 2.0, < 4.0)
rexml
signet (~> 0.12)
google-apis-core (0.3.0)
google-apis-core (0.4.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 0.14)
httpclient (>= 2.8.1, < 3.0)
googleauth (>= 0.16.2, < 2.a)
httpclient (>= 2.8.1, < 3.a)
mini_mime (~> 1.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.0)
retriable (>= 2.0, < 4.a)
rexml
signet (~> 0.14)
webrick
google-apis-iamcredentials_v1 (0.4.0)
google-apis-core (~> 0.1)
google-apis-storage_v1 (0.4.0)
google-apis-core (~> 0.1)
google-apis-iamcredentials_v1 (0.6.0)
google-apis-core (>= 0.4, < 2.a)
google-apis-storage_v1 (0.6.0)
google-apis-core (>= 0.4, < 2.a)
google-cloud-core (1.6.0)
google-cloud-env (~> 1.0)
google-cloud-errors (~> 1.0)
google-cloud-env (1.5.0)
faraday (>= 0.17.3, < 2.0)
google-cloud-errors (1.1.0)
google-cloud-storage (1.31.1)
google-cloud-storage (1.34.1)
addressable (~> 2.5)
digest-crc (~> 0.4)
google-apis-iamcredentials_v1 (~> 0.1)
google-apis-storage_v1 (~> 0.1)
google-cloud-core (~> 1.2)
googleauth (~> 0.9)
google-cloud-core (~> 1.6)
googleauth (>= 0.16.2, < 2.a)
mini_mime (~> 1.0)
googleauth (0.16.2)
faraday (>= 0.17.3, < 2.0)
Expand Down Expand Up @@ -330,7 +333,7 @@ GEM
builder
minitest (>= 5.0)
ruby-progressbar
mocha (1.12.0)
mocha (1.13.0)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
Expand Down Expand Up @@ -500,7 +503,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.0)
rubocop (1.17.0)
rubocop (1.18.3)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
Expand Down Expand Up @@ -677,7 +680,7 @@ DEPENDENCIES
mailman
mimemagic (~> 0.3.10)
minitest-reporters (~> 1.4.3)
mocha (~> 1.12)
mocha (~> 1.13)
mustermann (= 1.1.1)
mysql2 (>= 0.4.4)
nifty-generators
Expand Down Expand Up @@ -712,7 +715,7 @@ DEPENDENCIES
rest-client
reverse_markdown
rspec
rubocop (~> 1.17.0)
rubocop (~> 1.18.3)
ruby-openid
sanitize
sassc (~> 2.4.0)
Expand Down
56 changes: 54 additions & 2 deletions app/assets/javascripts/atWhoAutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,62 @@

// settings at https://github.com/ichord/At.js/wiki/Base-Document#settings

let userObj = null;

// stores recently active users in userObj
(function storeRecentlyActiveUsers() {
fetch('/users/active').then(res => res.json()).then(data => { userObj = data })
})();

// checks if the 'name' key in the JSON data is named 'username' or 'name' and then returns the
// correct key-value
const displayName = (item) => item.username ? item.username : item.name;

// displays a recently active text for prioritised users
const displayPriorityUsers = item => {
const username = displayName(item);
if(item.priority) {
return username + ' <small>recently active</small>'
}
return username
}

// returns a list of users that match the query
const filterUsers = query => {
const users = []
userObj.forEach(str => {
if(str.username.includes(query)){
users.push(str.username)
}
});

return users
};

// remove duplicates of prioritised usernames
const removeDuplicates = (userArr, prioritisedUsers) => {
const newData = []
userArr.forEach(i => {
if(!prioritisedUsers.includes(i.doc_title)){
newData.push({name: i.doc_title, priority: false})
}
});

return newData;
}

// merges normal and prioritised usernames
const mergeUsers = (recentlyActiveUsers, normalUsers) => {
const prioritisedUsers = recentlyActiveUsers.map(user => {
return { name: user, priority: true }
})

return prioritisedUsers.concat(normalUsers);
}

var at_config = {
at: "@",
displayTpl: (item) => `<li>${displayName(item)}</li>`,
displayTpl: (item) => `<li>${displayPriorityUsers(item)}</li>`,
insertTpl: (item) => `@${displayName(item)}`,
// loads and saves remote JSON data by URL
data: '/users/active',
Expand All @@ -17,7 +66,10 @@
remoteFilter: debounce(function(query, callback) {
$.getJSON("/api/srch/profiles?query=" + query + "&sort_by=recent&field=username", {}, function(data) {
if (data.hasOwnProperty('items') && data.items.length > 0) {
callback(data.items.map(function(i) { return i.doc_title }));
const prioritisedUsers = filterUsers(query);
const normalUsers = removeDuplicates(data.items, prioritisedUsers);
const mergedUsers = mergeUsers(prioritisedUsers, normalUsers);
callback(mergedUsers);
}
});
}, 200)
Expand Down
5 changes: 5 additions & 0 deletions app/assets/javascripts/translation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(document).ready(function () {
$('.translationIcon').filter(function(i) {
return (i + 1) % 3 === 0
}).show();
});
4 changes: 4 additions & 0 deletions app/assets/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ a .fa-white,
line-height: 2em;
}

.footer a {
color: #007bff !important;
}

.caption {
padding:12px;
font-size:10px;
Expand Down
3 changes: 1 addition & 2 deletions app/channels/room_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def unsubscribed
end

def speak(message)
return unless current_user && current_user.admin?

return unless current_user&.admin?
ActionCable.server.broadcast 'room_channel', message: message["message"]
end
end
11 changes: 11 additions & 0 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,17 @@ def publish_draft
end
end

def drafts
@user = User.find_by(name: params[:id])
if current_user&.can_moderate? || current_user == @user
@pagy, @drafts = pagy(@user.drafts, items: 24)
render template: 'notes/drafts'
else
flash[:warning] = "This page is only visible to the author and moderators."
redirect_to '/'
end
end

private

def set_node
Expand Down
11 changes: 5 additions & 6 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ class StatsController < ApplicationController
before_action :require_user, only: %i(index range notes wikis users questions comments tags)

def subscriptions
@tags = Rails.cache.fetch("stats-subscriptions-query", expires_in: 24.hours) do
TagSelection
.select("DISTINCT tag_selections.tid, tag_selections.user_id")
.where(following: true)
.joins("INNER JOIN community_tags ON community_tags.tid = tag_selections.tid")
.joins("INNER JOIN term_data ON term_data.tid = community_tags.tid")
@tags = Rails.cache.fetch("subscriptions-stats-query", expires_in: 24.hours) do
Tag
.joins("INNER JOIN tag_selections ON term_data.tid = tag_selections.tid")
.select("term_data.name")
.where(tag_selections: { following: true })
.group("term_data.name")
.joins("INNER JOIN rusers ON rusers.id = tag_selections.user_id")
.where("rusers.status = 1 OR rusers.status = 4")
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ def create
def delete
node_tag = NodeTag.where(nid: params[:nid], tid: params[:tid]).first
node = Node.where(nid: params[:nid]).first
# only admins, mods, and tag authors can delete other peoples' tags
if node_tag.uid == current_user.uid || logged_in_as(['admin', 'moderator']) || (node.uid == current_user.uid && node_tag.name != "locked")
# only admins, mods can delete other peoples' tags if the note/wiki contains the locked tag
if (node_tag.uid == current_user.uid && !node.has_tag('locked')) || logged_in_as(['admin', 'moderator']) || (node.uid == current_user.uid && !node.has_tag('locked'))

tag = Tag.joins(:node_tag)
.select('term_data.name')
Expand All @@ -385,8 +385,8 @@ def delete
end
end
end
elsif node_tag.name == "locked"
flash[:error] = "Only admins can delete the locked tag."
elsif node.has_tag('locked')
flash[:error] = "Only admins can delete tags on locked pages."
redirect_to Node.find_by(nid: params[:nid]).path
else
flash[:error] = I18n.t('tag_controller.must_own_tag_to_delete')
Expand Down
13 changes: 11 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,20 @@ def translation(key, options = {}, html = true)
translated_string2 = t(key, options)

if html && current_user&.has_tag('translation-helper') && translated_string2.include?("translation missing") && !translated_string.include?("<")
raw(%(<span>#{translated_string} <a href="https://www.transifex.com/publiclab/publiclaborg/translate/#de/$?q=text%3A#{translated_string}">
<i data-toggle='tooltip' data-placement='top' title='Needs translation? Click to help translate this text.' style='position:relative; right:2px; color:#bbb; font-size: 15px;' class='fa fa-globe'></i></a>
raw(%(<span>#{translated_string} <a class="translationIcon" style='display: none; padding-left: 3px;' href="https://www.transifex.com/publiclab/publiclaborg/translate/#de/$?q=text%3A#{translated_string}">
<i data-toggle='tooltip' data-placement='top' title='Needs translation? Click to help translate the text \" #{translated_string} \" .' style='position:relative; right:2px; color:#bbb; font-size: 15px;' class='fa fa-globe'></i></a>
</span>))
else
raw(translated_string)
end
end

def create_nav_dropdown_item(href, text)
translated_string = translation(text)
if current_user&.has_tag('translation-helper') && I18n.locale != :en
raw(%(<div class="dropdown-item"> <a class="text-body" href="/#{href}"> #{translated_string}</a> </div>))
else
raw(%(<a class="dropdown-item" href="/#{href}"> #{translated_string} </a>))
end
end
end
6 changes: 3 additions & 3 deletions app/javascript/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from "prop-types";

import { UserContext } from "./user-context";
import { StaticPropsContext } from "./static-props-context";
import { getEditTextAreaValues, getInitialCommentFormToggleState } from "./helpers";
import { getEditTextAreaValues, getInitialCommentFormsVisibility } from "./helpers";

import CommentsContainer from "./CommentsContainer";

Expand All @@ -23,7 +23,7 @@ const App = ({
// this is an object containing boolean values like: { "reply-33": false, "edit-1": true }
// this is used as the initial state showing whether or not an edit or reply comment form is shown or hidden
// false means the comment form is closed, true means open
const initialCommentFormToggleState = getInitialCommentFormToggleState(initialComments);
const initialCommentFormsVisibility = getInitialCommentFormsVisibility(initialComments);

// this is used as initial state for the content of <textarea>s inside comment forms
// main and reply comment forms are an empty string
Expand All @@ -41,7 +41,7 @@ const App = ({
<UserContext.Provider value={currentUser}>
<StaticPropsContext.Provider value={{ node, elementText }}>
<CommentsContainer
initialCommentFormToggleState={initialCommentFormToggleState}
initialCommentFormsVisibility={initialCommentFormsVisibility}
initialComments={initialComments}
initialTextAreaValues={initialTextAreaValues}
nodeId={nodeId}
Expand Down
Loading

0 comments on commit 098e6e3

Please sign in to comment.