Skip to content

Commit a54c715

Browse files
authored
Merge pull request #352 from nud/suivi-2046-mastodon-url
Include the Mastodon URL in a link element on user page (#2046)
2 parents c7ef92a + 5913215 commit a54c715

File tree

13 files changed

+76
-10
lines changed

13 files changed

+76
-10
lines changed

Docker.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ docker-compose run linuxfr.org bin/rails db:setup
2222
Finally, the environment is ready and you can open [http://dlfp.lo](http://dlfp.lo)
2323
in your favorite browser.
2424

25-
Note: to be able to access this URL, you'll need to add the line
26-
`127.0.0.1 dlfp.lo image.dlfp.lo` to the `/etc/hosts` file of your
27-
machine.
25+
Note: to be able to access this URL, you'll need to add the following line
26+
into the `/etc/hosts` file of your machine:
27+
28+
```
29+
127.0.0.1 dlfp.lo image.dlfp.lo
30+
```
2831

2932
Personalize configuration
3033
=========================
@@ -58,7 +61,9 @@ will directly detect changes and apply them on next page reload.
5861
Furthermore, if you need to access the Rails console, you need a second
5962
terminal and run:
6063

61-
`docker-compose run linuxfr.org bin/rails console`
64+
```
65+
docker-compose run linuxfr.org bin/rails console
66+
```
6267

6368
Note: currently, we didn't configure rails to show directly the
6469
`webconsole` in your browser. That's just because of time needed to
@@ -76,15 +81,19 @@ To get help about writing tests, see the
7681

7782
To run tests with Docker environment, you need to use this command:
7883

79-
`docker-compose run linuxfr.org bin/rails test -v`
84+
```
85+
docker-compose run linuxfr.org bin/rails test -v
86+
```
8087

8188
Inspect database schema
8289
=======================
8390

8491
In case you need to inspect the database, you need a second terminal
8592
and run:
8693

87-
`docker-compose run database mysql -hdatabase -ulinuxfr_rails -p linuxfr_rails`
94+
```
95+
docker-compose run database mysql -hdatabase -ulinuxfr_rails -p linuxfr_rails
96+
```
8897

8998
By default, the requested password is the same as the username.
9099

@@ -94,12 +103,16 @@ Apply database migrations
94103
In case you need to apply new database migrations, you need a second
95104
terminal and run:
96105

97-
`docker-compose run linuxfr.org bin/rails db:migrate`
106+
```
107+
docker-compose run linuxfr.org bin/rails db:migrate
108+
```
98109

99110
If you had issue and want to reset all data in your database system,
100111
use:
101112

102-
`docker-compose run linuxfr.org bin/rails db:reset`
113+
```
114+
docker-compose run linuxfr.org bin/rails db:reset
115+
```
103116

104117
Services provided by the docker-compose
105118
=======================================

app/controllers/application_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def seo_filter
3737
@keywords = %w(Linux Logiciel Libre GNU Free Software Actualité Forum Communauté)
3838
@description = "L’actualité du logiciel libre et des sujets voisins (DIY, Open Hardware, Open Data, les Communs, etc.), sur un site francophone contributif géré par une équipe bénévole par et pour des libristes enthousiastes"
3939
@feeds = {}
40+
@links = {}
4041
@last_comments = Comment.footer
4142
@popular_tags = Tag.footer
4243
@friend_sites = FriendSite.select([:url, :title])
@@ -56,7 +57,7 @@ def configure_permitted_parameters
5657
:sort_by_date_on_home, :hide_signature, :show_negative_nodes,
5758
:totoz_style, :totoz_source,
5859
:board_in_sidebar,
59-
user_attributes: [:id, :name, :homesite, :jabber_id, :signature, :avatar, :custom_avatar_url]
60+
user_attributes: [:id, :name, :homesite, :jabber_id, :mastodon_url, :signature, :avatar, :custom_avatar_url]
6061
])
6162
end
6263

app/helpers/application_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def feed(title, link=nil)
1616
@feeds[link] = title
1717
end
1818

19+
def link(rel, link)
20+
@links[link] = rel
21+
end
22+
1923
def meta_for(content)
2024
@author = content.node.user.try(:name)
2125
@keywords = content.node.popular_tags.map &:name

app/helpers/node_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def posted_by(content, user_link='Anonyme')
111111
user_infos = []
112112
user_infos << homesite_link(user)
113113
user_infos << jabber_link(user)
114+
user_infos << mastodon_link(user)
114115
user_infos.compact!
115116
user_link += (" (" + user_infos.join(', ') + ")").html_safe if user_infos.any?
116117
end

app/helpers/users_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@ def jabber_link(user)
4040
link_to("adresse XMPP", "xmpp:" + user.jabber_id)
4141
end
4242

43+
def mastodon_link(user)
44+
return if user.mastodon_url.blank?
45+
link_to("Mastodon", user.mastodon_url)
46+
end
4347
end

