@@ -51,17 +51,28 @@ def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_fo
51
51
52
52
# Displays a link to user's account page if active
53
53
def link_to_user ( user , options = { } )
54
- if user . is_a? ( User )
55
- name = h ( user . name ( options [ :format ] ) )
56
- if user . active? || ( User . current . admin? && user . logged? )
57
- only_path = options [ :only_path ] . nil? ? true : options [ :only_path ]
58
- link_to name , user_url ( user , :only_path => only_path ) , :class => user . css_classes
59
- else
60
- name
54
+ user . is_a? ( User ) ? link_to_principal ( user , options ) : h ( user . to_s )
55
+ end
56
+
57
+ # Displays a link to user's account page or group page
58
+ def link_to_principal ( principal , options = { } )
59
+ only_path = options [ :only_path ] . nil? ? true : options [ :only_path ]
60
+ case principal
61
+ when User
62
+ name = h ( principal . name ( options [ :format ] ) )
63
+ if principal . active? || ( User . current . admin? && principal . logged? )
64
+ url = user_url ( principal , :only_path => only_path )
65
+ css_classes = principal . css_classes
61
66
end
67
+ when Group
68
+ name = h ( principal . to_s )
69
+ url = group_url ( principal , :only_path => only_path )
70
+ css_classes = "group icon icon-#{ principal . class . name . downcase } "
62
71
else
63
- h ( user . to_s )
72
+ name = h ( principal . to_s )
64
73
end
74
+
75
+ url ? link_to ( name , url , :class => css_classes ) : name
65
76
end
66
77
67
78
# Displays a link to edit group page if current user is admin
0 commit comments