Skip to content

Commit

Permalink
Merge branch 'main' into fix/labels-disappear
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Jan 9, 2024
2 parents 74fc556 + bc3cb94 commit e3a155b
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 180 deletions.
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ gem 'httparty', '~> 0.21.0'
gem 'slack-notifier', '~> 2.4.0'

# css styles for emails
gem 'nokogiri', '~> 1.15.5'
gem 'nokogiri', '~> 1.16.0'
gem 'premailer-rails', '~> 1.12.0'

# filtering
Expand Down Expand Up @@ -144,7 +144,7 @@ group :development, :test do
# Use mocha for stubbing and mocking
gem 'mocha', '~> 2.1.0'
# Factory bot for factories
gem 'factory_bot_rails', '~> 6.4.2'
gem 'factory_bot_rails', '~> 6.4.3'

# test template rendering
gem 'rails-controller-testing', '~> 1.0.5'
Expand Down Expand Up @@ -179,8 +179,8 @@ group :development do
gem 'rb-readline', '~> 0.5.5' # require for irb
gem 'rubocop-capybara', '~> 2.19.0'
gem 'rubocop-factory_bot', '~> 2.24'
gem 'rubocop-minitest', '~> 0.33.0'
gem 'rubocop-rails', '~> 2.22.2'
gem 'rubocop-minitest', '~> 0.34.3'
gem 'rubocop-rails', '~> 2.23.1'

