From adb7fcb6b3ec5d00f5ed1dd0fb215faaaeec9a18 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 5 Dec 2016 16:18:24 +0800 Subject: [PATCH] FEATURE: Add bio to group page. --- .../javascripts/admin/templates/group.hbs | 5 +++ .../javascripts/discourse/models/group.js.es6 | 1 + .../javascripts/discourse/templates/group.hbs | 44 +++++++++++-------- .../discourse/templates/modal/edit-group.hbs | 3 ++ app/assets/stylesheets/common/base/group.scss | 11 ++++- app/controllers/groups_controller.rb | 7 ++- app/models/group.rb | 7 +++ app/serializers/basic_group_serializer.rb | 20 ++++++++- config/locales/client.en.yml | 1 + .../20161205065743_add_bio_to_groups.rb | 6 +++ spec/integration/groups_spec.rb | 4 +- spec/models/group_spec.rb | 8 +++- .../javascripts/acceptance/groups-test.js.es6 | 1 + 13 files changed, 94 insertions(+), 24 deletions(-) create mode 100644 db/migrate/20161205065743_add_bio_to_groups.rb diff --git a/app/assets/javascripts/admin/templates/group.hbs b/app/assets/javascripts/admin/templates/group.hbs index b8852002aab..42993a1e923 100644 --- a/app/assets/javascripts/admin/templates/group.hbs +++ b/app/assets/javascripts/admin/templates/group.hbs @@ -11,6 +11,11 @@ {{#if model.id}} {{#unless model.automatic}} +
+ + {{d-editor value=model.bio_raw}} +
+ {{#if model.hasOwners}}
diff --git a/app/assets/javascripts/discourse/models/group.js.es6 b/app/assets/javascripts/discourse/models/group.js.es6 index 68550d2c2b5..510149b6ba3 100644 --- a/app/assets/javascripts/discourse/models/group.js.es6 +++ b/app/assets/javascripts/discourse/models/group.js.es6 @@ -114,6 +114,7 @@ const Group = Discourse.Model.extend({ flair_url: this.get('flair_url'), flair_bg_color: this.get('flairBackgroundHexColor'), flair_color: this.get('flairHexColor'), + bio_raw: this.get('bio_raw') }; }, diff --git a/app/assets/javascripts/discourse/templates/group.hbs b/app/assets/javascripts/discourse/templates/group.hbs index d12de33ef2a..1fa500cc97c 100644 --- a/app/assets/javascripts/discourse/templates/group.hbs +++ b/app/assets/javascripts/discourse/templates/group.hbs @@ -13,26 +13,34 @@
-
- -

- {{#if model.flair_url}} - - {{avatar-flair - flairURL=model.flair_url - flairBgColor=model.flair_bg_color - flairColor=model.flair_color - groupName=model.name}} - - {{/if}} - {{groupName}} -

-
- - {{#if canEditGroup}} +
+
- {{d-button action="showGroupEditor" class="group-edit-btn btn-small" icon="pencil"}} +

+ {{#if model.flair_url}} + + {{avatar-flair + flairURL=model.flair_url + flairBgColor=model.flair_bg_color + flairColor=model.flair_color + groupName=model.name}} + + {{/if}} + {{groupName}} +

+ + {{#if canEditGroup}} + + {{d-button action="showGroupEditor" class="group-edit-btn btn-small" icon="pencil"}} + + {{/if}} +
+ + {{#if model.bio_cooked}} +
+

{{{model.bio_cooked}}}

+
{{/if}}
diff --git a/app/assets/javascripts/discourse/templates/modal/edit-group.hbs b/app/assets/javascripts/discourse/templates/modal/edit-group.hbs index f467e5e94e2..0a3ffabd923 100644 --- a/app/assets/javascripts/discourse/templates/modal/edit-group.hbs +++ b/app/assets/javascripts/discourse/templates/modal/edit-group.hbs @@ -1,5 +1,8 @@ {{#d-modal-body title="group.edit.title" class="edit-group groups"}}
+ + {{d-editor value=model.bio_raw class="edit-group-bio"}} + {{group-flair-inputs model=model}}
{{/d-modal-body}} diff --git a/app/assets/stylesheets/common/base/group.scss b/app/assets/stylesheets/common/base/group.scss index c948ab5da2a..5b360ede9ce 100644 --- a/app/assets/stylesheets/common/base/group.scss +++ b/app/assets/stylesheets/common/base/group.scss @@ -3,6 +3,11 @@ font-weight: normal; } +.group-details-container { + background: rgba(204, 204, 204, 0.2); + padding: 20px; +} + table.group-members { width: 100%; @@ -55,7 +60,11 @@ table.group-members { margin-left: 5px; } -.form-horizontal { +.groups.edit-group .form-horizontal { + textarea { + width: 99%; + } + label { font-weight: bold; } diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 918a113848a..af7e39e4cca 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -169,7 +169,12 @@ class GroupsController < ApplicationController private def group_params - params.require(:group).permit(:flair_url, :flair_bg_color, :flair_color) + params.require(:group).permit( + :flair_url, + :flair_bg_color, + :flair_color, + :bio_raw + ) end def find_group(param_name) diff --git a/app/models/group.rb b/app/models/group.rb index c0c487f4d23..dde84c29225 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -13,6 +13,7 @@ class Group < ActiveRecord::Base has_and_belongs_to_many :web_hooks before_save :downcase_incoming_email + before_save :cook_bio after_save :destroy_deletions after_save :automatic_group_membership @@ -83,6 +84,12 @@ class Group < ActiveRecord::Base self.incoming_email = (incoming_email || "").strip.downcase.presence end + def cook_bio + if !self.bio_raw.blank? + self.bio_cooked = PrettyText.cook(self.bio_raw) + end + end + def incoming_email_validator return if self.automatic || self.incoming_email.blank? diff --git a/app/serializers/basic_group_serializer.rb b/app/serializers/basic_group_serializer.rb index 783fdafb941..401a88b2ff1 100644 --- a/app/serializers/basic_group_serializer.rb +++ b/app/serializers/basic_group_serializer.rb @@ -14,9 +14,25 @@ class BasicGroupSerializer < ApplicationSerializer :has_messages, :flair_url, :flair_bg_color, - :flair_color + :flair_color, + :bio_raw, + :bio_cooked def include_incoming_email? - scope.is_staff? + staff? + end + + def include_has_messsages + staff? + end + + def include_bio_raw + staff? + end + + private + + def staff? + @staff ||= scope.is_staff? end end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 486748c2154..bde096aa7a7 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1849,6 +1849,7 @@ en: edit: title: 'Edit Group' name: "Name" + bio: "About Group" name_placeholder: "Group name, no spaces, same as username rule" flair_url: "Avatar Flair Image" flair_url_placeholder: "(Optional) Image URL or Font Awesome class" diff --git a/db/migrate/20161205065743_add_bio_to_groups.rb b/db/migrate/20161205065743_add_bio_to_groups.rb new file mode 100644 index 00000000000..846b3a1c979 --- /dev/null +++ b/db/migrate/20161205065743_add_bio_to_groups.rb @@ -0,0 +1,6 @@ +class AddBioToGroups < ActiveRecord::Migration + def change + add_column :groups, :bio_raw, :text + add_column :groups, :bio_cooked, :text + end +end diff --git a/spec/integration/groups_spec.rb b/spec/integration/groups_spec.rb index e7f4e9eb7d8..4196216c19e 100644 --- a/spec/integration/groups_spec.rb +++ b/spec/integration/groups_spec.rb @@ -46,7 +46,8 @@ describe "Groups" do xhr :put, "/groups/#{group.id}", { group: { flair_bg_color: 'FFF', flair_color: 'BBB', - flair_url: 'fa-adjust' + flair_url: 'fa-adjust', + bio_raw: 'testing' } } expect(response).to be_success @@ -56,6 +57,7 @@ describe "Groups" do expect(group.flair_bg_color).to eq('FFF') expect(group.flair_color).to eq('BBB') expect(group.flair_url).to eq('fa-adjust') + expect(group.bio_raw).to eq('testing') end end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index dfc54ba1a87..8a6477ed731 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -322,7 +322,6 @@ describe Group do expect(Group.desired_trust_level_groups(2).sort).to eq [10,11,12] end - it "correctly handles trust level changes" do user = Fabricate(:user, trust_level: 2) Group.user_trust_level_change!(user.id, 2) @@ -369,4 +368,11 @@ describe Group do expect(u3.reload.trust_level).to eq(3) end + it 'should cook the bio' do + group = Fabricate(:group) + group.update_attributes!(bio_raw: 'This is a group for :unicorn: lovers') + + expect(group.bio_cooked).to include("unicorn.png") + end + end diff --git a/test/javascripts/acceptance/groups-test.js.es6 b/test/javascripts/acceptance/groups-test.js.es6 index 045c37fd6fc..8cb827f3ef3 100644 --- a/test/javascripts/acceptance/groups-test.js.es6 +++ b/test/javascripts/acceptance/groups-test.js.es6 @@ -46,5 +46,6 @@ test("Admin Browsing Groups", () => { andThen(() => { ok(find('.group-flair-inputs').length === 1, 'it should display avatar flair inputs'); + ok(find('.edit-group-bio').length === 1, 'it should display group bio input'); }); });