I fixed this with some HTML and JavaScript. Put it on a wiki page or in a macro and when a user visits the page they are subscribed to the calendar. Bonus: wrap it in SQL to detect if a user has already subscribed to the calendar or not.
The logic is:
1) Run a SQL to determine if the user is subscribed to the chosen calendar
Throw a message if the SQL returns no result.
2) Run JavaScript on the page to detect the failure message from the SQL
3) If the failure message is detected then activate the calendar subscribe script to force the user to subscribe to the calendar
The other way is to do all of this in SQL using a where clause to add the calendar if they are not subscribed, noting that hitting the DB directly should be avoided and not everyone has Bob's excellent SQL macro.
As a V3 macro this looks like this:
## Macro title: auto-cal-subscribe
## Macro has a body: N
## Body processing: N/A
## Output: Text message if no calendar subscriptions are detected which is used to auto subscribe the user to a calendar
##
## Developed by: OutOfTheBox
## @noparams
## 1. Detect the user's logon id
## 2. Determine if the user has any Calendars by reading OS_PROPERTYENTRY
## 3. If no calendar subscriptions are found then run the auto-calendar-subscribe macro
## Hide the error box if the page does not have confluence-admin edit rights so users can't see the SQL
{style}div.error { display: none !important; }{style}
## Retrieve userid
#set( $username = "$req.getRemoteUser()" )
## Read database to determine if this user currently has a calendar subscribed
{show-to:group=confluence-users}
{sql-query:dataSource=wiki|autoNumber=true|table=false|output=wiki|noDataMessage=NoCalendarDetected}
select case ENTITY_ID
when 0 then ''
else 'No calendars detected'
end as STATUS
from OS_PROPERTYENTRY
where
entity_name = 'CWD_$username'
and entity_key = 'calendar'
and text_val like '%subCalendar%'
{sql-query}
{show-to}
## This is the form which is used to subscribe to a calendar
{html}
<!-- Create the form for subscribing to the test calendar -->
<form name="autosubscribetocalendar" id="autosubscribetocalendar" class="hidden" method="POST" action="http:>
#form_xsrfToken() <!-- Generate atl_token input field -->
<input type="hidden" name="subCalendarId" value="e1310ae6-e9db-45ff-8316-5da18c514f8f"> <!-- Calendar to subscribe this user to -->
<input type="submit" value="Subscribe" >
</form>
{html}
## This is the javascript which triggers the form
## If the result of the first SQL outputs the text 'NoCalendarDetected' then this script will trigger
{html}
<script type="text/javascript">
AJS.$(document).ready(function() {
if ( AJS.$('p:contains("NoCalendarDetected")').length > 1 ) {
AJS.$("#autosubscribetocalendar").submit(); }
AJS.$('p:contains("NoCalendarDetected")').hide(); AJS.$('div.error').remove(); });
</script>
{html}
Change the SQL to detect the calendar to automatically subscribe a user to. Put the macro on a wiki page.
Alternatively, convert this to HTML and put it in your Custom HTML at the end of the body.
Or, publish a link to the calendar in a public place e.g. _http://confluence.internal/wiki/calendar/previewcalendar.action?subCalendarId=e1310ae6-e9db-45ff-8316-5da18c514f8f_ so people can find it.
+52145