app/models/statistics/users.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,9 @@ def top_email_domains
109109
def top_xmpp_domains
110110
select_all "SELECT SUBSTRING_INDEX(jabber_id,'@', -1) AS domain, COUNT(*) AS cnt FROM accounts LEFT JOIN users ON accounts.user_id=users.id WHERE jabber_id LIKE '%@%' AND current_sign_in_at > DATE_SUB(CURDATE(),INTERVAL 90 DAY) AND role<>'inactive' GROUP BY domain HAVING cnt > 3 ORDER BY cnt DESC LIMIT 10;"
111111
end
112+
113+
def top_mastodon_domains
114+
# We assume Mastodon URLs will always start with "https://"
115+
select_all "SELECT SUBSTRING_INDEX(SUBSTRING(mastodon_url, 9),'/', 1) AS domain, COUNT(*) AS cnt FROM accounts LEFT JOIN users ON accounts.user_id=users.id WHERE mastodon_url LIKE 'https://%/%' AND current_sign_in_at > DATE_SUB(CURDATE(),INTERVAL 90 DAY) AND role<>'inactive' GROUP BY domain HAVING cnt > 3 ORDER BY cnt DESC LIMIT 10;"
116+
end
112117
end

app/models/user.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# name :string(40)
88
# homesite :string(100)
99
# jabber_id :string(32)
10+
# mastodon_url :string(100)
1011
# cached_slug :string(32) not null
1112
# created_at :datetime
1213
# updated_at :datetime
@@ -33,6 +34,8 @@ class User < ActiveRecord::Base
3334
validates :homesite, length: { maximum: 100, message: "L’adresse du site Web personnel est trop longue" }
3435
validates :name, length: { maximum: 40, message: "Le nom affiché est trop long" }
3536
validates :jabber_id, length: { maximum: 32, message: "L’adresse XMPP est trop longue" }
37+
validates :mastodon_url, http_url: { protocols: ["https"], message: "L’adresse du compte Mastodon n’est pas valide" },
38+
length: { maximum: 255, message: "L’adresse du compte Mastodon est trop longue" }
3639
validates :signature, length: { maximum: 255, message: "La signature est trop longue" }
3740
validates :custom_avatar_url, length: { maximum: 255, message: "L’adresse de l’avatar est trop longue" }
3841

app/views/devise/registrations/_preferences.html.haml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
= u.label :jabber_id, 'Adresse XMPP'
1212
%span.prefix xmpp:
1313
= u.text_field :jabber_id, placeholder: "[email protected]", maxlength: 32
14+
%p
15+
= u.label :mastodon_url, 'Adresse du compte Mastodon'
16+
= u.url_field :mastodon_url, placeholder: "https://mastodon.example/@me", maxlength: 255
17+
%span.help
18+
Après avoir enregistré l’adresse de votre compte Mastodon, vous pourrez utiliser le lien <kbd>https://linuxfr.org/users/#{current_user.login}</kbd> pour
19+
<a href="https://docs.joinmastodon.org/user/profile/#verification">prouver que le compte Mastodon et le compte LinuxFr.org appartiennent à la même personne.</a>
1420
%p
1521
= u.label :signature, "Signature"
1622
= u.text_field :signature, maxlength: 250, size: 100

app/views/layouts/_head.html.haml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
%meta(name="robots" content="noindex, nofollow")
1919
- @feeds.each do |link,title|
2020
= auto_discovery_link_tag :atom, link, { title: title }
21+
- @links.each do |link,rel|
22+
%link(rel=rel href=link)

app/views/statistics/users.html.haml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
%li= link_to("Informations personnelles", "#stats_infosperso")
2020
%li= link_to("Domaines des courriels", "#stats_courriel")
2121
%li= link_to("Domaines XMPP", "#stats_xmpp")
22+
%li= link_to("Domaines Mastodon", "#stats_mastodon")
2223
%li= link_to("Utilisation des fonctionnalités", "#stats_fonctionnalites")
2324
%li= link_to("Style (CSS)", "#stats_css")
2425
%li= link_to("Karmas des utilisatrices et utilisateurs", "#stats_karma")
@@ -252,6 +253,24 @@
252253
%td
253254
#{@stats.pctrecent(domain["cnt"])}
254255

256+
%h2#stats_mastodon Domaines Mastodon
257+
%p
258+
Sur #{pluralize @stats.nb_recently_used_accounts, "compte valide et utilisé", "comptes valides et utilisés"} au cours des trois derniers mois :
259+
%table
260+
- maxval = @stats.nb_recently_used_accounts
261+
%tr
262+
%th Domaines à plus de trois comptes
263+
%th Nombre de comptes
264+
%th Actifs
265+
- @stats.top_mastodon_domains.each do |domain|
266+
%tr
267+
%td.stat
268+
= domain["domain"]
269+
%td
270+
.stat.misc(style="width: #{(width_stats * domain["cnt"] / maxval).to_i}px;")= domain["cnt"]
271+
%td
272+
#{@stats.pctrecent(domain["cnt"])}
273+
255274
%h2#stats_fonctionnalites Utilisation des fonctionnalités
256275
%p
257276
Sur #{pluralize @stats.nb_recently_used_accounts, "compte valide et utilisé", "comptes valides"} au cours des trois derniers mois :

0 commit comments

Comments
 (0)