# for opening letters
gem 'letter_opener', '~> 1.8.1'
Expand Down
45 changes: 23 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ GEM
base64 (0.2.0)
bcrypt (3.1.19)
bcrypt_pbkdf (1.1.0)
bigdecimal (3.1.4)
bigdecimal (3.1.5)
bindata (2.4.15)
bindex (0.8.1)
bootsnap (1.17.0)
Expand Down Expand Up @@ -183,9 +183,9 @@ GEM
activesupport (>= 5.2, < 8)
excon (0.100.0)
execjs (2.9.1)
factory_bot (6.4.2)
factory_bot (6.4.5)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.2)
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
faker (3.2.2)
Expand Down Expand Up @@ -224,16 +224,16 @@ GEM
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
io-console (0.6.0)
irb (1.9.1)
io-console (0.7.1)
irb (1.11.0)
rdoc
reline (>= 0.3.8)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jsbundling-rails (1.2.1)
railties (>= 6.0.0)
json (2.6.3)
json (2.7.1)
json-jwt (1.16.3)
activesupport (>= 4.2)
aes_key_wrap
Expand Down Expand Up @@ -303,7 +303,7 @@ GEM
net-protocol
net-ssh (7.1.0)
nio4r (2.5.9)
nokogiri (1.15.5-x86_64-linux)
nokogiri (1.16.0-x86_64-linux)
racc (~> 1.4)
oauth2 (2.0.8)
faraday (>= 0.17.3, < 3.0)
Expand Down Expand Up @@ -344,7 +344,7 @@ GEM
validate_url
webfinger (~> 2.0)
orm_adapter (0.5.0)
parallel (1.23.0)
parallel (1.24.0)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
Expand All @@ -358,7 +358,7 @@ GEM
premailer (~> 1.7, >= 1.7.9)
pretender (0.5.0)
actionpack (>= 6.1)
psych (5.1.1.1)
psych (5.1.2)
stringio
public_suffix (5.0.3)
puma (6.4.0)
Expand All @@ -378,7 +378,7 @@ GEM
rack (>= 2.1.0)
rack-protection (3.0.4)
rack
rack-session (1.0.1)
rack-session (1.0.2)
rack (< 3)
rack-test (2.1.0)
rack (>= 1.3)
Expand Down Expand Up @@ -427,25 +427,25 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
rb-readline (0.5.5)
rdoc (6.6.0)
rdoc (6.6.2)
psych (>= 4.0.0)
regexp_parser (2.8.2)
reline (0.4.0)
regexp_parser (2.8.3)
reline (0.4.2)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.6)
rouge (4.2.0)
rubocop (1.57.2)
rubocop (1.59.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
Expand All @@ -454,9 +454,10 @@ GEM
rubocop (~> 1.41)
rubocop-factory_bot (2.24.0)
rubocop (~> 1.33)
rubocop-minitest (0.33.0)
rubocop-minitest (0.34.3)
rubocop (>= 1.39, < 2.0)
rubocop-rails (2.22.2)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-rails (2.23.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
Expand Down Expand Up @@ -504,7 +505,7 @@ GEM
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
stackprof (0.2.25)
stringio (3.0.9)
stringio (3.1.0)
swd (2.0.2)
activesupport (>= 3)
attr_required (>= 0.0.5)
Expand Down Expand Up @@ -580,7 +581,7 @@ DEPENDENCIES
docker-api (~> 2.2.0)
ed25519
exception_notification (~> 4.5.0)
factory_bot_rails (~> 6.4.2)
factory_bot_rails (~> 6.4.3)
faker (~> 3.2.2)
flamegraph (~> 0.9.5)
has_scope (~> 0.8.2)
Expand All @@ -604,7 +605,7 @@ DEPENDENCIES
minitest-utils (~> 0.4.8)
mocha (~> 2.1.0)
mysql2 (~> 0.5.5)
nokogiri (~> 1.15.5)
nokogiri (~> 1.16.0)
omniauth-google-oauth2 (~> 1.1.1)
omniauth-oauth2 (~> 1.8.0)
omniauth-rails_csrf_protection (~> 1.0.1)
Expand All @@ -621,8 +622,8 @@ DEPENDENCIES
rouge (= 4.2.0)
rubocop-capybara (~> 2.19.0)
rubocop-factory_bot (~> 2.24)
rubocop-minitest (~> 0.33.0)
rubocop-rails (~> 2.22.2)
rubocop-minitest (~> 0.34.3)
rubocop-rails (~> 2.23.1)
ruby-saml (~> 1.16.0)
rubyzip (~> 2.3.2)
selenium-webdriver (~> 4.16.0)
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export class Notification {
// We only want to install the click handler for the full element on the small notification view.
if (installClickHandler) {
this.element.addEventListener("click", event => {
// Use default browser behavior if the user clicked on the link itself.
if (event.target instanceof HTMLAnchorElement) return;

this.visit();
event.stopPropagation();
});
Expand Down
12 changes: 8 additions & 4 deletions app/assets/javascripts/state/SavedAnnotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class SavedAnnotationState extends State {
@stateProperty private paginationByURL = new StateMap<string, Pagination>();
@stateProperty private byId = new StateMap<number, SavedAnnotation>();

private get url(): string {
return `/${I18n.locale}${URL}`;
}

private async fetchList(url: string): Promise<Array<SavedAnnotation>> {
const response = await fetch(url);
this.listByURL.set(url, await response.json());
Expand All @@ -42,14 +46,14 @@ class SavedAnnotationState extends State {
}

private async fetch(id: number): Promise<SavedAnnotation> {
const url = `${URL}/${id}.json`;
const url = `${this.url}/${id}.json`;
const response = await fetch(url);
this.byId.set(id, await response.json());
return this.byId.get(id);
}

async create(data: { from: number, saved_annotation: { title: string, annotation_text: string } }): Promise<number> {
const url = `${URL}.json`;
const url = `${this.url}.json`;
const response = await fetch(url, {
method: "post",
body: JSON.stringify(data),
Expand All @@ -66,7 +70,7 @@ class SavedAnnotationState extends State {
}

getList(params?: Map<string, string>, arrayParams?: Map<string, string[]>): Array<SavedAnnotation> | undefined {
const url = addParametersToUrl(`${URL}.json`, params, arrayParams);
const url = addParametersToUrl(`${this.url}.json`, params, arrayParams);
delayerByURL.get(url)(() => {
if (!this.listByURL.has(url)) {
this.fetchList(url);
Expand All @@ -76,7 +80,7 @@ class SavedAnnotationState extends State {
}

getPagination(params?: Map<string, string>, arrayParams?: Map<string, string[]>): Pagination {
const url = addParametersToUrl(`${URL}.json`, params, arrayParams);
const url = addParametersToUrl(`${this.url}.json`, params, arrayParams);
delayerByURL.get(url)(() => {
if (!this.paginationByURL.has(url)) {
this.fetchList(url);
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/models/submissions.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
td.line-nr {
text-align: right;
white-space: pre-wrap;
user-select: none;
}

th {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def show
flash.now[:alert] = I18n.t('activities.show.not_a_member') if @course && !current_user&.member_of?(@course)

# Double check if activity still exists within this course (And throw a 404 when it does not)
@course&.activities&.find_by!(id: @activity.id) if current_user&.course_admin?(@course)
@course&.activities&.find(@activity.id) if current_user&.course_admin?(@course)
# We still need to check access because an unauthenticated user should be able to see public activities
raise Pundit::NotAuthorizedError, 'Not allowed' unless @activity.accessible?(current_user, @course)

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def index
end

@courses = @courses.paginate(page: parse_pagination_param(params[:page]))
@membership_status = current_user&.course_memberships&.where(course_id: @courses.pluck(:id))&.map { |c| [c.course_id, c.status] }&.to_h || {}
@membership_status = current_user&.course_memberships&.where(course_id: @courses.pluck(:id)).to_h { |c| [c.course_id, c.status] }
@repository = Repository.find(params[:repository_id]) if params[:repository_id]
@institution = Institution.find(params[:institution_id]) if params[:institution_id]
@copy_courses = params[:copy_courses]
Expand Down
10 changes: 5 additions & 5 deletions app/models/concerns/cacheable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ def invalidateable_instance_cacheable(name, cache_string)
end[1]
end

define_method("invalidate_#{name}".to_sym) do |options = {}|
define_method(:"invalidate_#{name}") do |options = {}|
lookup_string = cache_string.call(self, options)
Rails.cache.delete(lookup_string)
end

define_method("invalidate_delayed_#{name}".to_sym) do |options = {}|
define_method(:"invalidate_delayed_#{name}") do |options = {}|
lookup_string = cache_string.call(self, options)
value = Rails.cache.read(lookup_string)
Rails.cache.write(lookup_string, [true, value[1]], expires_in: CACHE_EXPIRY_TIME) if value.present? && !value[0]
end

define_method("old_#{name}".to_sym, calculator)
define_method(:"old_#{name}", calculator)
end

def updateable_class_cacheable(name, cache_string)
Expand All @@ -38,7 +38,7 @@ def updateable_class_cacheable(name, cache_string)
Rails.cache.fetch(cache_string.call(options))
end

define_singleton_method("update_#{name}".to_sym) do |options = {}|
define_singleton_method(:"update_#{name}") do |options = {}|
old = Rails.cache.fetch(cache_string.call(options))
updated = if old.present?
updater.call(options, old)
Expand All @@ -48,7 +48,7 @@ def updateable_class_cacheable(name, cache_string)
Rails.cache.write(cache_string.call(options), updated)
end

define_singleton_method("old_#{name}".to_sym, updater)
define_singleton_method(:"old_#{name}", updater)
end
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/tokenable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Tokenable
class_methods do
def token_generator(name, length: 16, unique: true)
token_name = name.to_sym
generate_token_method_name = "generate_#{name}".to_sym
generate_token_method_name = :"generate_#{name}"

# Generate a random base64 string, but strip characters which might
# look ambiguous.
Expand Down
6 changes: 3 additions & 3 deletions app/models/institution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ def self.similarity_matrix
.filter { |u| IGNORED_DOMAINS_FOR_SIMILARITY.exclude?(u[:domain]) && u[:count] > 1 }

# we group by domain to get all institutions with the same domain, we update the similarity matrix for all pairs of institutions
domains.group_by { |u| u[:domain] }.each do |_, institution|
domains.group_by { |u| u[:domain] }.each_value do |institution|
institution.combination(2).each do |i1, i2|
overlap = [i1[:count], i2[:count]].min
matrix[i1[:institution_id]][i2[:institution_id]] = [matrix[i1[:institution_id]][i2[:institution_id]], overlap].max
matrix[i2[:institution_id]][i1[:institution_id]] = matrix[i1[:institution_id]][i2[:institution_id]]
end
end

emails.group_by(&:email).each do |_, users|
emails.group_by(&:email).each_value do |users|
users.combination(2).each do |u1, u2|
matrix[u1.institution_id][u2.institution_id] += 1
matrix[u2.institution_id][u1.institution_id] += 1
end
end

usernames.each { |u| u.username.downcase! }.group_by(&:username).each do |_, users|
usernames.each { |u| u.username.downcase! }.group_by(&:username).each_value do |users|
users.combination(2).each do |u1, u2|
matrix[u1.institution_id][u2.institution_id] += 1
matrix[u2.institution_id][u1.institution_id] += 1
Expand Down
2 changes: 1 addition & 1 deletion app/views/activities/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ end %>
<%= @course&.id || "null" %>,
<%= raw "\"#{@series&.deadline&.httpdate}\"" || "null" %>,
"<%= submissions_url %>",
`<%= (@activity.exercise? && @activity.boilerplate&.gsub('`', '\\\\`'))|| "" %>`,
`<%= escape_javascript (@activity.exercise? && @activity.boilerplate)|| "" %>`,
);
});
</script>
Loading

0 comments on commit e3a155b

Please sign in to comment.